8typedef LPTHREAD_START_ROUTINE RESIP_THREAD_START_ROUTINE;
11typedef unsigned(__stdcall *RESIP_THREAD_START_ROUTINE)(
void*);
26#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
31ThreadIf::TlsDestructorMap *ThreadIf::mTlsDestructors;
32Mutex *ThreadIf::mTlsDestructorsMutex;
38unsigned int TlsDestructorInitializer::mInstanceCounter=0;
39TlsDestructorInitializer::TlsDestructorInitializer()
41 if (mInstanceCounter++ == 0)
43 ThreadIf::mTlsDestructorsMutex =
new Mutex();
44 ThreadIf::mTlsDestructors =
new ThreadIf::TlsDestructorMap;
47TlsDestructorInitializer::~TlsDestructorInitializer()
49 if (--mInstanceCounter == 0)
51 delete ThreadIf::mTlsDestructorsMutex;
52 ThreadIf::mTlsDestructors->clear();
53 delete ThreadIf::mTlsDestructors;
79 mThreadObj = std::make_shared<std::thread>([
this]
84 ThreadIf::tlsDestroyAll();
126 return std::this_thread::get_id();
134 if (key!=TLS_OUT_OF_INDEXES)
136 Lock lock(*mTlsDestructorsMutex);
137 (*mTlsDestructors)[key] = destructor;
142 return GetLastError();
145 return pthread_key_create(&key, destructor);
155 Lock lock(*mTlsDestructorsMutex);
156 mTlsDestructors->erase(key);
161 return GetLastError();
164 return pthread_key_delete(key);
172 return TlsSetValue(key, (LPVOID)val)>0?0:GetLastError();
174 return pthread_setspecific(key, val);
182 return TlsGetValue(key);
184 return pthread_getspecific(key);
221ThreadIf::tlsDestroyAll()
223 Lock lock(*mTlsDestructorsMutex);
224 ThreadIf::TlsDestructorMap::const_iterator i = mTlsDestructors->begin();
225 while(i != mTlsDestructors->end())
227 void *val = TlsGetValue(i->first);
#define resip_assert(x)
This file needs to work for both C and C++ code.
Handles cross-platform sockets compatibility.
static void * tlsGetValue(TlsKey key)
This function follows pthread_getspecific() signature.
static int tlsKeyCreate(TlsKey &key, TlsDestructor *destructor)
This function follows pthread_key_create() signature.
std::shared_ptr< std::thread > mThreadObj
static int tlsKeyDelete(TlsKey key)
This function follows pthread_key_delete() signature.
static int tlsSetValue(TlsKey key, const void *val)
This function follows pthread_setspecific() signature.
Condition mShutdownCondition
virtual bool waitForShutdown(int ms) const
dcm! – add UnusedChecking(_enum) below;
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
std::unique_lock< Mutex > Lock
A convenience class to lock a Lockable (such as a Mutex) on object creation, and unlock on destructio...