14#include "arccore/base/NotImplementedException.h"
15#include "arccore/base/IFunctor.h"
17#include "arccore/concurrency/GlibThreadImplementation.h"
18#include "arccore/concurrency/IThreadBarrier.h"
19#include "arccore/concurrency/Mutex.h"
20#include "arccore/concurrency/GlibAdapter.h"
34static void* _GlibStartFunc(
void* f)
36 IFunctor* ff =
reinterpret_cast<IFunctor*
>(f);
50 : m_wait_mutex(
nullptr), m_wait(
nullptr), m_nb_thread(0)
51 , m_current_reached(0) {}
57 m_nb_thread = nb_thread;
58 m_current_reached = 0;
66 m_current_reached = 0;
78 if (m_current_reached==m_nb_thread){
79 m_current_reached = 0;
85 m_wait->wait(m_wait_mutex);
86 m_wait_mutex->unlock();
99extern "C" ARCCORE_CONCURRENCY_EXPORT IThreadBarrier*
100createGlibThreadBarrier()
102 return new GlibThreadBarrier();
108GlibThreadImplementation::
109GlibThreadImplementation()
110: m_global_mutex_impl(nullptr)
114GlibThreadImplementation::
115~GlibThreadImplementation()
117 GlobalMutex::destroy();
118 if (m_global_mutex_impl)
119 destroyMutex(m_global_mutex_impl);
122void GlibThreadImplementation::
125 m_global_mutex_impl = createMutex();
129ThreadImpl* GlibThreadImplementation::
130createThread(IFunctor* f)
132 return reinterpret_cast<ThreadImpl*
>(g_thread_new(
nullptr,&_GlibStartFunc,f));
135void GlibThreadImplementation::
136joinThread(ThreadImpl* t)
138 GThread* tt =
reinterpret_cast<GThread*
>(t);
142void GlibThreadImplementation::
143destroyThread(ThreadImpl* t)
148void GlibThreadImplementation::
149createSpinLock(Int64* spin_lock_addr)
151 volatile gint* v = (gint*)spin_lock_addr;
155void GlibThreadImplementation::
156lockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr)
158 ARCCORE_UNUSED(scoped_spin_lock_addr);
160 volatile gint* v = (gint*)spin_lock_addr;
161 if (!g_bit_trylock(v, 0)) {
164 }
while (!g_bit_trylock(v, 0));
168void GlibThreadImplementation::
169unlockSpinLock(Int64* spin_lock_addr, Int64* scoped_spin_lock_addr)
171 ARCCORE_UNUSED(scoped_spin_lock_addr);
173 volatile gint* v = (gint*)spin_lock_addr;
177MutexImpl* GlibThreadImplementation::
180 GlibMutex* m =
new GlibMutex();
181 return reinterpret_cast<MutexImpl*
>(m);
184void GlibThreadImplementation::
185destroyMutex(MutexImpl* mutex)
187 GlibMutex* m =
reinterpret_cast<GlibMutex*
>(mutex);
191void GlibThreadImplementation::
192lockMutex(MutexImpl* mutex)
194 GlibMutex* m =
reinterpret_cast<GlibMutex*
>(mutex);
198void GlibThreadImplementation::
199unlockMutex(MutexImpl* mutex)
201 GlibMutex* m =
reinterpret_cast<GlibMutex*
>(mutex);
205Int64 GlibThreadImplementation::
208 Int64 v =
reinterpret_cast<Int64
>(g_thread_self());
212IThreadBarrier* GlibThreadImplementation::
215 return new GlibThreadBarrier();
virtual void destroy()
Détruit la barrière.
virtual void init(Integer nb_thread)
Initialise la barrière pour nb_thread.
virtual bool wait()
Bloque et attend que tous les threads appellent cette méthode.
static void init(MutexImpl *p)
Initialise le mutex global. Interne a Arccore. Doit être alloué par new.
Interface d'une barrière entre threads.
Espace de nom de Arccore.
Int32 Integer
Type représentant un entier.