47#if LASS_HAVE_WIN32_THREADS
49#elif LASS_HAVE_PTHREAD_H
52# error "[LASS BUILD MSG] Threading not supported for this platform"
60const TCpuSet availableProcessors()
63 static bool isInitialized =
false;
66 set = impl::availableProcessors();
72static TCpuSet forceCalculationAtStartup = availableProcessors();
76 return availableProcessors().size();
81 const TCpuSet& set = availableProcessors();
82 return static_cast<size_t>(std::count(set.begin(), set.end(),
true));
87 const TCpuSet& set = availableProcessors();
88 return processor < set.size() && set[processor];
95 pimpl_ =
new impl::MutexInternal;
101 LASS_ASSERT(pimpl_->lockCount() == 0);
102 if (pimpl_->lockCount() > 0)
104 std::cerr <<
"[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: "
105 <<
"destroying a CriticalSection that still has "
106 << pimpl_->lockCount() <<
" locks." << std::endl;
121 return pimpl_->tryLock();
130bool Mutex::isLocked()
const
133 return pimpl_->lockCount() > 0;
141CriticalSection::CriticalSection(
void )
143 pimpl_ =
new impl::CriticalSectionInternal;
146CriticalSection::~CriticalSection(
void)
149 impl::CriticalSectionInternal* pimpl =
static_cast<impl::CriticalSectionInternal*
>(pimpl_);
150 LASS_ASSERT(pimpl->lockCount() == 0);
151 if (pimpl->lockCount() > 0)
153 std::cerr <<
"[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: "
154 <<
"destroying a CriticalSection that still has "
155 << pimpl->lockCount() <<
" locks." << std::endl;
161void CriticalSection::lock()
164 impl::CriticalSectionInternal* pimpl =
static_cast<impl::CriticalSectionInternal*
>(pimpl_);
171 impl::CriticalSectionInternal* pimpl =
static_cast<impl::CriticalSectionInternal*
>(pimpl_);
172 return pimpl->tryLock();
175void CriticalSection::unlock()
178 impl::CriticalSectionInternal* pimpl =
static_cast<impl::CriticalSectionInternal*
>(pimpl_);
182bool CriticalSection::isLocked()
const
185 impl::CriticalSectionInternal* pimpl =
static_cast<impl::CriticalSectionInternal*
>(pimpl_);
186 return pimpl->lockCount() > 0;
193Condition::Condition(
void)
195 pimpl_ =
new impl::ConditionInternal;
198Condition::~Condition(
void)
204void Condition::wait()
210WaitResult Condition::wait(
unsigned long iMilliSeconds)
213 return pimpl_->wait(iMilliSeconds);
216void Condition::signal()
222void Condition::broadcast()
232Thread::Thread(
ThreadKind iKind,
const char* name)
234 pimpl_ =
new impl::ThreadInternal(*
this, iKind, name);
266 pimpl_->bind(processor);
269const TCpuSet Thread::affinity()
const
272 return pimpl_->affinity();
275void Thread::sleep(
unsigned long iMilliSeconds)
277 impl::ThreadInternal::sleep(iMilliSeconds);
282 impl::ThreadInternal::yield();
289 impl::ThreadInternal::bindCurrent(processor);
296ThreadLocalStorage::ThreadLocalStorage(
void (*destructor)(
void*))
298 pimpl_ =
new impl::ThreadLocalStorageInternal(destructor);
301ThreadLocalStorage::~ThreadLocalStorage()
307void* ThreadLocalStorage::get()
const
310 return pimpl_->get();
313void ThreadLocalStorage::set(
void* value)
static void bindCurrent(size_t processor)
bind current thread to a processor (current as in callee's context)
void bind(size_t processor)
bind this thread to a processor (this as in this-pointer)
bool isAvailableProcessor(size_t processor)
Check whether a processor is avaialable.
size_t numberOfAvailableProcessors()
Return total number of processors in machine that are online.
LockResult
Return code for lock functions.
size_t numberOfProcessors()
Return highest id of processor + 1, in this machine.
WaitResult
Return code for wait functions.
general utility, debug facilities, ...
Library for Assembled Shared Sources.