Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ArcaneThreadMisc.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ArcaneThreadMisc.h (C) 2000-2021 */
9/* */
10/* Various functions for threads. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_THREAD_ARCANETHREADMISC_H
13#define ARCANE_PARALLEL_THREAD_ARCANETHREADMISC_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/parallel/thread/ArcaneThread.h"
18
19#include <thread>
20
21#if defined(__x86_64__)
22#include <immintrin.h> // For _mm_pause()
23#endif
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
40inline void
42{
43 bool is_done = false;
44#if defined(__x86_64__)
45 while (count > 0) {
46 _mm_pause();
47 --count;
48 }
49 is_done = true;
50#elif defined(__aarch64__)
51 while (count > 0) {
52 __asm__ __volatile__("yield" ::: "memory");
53 --count;
54 }
55 is_done = true;
56#else
57 ARCANE_UNUSED(count);
58#endif
59 if (!is_done)
60 std::this_thread::yield();
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66} // End namespace Arcane
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71#endif
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
void arcaneDoCPUPause(Int32 count)
Uses the CPU 'pause' instruction if possible.
std::int32_t Int32
Signed integer type of 32 bits.