8#ifndef INCLUDED_BSLMT_THREADUTIL
9#define INCLUDED_BSLMT_THREADUTIL
319#include <bslscm_version.h>
340#include <bsl_string.h>
342#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
345#include <bsl_chrono.h>
357 typedef void *(*bslmt_ThreadFunction)(
void *);
368template <
class THREAD_POLICY>
369struct ThreadUtilImpl;
431 double normalizedSchedulingPriority);
490 template <
class INVOKABLE>
492 const INVOKABLE& function);
493 template <
class INVOKABLE>
496 const INVOKABLE& function);
559 template <
class INVOKABLE>
561 const INVOKABLE& function,
563 template <
class INVOKABLE>
566 const INVOKABLE& function,
585 static void exit(
void *status);
622 static int join(
Handle& threadHandle,
void **status = 0);
631 static void microSleep(
int microseconds,
int seconds = 0);
648#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
654 template <
class REP_TYPE,
class PERIOD_TYPE>
656 const bsl::chrono::duration<REP_TYPE, PERIOD_TYPE>& sleepTime);
675#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
686 template <
class CLOCK,
class DURATION>
688 const bsl::chrono::time_point<CLOCK, DURATION>& absoluteTime);
893 return Imp::create(handle, function, userData);
896template <
class INVOKABLE>
899 const INVOKABLE& function)
908template <
class INVOKABLE>
912 const INVOKABLE& function)
925 ThreadFunction function,
940 return Imp::create(handle, function, userData);
943template <
class INVOKABLE>
947 const INVOKABLE& function,
963 int rc = Imp::create(handle,
973template <
class INVOKABLE>
976 const INVOKABLE& function,
992 int rc = Imp::create(handle,
1004 return Imp::detach(handle);
1017 return Imp::getMinSchedulingPriority(policy);
1024 return Imp::getMaxSchedulingPriority(policy);
1032 return Imp::getThreadName(threadName);
1038 return Imp::join(threadHandle, status);
1044 Imp::microSleep(microseconds, seconds);
1050 Imp::setThreadName(threadName);
1056 Imp::sleep(sleepTime);
1059#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
1060template <
class REP_TYPE,
class PERIOD_TYPE>
1063 const bsl::chrono::duration<REP_TYPE, PERIOD_TYPE>& sleepTime)
1073 int status = Imp::sleepUntil(absoluteTime, clockType);
1078#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
1079template <
class CLOCK,
class DURATION>
1081 const bsl::chrono::time_point<CLOCK, DURATION>& absoluteTime)
1083 typename CLOCK::time_point now = CLOCK::now();
1090 while (absoluteTime > now) {
1092 .addDuration(absoluteTime - now);
1114 return Imp::INVALID_HANDLE == a
1115 ? (Imp::INVALID_HANDLE == b)
1116 : (Imp::INVALID_HANDLE == b ? false : Imp::areEqual(a, b));
1122 return Imp::areEqualId(a, b);
1128 return Imp::handleToId(threadHandle);
1134 return Imp::idAsUint64(threadId);
1140 return Imp::idAsInt(threadId);
1146 return Imp::INVALID_HANDLE;
1152 return Imp::areEqual(a, b);
1158 return Imp::areEqualId(a, b);
1165 return Imp::nativeHandle(handle);
1177 return Imp::selfId();
1183 return Imp::selfIdAsInt();
1189 return Imp::selfIdAsUint64();
1198 ktid = Imp::selfKernelIdAsUint64();
1208 return Imp::createKey(key, threadKeyCleanupFunction);
1214 return Imp::deleteKey(key);
1220 return Imp::getSpecific(key);
1226 return Imp::setSpecific(key, value);
1232 return Imp::hardwareConcurrency();
Definition bslstl_string.h:1252
Definition bslma_allocator.h:545
Definition bslma_managedptr.h:1173
TARGET_TYPE * ptr() const
Definition bslma_managedptr.h:2603
ManagedPtr_PairProxy< TARGET_TYPE, ManagedPtrDeleter > release()
Definition bslma_managedptr.h:2490
Definition bslmt_threadattributes.h:361
bslstl::StringRef threadName() const
Definition bslmt_threadattributes.h:772
SchedulingPolicy
Definition bslmt_threadattributes.h:381
Definition bsls_timeinterval.h:307
Definition bslstl_stringref.h:374
#define BSLA_MAYBE_UNUSED
Definition bsla_maybeunused.h:239
void * bslmt_EntryPointFunctorAdapter_invoker(void *argument)
void(* bslmt_KeyDestructorFunction)(void *)
Definition bslmt_threadutil.h:363
void *(* bslmt_ThreadFunction)(void *)
Definition bslmt_threadutil.h:357
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:2045
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_THREAD_LOCAL
Definition bsls_keyword.h:701
Definition bslmt_barrier.h:344
static Allocator * globalAllocator(Allocator *basicAllocator=0)
Definition bslma_default.h:921
static void allocateAdapter(bslma::ManagedPtr< EntryPointFunctorAdapter< TYPE > > *adapter, const TYPE &invokable, const bslstl::StringRef &threadName, bslma::Allocator *basicAllocator=0)
Definition bslmt_entrypointfunctoradapter.h:396
Definition bslmt_entrypointfunctoradapter.h:221
Definition bslmt_threadutil.h:379
bslmt_ThreadFunction ThreadFunction
Prototype for thread entry-point functions.
Definition bslmt_threadutil.h:400
static void microSleep(int microseconds, int seconds=0)
Definition bslmt_threadutil.h:1042
static int create(Handle *handle, const ThreadAttributes &attributes, ThreadFunction function, void *userData)
static bool isThreadLimitReached()
static bsls::Types::Uint64 selfIdAsInt()
Definition bslmt_threadutil.h:1181
static int create(Handle *handle, ThreadFunction function, void *userData)
Definition bslmt_threadutil.h:883
static Handle self()
Definition bslmt_threadutil.h:1169
static bool areEqualId(const Id &a, const Id &b)
Definition bslmt_threadutil.h:1120
Imp::Handle Handle
Definition bslmt_threadutil.h:389
static bsls::Types::Uint64 selfIdAsUint64()
Definition bslmt_threadutil.h:1187
static Id handleToId(const Handle &threadHandle)
Definition bslmt_threadutil.h:1126
static void getThreadName(bsl::string *threadName)
Definition bslmt_threadutil.h:1028
static void sleepUntil(const bsls::TimeInterval &absoluteTime, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
Definition bslmt_threadutil.h:1070
static bool isEqualId(const Id &a, const Id &b)
Definition bslmt_threadutil.h:1156
static int detach(Handle &handle)
Definition bslmt_threadutil.h:1002
static int idAsInt(const Id &threadId)
Definition bslmt_threadutil.h:1138
static Id selfId()
Definition bslmt_threadutil.h:1175
static int deleteKey(Key &key)
Definition bslmt_threadutil.h:1212
static bool areEqual(const Handle &a, const Handle &b)
Definition bslmt_threadutil.h:1108
Imp::NativeHandle NativeHandle
Platform-specific thread handle type.
Definition bslmt_threadutil.h:392
static int join(Handle &threadHandle, void **status=0)
Definition bslmt_threadutil.h:1036
static bool isEqual(const Handle &a, const Handle &b)
Definition bslmt_threadutil.h:1150
static void setThreadName(const bslstl::StringRef &threadName)
Definition bslmt_threadutil.h:1048
static int getMaxSchedulingPriority(ThreadAttributes::SchedulingPolicy policy)
Definition bslmt_threadutil.h:1021
bslmt_KeyDestructorFunction Destructor
Prototype for thread-specific key destructors.
Definition bslmt_threadutil.h:406
static int createWithAllocator(Handle *handle, ThreadFunction function, void *userData, bslma::Allocator *allocator)
static bsls::Types::Uint64 idAsUint64(const Id &threadId)
Definition bslmt_threadutil.h:1132
static NativeHandle nativeHandle(const Handle &handle)
Definition bslmt_threadutil.h:1163
ThreadUtilImpl< Platform::ThreadPolicy > Imp
Platform-specific implementation type.
Definition bslmt_threadutil.h:385
Imp::Id Id
Definition bslmt_threadutil.h:397
static void sleep(const bsls::TimeInterval &sleepTime)
Definition bslmt_threadutil.h:1054
static const Handle & invalidHandle()
Definition bslmt_threadutil.h:1144
static int convertToSchedulingPriority(ThreadAttributes::SchedulingPolicy policy, double normalizedSchedulingPriority)
static bsls::Types::Uint64 selfKernelIdAsUint64()
Definition bslmt_threadutil.h:1193
Imp::Key Key
Thread-specific key type, used to refer to thread-specific storage.
Definition bslmt_threadutil.h:403
static void setThreadLimit(unsigned int n)
static void yield()
Definition bslmt_threadutil.h:1100
static void exit(void *status)
Definition bslmt_threadutil.h:1008
static void * getSpecific(const Key &key)
Definition bslmt_threadutil.h:1218
static int getMinSchedulingPriority(ThreadAttributes::SchedulingPolicy policy)
Definition bslmt_threadutil.h:1014
static unsigned int hardwareConcurrency()
Definition bslmt_threadutil.h:1230
static int setSpecific(const Key &key, const void *value)
Definition bslmt_threadutil.h:1224
static int createWithAllocator(Handle *handle, const ThreadAttributes &attributes, ThreadFunction function, void *userData, bslma::Allocator *allocator)
static int createKey(Key *key, Destructor threadKeyCleanupFunction)
Definition bslmt_threadutil.h:1206
Enum
Definition bsls_systemclocktype.h:119
@ e_REALTIME
Definition bsls_systemclocktype.h:122
static TimeInterval now(SystemClockType::Enum clockType)
Definition bsls_systemtime.h:177
unsigned long long Uint64
Definition bsls_types.h:139