8#ifndef INCLUDED_BSLMT_THREADUTIL
9#define INCLUDED_BSLMT_THREADUTIL
319#include <bslscm_version.h>
339#include <bsl_string.h>
341#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
344#include <bsl_chrono.h>
355 typedef void *(*bslmt_ThreadFunction)(
void *);
366template <
class THREAD_POLICY>
367struct ThreadUtilImpl;
418 double normalizedSchedulingPriority);
473 template <
class INVOKABLE>
475 const INVOKABLE& function);
476 template <
class INVOKABLE>
479 const INVOKABLE& function);
538 template <
class INVOKABLE>
540 const INVOKABLE& function,
542 template <
class INVOKABLE>
545 const INVOKABLE& function,
561 static void exit(
void *status);
594 static int join(
Handle& threadHandle,
void **status = 0);
602 static void microSleep(
int microseconds,
int seconds = 0);
617#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
622 template <
class REP_TYPE,
class PERIOD_TYPE>
624 const bsl::chrono::duration<REP_TYPE, PERIOD_TYPE>& sleepTime);
641#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
650 template <
class CLOCK,
class DURATION>
652 const bsl::chrono::time_point<CLOCK, DURATION>& absoluteTime);
819 return Imp::create(handle, function, userData);
822template <
class INVOKABLE>
825 const INVOKABLE& function)
834template <
class INVOKABLE>
838 const INVOKABLE& function)
851 ThreadFunction function,
862 return Imp::create(handle, function, userData);
865template <
class INVOKABLE>
869 const INVOKABLE& function,
881 int rc = Imp::create(handle,
891template <
class INVOKABLE>
894 const INVOKABLE& function,
917 return Imp::detach(handle);
930 return Imp::getMinSchedulingPriority(policy);
937 return Imp::getMaxSchedulingPriority(policy);
945 return Imp::getThreadName(threadName);
951 return Imp::join(threadHandle, status);
957 Imp::microSleep(microseconds, seconds);
963 Imp::setThreadName(threadName);
969 Imp::sleep(sleepTime);
972#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
973template <
class REP_TYPE,
class PERIOD_TYPE>
976 const bsl::chrono::duration<REP_TYPE, PERIOD_TYPE>& sleepTime)
986 int status = Imp::sleepUntil(absoluteTime, clockType);
991#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
992template <
class CLOCK,
class DURATION>
994 const bsl::chrono::time_point<CLOCK, DURATION>& absoluteTime)
996 typename CLOCK::time_point now = CLOCK::now();
1003 while (absoluteTime > now) {
1027 return Imp::INVALID_HANDLE == a
1028 ? (Imp::INVALID_HANDLE == b)
1029 : (Imp::INVALID_HANDLE == b ? false : Imp::areEqual(a, b));
1035 return Imp::areEqualId(a, b);
1041 return Imp::handleToId(threadHandle);
1047 return Imp::idAsUint64(threadId);
1053 return Imp::idAsInt(threadId);
1059 return Imp::INVALID_HANDLE;
1065 return Imp::areEqual(a, b);
1071 return Imp::areEqualId(a, b);
1078 return Imp::nativeHandle(handle);
1090 return Imp::selfId();
1096 return Imp::selfIdAsInt();
1102 return Imp::selfIdAsUint64();
1110 return Imp::createKey(key, threadKeyCleanupFunction);
1116 return Imp::deleteKey(key);
1122 return Imp::getSpecific(key);
1128 return Imp::setSpecific(key, value);
1134 return Imp::hardwareConcurrency();
Definition bslstl_string.h:1281
Definition bslma_allocator.h:457
Definition bslma_managedptr.h:1182
TARGET_TYPE * ptr() const
Definition bslma_managedptr.h:2553
ManagedPtr_PairProxy< TARGET_TYPE, ManagedPtrDeleter > release()
Definition bslma_managedptr.h:2454
Definition bslmt_threadattributes.h:356
bslstl::StringRef threadName() const
Definition bslmt_threadattributes.h:761
SchedulingPolicy
Definition bslmt_threadattributes.h:376
Definition bsls_timeinterval.h:301
BSLS_KEYWORD_CONSTEXPR_CPP14 TimeInterval & addDuration(const std::chrono::duration< REP_TYPE, PERIOD_TYPE > &duration, typename std::enable_if< TimeInterval_DurationTraits< REP_TYPE, PERIOD_TYPE >::k_IMPLICIT_CONVERSION_ENABLED, int >::type *=0)
Definition bsls_timeinterval.h:1226
Definition bslstl_stringref.h:372
#define BSLA_MAYBE_UNUSED
Definition bsla_maybeunused.h:239
void * bslmt_EntryPointFunctorAdapter_invoker(void *argument)
void(* bslmt_KeyDestructorFunction)(void *)
Definition bslmt_threadutil.h:361
void *(* bslmt_ThreadFunction)(void *)
Definition bslmt_threadutil.h:355
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:1856
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bslmt_barrier.h:344
static Allocator * globalAllocator(Allocator *basicAllocator=0)
Definition bslma_default.h:905
static bsls::TimeInterval durationToTimeInterval(const bsl::chrono::duration< REP_TYPE, PERIOD_TYPE > &duration)
Definition bslmt_chronoutil.h:307
static void allocateAdapter(bslma::ManagedPtr< EntryPointFunctorAdapter< TYPE > > *adapter, const TYPE &invokable, const bslstl::StringRef &threadName, bslma::Allocator *basicAllocator=0)
Definition bslmt_entrypointfunctoradapter.h:395
Definition bslmt_entrypointfunctoradapter.h:221
Definition bslmt_threadutil.h:375
bslmt_ThreadFunction ThreadFunction
Prototype for thread entry-point functions.
Definition bslmt_threadutil.h:396
static void microSleep(int microseconds, int seconds=0)
Definition bslmt_threadutil.h:955
static int create(Handle *handle, const ThreadAttributes &attributes, ThreadFunction function, void *userData)
static bsls::Types::Uint64 selfIdAsInt()
Definition bslmt_threadutil.h:1094
static int create(Handle *handle, ThreadFunction function, void *userData)
Definition bslmt_threadutil.h:813
static Handle self()
Definition bslmt_threadutil.h:1082
static bool areEqualId(const Id &a, const Id &b)
Definition bslmt_threadutil.h:1033
Imp::Handle Handle
Definition bslmt_threadutil.h:385
static bsls::Types::Uint64 selfIdAsUint64()
Definition bslmt_threadutil.h:1100
static Id handleToId(const Handle &threadHandle)
Definition bslmt_threadutil.h:1039
static void getThreadName(bsl::string *threadName)
Definition bslmt_threadutil.h:941
static void sleepUntil(const bsls::TimeInterval &absoluteTime, bsls::SystemClockType::Enum clockType=bsls::SystemClockType::e_REALTIME)
Definition bslmt_threadutil.h:983
static bool isEqualId(const Id &a, const Id &b)
Definition bslmt_threadutil.h:1069
static int detach(Handle &handle)
Definition bslmt_threadutil.h:915
static int idAsInt(const Id &threadId)
Definition bslmt_threadutil.h:1051
static Id selfId()
Definition bslmt_threadutil.h:1088
static int deleteKey(Key &key)
Definition bslmt_threadutil.h:1114
static bool areEqual(const Handle &a, const Handle &b)
Definition bslmt_threadutil.h:1021
Imp::NativeHandle NativeHandle
Platform-specific thread handle type.
Definition bslmt_threadutil.h:388
static int join(Handle &threadHandle, void **status=0)
Definition bslmt_threadutil.h:949
static bool isEqual(const Handle &a, const Handle &b)
Definition bslmt_threadutil.h:1063
static void setThreadName(const bslstl::StringRef &threadName)
Definition bslmt_threadutil.h:961
static int getMaxSchedulingPriority(ThreadAttributes::SchedulingPolicy policy)
Definition bslmt_threadutil.h:934
bslmt_KeyDestructorFunction Destructor
Prototype for thread-specific key destructors.
Definition bslmt_threadutil.h:402
static int createWithAllocator(Handle *handle, ThreadFunction function, void *userData, bslma::Allocator *allocator)
static bsls::Types::Uint64 idAsUint64(const Id &threadId)
Definition bslmt_threadutil.h:1045
static NativeHandle nativeHandle(const Handle &handle)
Definition bslmt_threadutil.h:1076
ThreadUtilImpl< Platform::ThreadPolicy > Imp
Platform-specific implementation type.
Definition bslmt_threadutil.h:381
Imp::Id Id
Definition bslmt_threadutil.h:393
static void sleep(const bsls::TimeInterval &sleepTime)
Definition bslmt_threadutil.h:967
static const Handle & invalidHandle()
Definition bslmt_threadutil.h:1057
static int convertToSchedulingPriority(ThreadAttributes::SchedulingPolicy policy, double normalizedSchedulingPriority)
Imp::Key Key
Thread-specific key type, used to refer to thread-specific storage.
Definition bslmt_threadutil.h:399
static void yield()
Definition bslmt_threadutil.h:1013
static void exit(void *status)
Definition bslmt_threadutil.h:921
static void * getSpecific(const Key &key)
Definition bslmt_threadutil.h:1120
static int getMinSchedulingPriority(ThreadAttributes::SchedulingPolicy policy)
Definition bslmt_threadutil.h:927
static unsigned int hardwareConcurrency()
Definition bslmt_threadutil.h:1132
static int setSpecific(const Key &key, const void *value)
Definition bslmt_threadutil.h:1126
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:1108
Enum
Definition bsls_systemclocktype.h:117
@ e_REALTIME
Definition bsls_systemclocktype.h:120
static TimeInterval now(SystemClockType::Enum clockType)
Definition bsls_systemtime.h:175
unsigned long long Uint64
Definition bsls_types.h:137