8#ifndef INCLUDED_BSLMT_THREADUTILIMPL_PTHREAD
9#define INCLUDED_BSLMT_THREADUTILIMPL_PTHREAD
86#include <bslscm_version.h>
90#ifdef BSLMT_PLATFORM_POSIX_THREADS
101#include <bsl_string.h>
112 typedef void *(*bslmt_ThreadFunction)(
void *);
123template <
class THREAD_POLICY>
124struct ThreadUtilImpl;
133struct ThreadUtilImpl<Platform::PosixThreads> {
136 typedef pthread_t Handle;
137 typedef pthread_t NativeHandle;
138 typedef pthread_t Id;
139 typedef pthread_key_t Key;
142 static const pthread_t INVALID_HANDLE;
159 static int create(Handle *threadHandle,
160 const ThreadAttributes& attributes,
174 static int create(Handle *threadHandle,
183 static int detach(Handle& threadHandle);
190 static void exit(
void *status);
198 static int getMaxSchedulingPriority(
207 static int getMinSchedulingPriority(
213 static void getThreadName(
bsl::string *threadName);
221 static int join(Handle& threadHandle,
void **status = (
void**)0);
233 static int microSleep(
int microseconds,
287 bool retryOnSignalInterrupt
301 static bool areEqual(
const Handle& a,
const Handle& b);
305 static bool areEqualId(
const Id& a,
const Id& b);
321 static int idAsInt(
const Id& threadId);
327 static NativeHandle nativeHandle(
const Handle& threadHandle);
331 static Handle self();
355 static Id handleToId(
const Handle& threadHandle);
370 static int deleteKey(Key& key);
376 static void *getSpecific(
const Key& key);
381 static int setSpecific(
const Key& key,
const void *value);
385 static unsigned int hardwareConcurrency();
399int ThreadUtilImpl<bslmt::Platform::PosixThreads>::create(
400 Handle *threadHandle,
404 ThreadAttributes attr;
405 return create(threadHandle, attr, function, userData);
409int ThreadUtilImpl<bslmt::Platform::PosixThreads>::detach(Handle& threadHandle)
411 return pthread_detach(threadHandle);
415void ThreadUtilImpl<bslmt::Platform::PosixThreads>::exit(
void *status)
417 pthread_exit(status);
421int ThreadUtilImpl<bslmt::Platform::PosixThreads>::join(Handle& threadHandle,
424 return pthread_join(threadHandle, status);
428int ThreadUtilImpl<bslmt::Platform::PosixThreads>::sleepUntil(
432 return sleepUntil(absoluteTime,
false, clockType);
436void ThreadUtilImpl<bslmt::Platform::PosixThreads>::yield()
444bool ThreadUtilImpl<bslmt::Platform::PosixThreads>::areEqual(
const Handle& a,
447 return pthread_equal(a, b);
451bool ThreadUtilImpl<bslmt::Platform::PosixThreads>::areEqualId(
const Id& a,
454 return pthread_equal(a, b);
458ThreadUtilImpl<bslmt::Platform::PosixThreads>::Id
459ThreadUtilImpl<bslmt::Platform::PosixThreads>::handleToId(
460 const Handle& threadHandle)
467ThreadUtilImpl<bslmt::Platform::PosixThreads>::idAsUint64(
const Id& threadId)
469#ifdef BSLS_PLATFORM_OS_DARWIN
478ThreadUtilImpl<bslmt::Platform::PosixThreads>::idAsInt(
const Id& threadId)
483 return static_cast<int>(idAsUint64(threadId));
487ThreadUtilImpl<bslmt::Platform::PosixThreads>::NativeHandle
488ThreadUtilImpl<bslmt::Platform::PosixThreads>::nativeHandle(
489 const Handle& threadHandle)
495ThreadUtilImpl<bslmt::Platform::PosixThreads>::Handle
496ThreadUtilImpl<bslmt::Platform::PosixThreads>::self()
498 return pthread_self();
502ThreadUtilImpl<bslmt::Platform::PosixThreads>::Id
503ThreadUtilImpl<bslmt::Platform::PosixThreads>::selfId()
505 return pthread_self();
510ThreadUtilImpl<bslmt::Platform::PosixThreads>::selfIdAsInt()
512 return idAsInt(selfId());
517ThreadUtilImpl<bslmt::Platform::PosixThreads>::selfIdAsUint64()
519 return idAsUint64(selfId());
525int ThreadUtilImpl<bslmt::Platform::PosixThreads>::createKey(
529 return pthread_key_create(key,destructor);
533int ThreadUtilImpl<bslmt::Platform::PosixThreads>::deleteKey(Key& key)
535 return pthread_key_delete(key);
539void *ThreadUtilImpl<bslmt::Platform::PosixThreads>::getSpecific(
542 return pthread_getspecific(key);
546int ThreadUtilImpl<bslmt::Platform::PosixThreads>::setSpecific(
550 return pthread_setspecific(key, value);
Definition bslstl_string.h:1281
SchedulingPolicy
Definition bslmt_threadattributes.h:376
Definition bsls_timeinterval.h:301
Definition bslstl_stringref.h:372
void(* bslmt_KeyDestructorFunction)(void *)
Definition bslmt_threadutil.h:361
void *(* bslmt_ThreadFunction)(void *)
Definition bslmt_threadutil.h:355
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344
Enum
Definition bsls_systemclocktype.h:117
@ e_REALTIME
Definition bsls_systemclocktype.h:120
unsigned long long Uint64
Definition bsls_types.h:137