21#if defined(__BORLANDC__)
45void TCountedSemaphore::Release()
53void TEventSemaphore::Release()
126 Size = size >= 0 ? size : count;
131 for (;
i < Count;
i++)
133 for (;
i < Size;
i++)
148 Sems[Count++] = &
sem;
154 CHECK(Count <= Size);
155 for (
int i = 0;
i < Count;
i++)
156 if (Sems[
i] == &
sem) {
157 for (
int j =
i;
j < Count-1;
j++)
159 Sems[Count-1] =
nullptr;
165void TSemaphoreSet::Release(
int index)
170 for (
int i = 0;
i < Count;
i++)
175static HANDLE* newHandles(
const TSemaphoreSet& set)
178 for (
int i = 0;
i < set.GetCount();
i++) {
204 if (InitLock(set.Count,
wait,
274 static TNtDll_& GetInstance()
300 ULONG sharedExclusive;
301 HANDLE hExclusiveSemaphore;
302 ULONG exclusiveWaiters;
303 ULONG numberOfWaiters;
309 typedef RTL_RESOURCE* PRTL_RESOURCE;
322 RtlInitializeResource(*
this,
"RtlInitializeResource"),
323 RtlDeleteResource(*
this,
"RtlDeleteResource"),
324 RtlAcquireResourceExclusive(*
this,
"RtlAcquireResourceExclusive"),
325 RtlAcquireResourceShared(*
this,
"RtlAcquireResourceShared"),
326 RtlReleaseResource(*
this,
"RtlReleaseResource"),
327 RtlDumpResource(*
this,
"RtlDumpResource")
332 TNtDll_(
const TNtDll_&);
343struct TMRSWSection::TPimpl
346 TNtDll_::RTL_RESOURCE RtlResource;
348 TPimpl(TNtDll_&
dll) : Dll(
dll) {}
352 : Pimpl(
new TPimpl(TNtDll_::GetInstance()))
354 Pimpl->Dll.RtlInitializeResource(&Pimpl->RtlResource);
359 Pimpl->Dll.RtlDeleteResource(&Pimpl->RtlResource);
365 Pimpl->Dll.RtlDumpResource(&Pimpl->RtlResource);
371 TNtDll_&
dll = Section.Pimpl->Dll;
372 TNtDll_::PRTL_RESOURCE
r = &Section.Pimpl->RtlResource;
374 dll.RtlAcquireResourceShared(
r,
wait) :
375 dll.RtlAcquireResourceExclusive(
r,
wait);
383 TNtDll_::PRTL_RESOURCE
r = &
Section.Pimpl->RtlResource;
384 dll.RtlReleaseResource(
r);
403 TerminationRequested(0),
416 TerminationRequested(0),
434 TerminationRequested(0),
460 if (
this != &thread) {
464 TerminationRequested =
false;
472#if defined(BI_COMP_MSC)
485 WARN(!
ok,
_T(
"TThread::~TThread: Terminating due to failed precondition. Error: ")
487 if (!
ok) std::terminate();
492# if !defined(BI_MULTI_THREAD_RTL) || !defined(BI_COMP_BORLANDC)
511# if defined(BI_MULTI_THREAD_RTL)
514 Handle =
::CreateThread(0, 0, &TThread::Execute,
this, 0, &ThreadId);
589 TerminationRequested =
true;
602 return ::WaitForSingleObject(Handle,
timeout);
604 return static_cast<ulong>(-1);
628 _T(
" [id:") << Handle <<
_T(
']'));
629 return ::SetThreadPriority(Handle,
pri);
651#if defined(BI_MULTI_THREAD_RTL)
680# if (defined(BI_COMP_MSC)||defined(BI_COMP_GNUC)) && defined(BI_MULTI_THREAD_RTL)
691TThread::CheckStatus()
const
706TThread::TThreadError::TThreadError(TErrorType
type)
708 TXBase(MakeString(
type)),
718tstring TThread::TThreadError::MakeString(TErrorType
type)
721 _T(
"Suspend() before Run()"),
722 _T(
"Resume() before Run()"),
723 _T(
"Resume() during Run()"),
724 _T(
"Suspend() after Exit()"),
725 _T(
"Resume() after Exit()"),
726 _T(
"creation failure"),
727 _T(
"destroyed before Exit()"),
728 _T(
"illegal assignment"),
729 _T(
"Multithreaded Runtime not selected"),
733 Msg =
_T(
"Error[thread]: ");
740#if defined(BI_MULTI_THREAD_RTL) && defined(OWL5_COMPAT)
746 while(index >= (
int)Data.Size())
759static long _owlTlsRef = 0;
#define OWL_DIAG_DEFINE_GROUP_INIT(f, g, e, l)
#define WARN(condition, message)
#define TRACEX(group, level, message)
TFileTime is a class derived from the structure FILETIME.
TLock(TMRSWSection &, bool shared, bool wait=true)
shared == true; allows multiple (read) access to the section.
TXLockFailure(const tstring &msg)
Multiple Read, Single Write section.
void Dump()
Dumps the current state of the section to the debugger output.
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Base class for handle-based thread synchronization classes, TMutex, TCountedSemaphore and TEventSemap...
THandle Handle
Derived class must initialize.
void Release(bool relinquish=false)
TLock(const TSemaphoreSet &set, TWaitWhat wait, ulong timeOut=NoLimit, bool alertable=false)
Assumes that set is not modified while locked.
bool InitLock(int count, TWaitWhat wait, int index)
Semaphore object aggregator.
void Remove(const TSemaphore &sem)
TSemaphoreSet(const TSemaphore *sems[], int size=-1)
sems is initial array of sem ptrs, may be 0 to add sems later, size is maximum sems to hold,...
void Add(const TSemaphore &sem)
The error class that defines the objects that are thrown when an error occurs.
@ SuspendBeforeRun
The user called Suspend() on an object before calling Start().
@ AssignError
An attempt was made to assign to an object that was not in either the Created or the Finished state.
@ ResumeBeforeRun
The user called Resume() on an object before calling Start().
@ DestroyBeforeExit
The object's destructor was invoked its thread had exited.
@ ResumeDuringRun
The user called Resume() on a thread that was not Suspended.
@ SuspendAfterExit
The user called Suspend() on an object whose thread had already exited.
@ CreationFailure
The operating system was unable to create the thread.
@ ResumeAfterExit
The user called Resume() on an object whose thread had already exited.
TThread provides a system-independent interface to threads.
TThread()
Create a thread. Derived class overrides Run()
ulong TerminateAndWait(ulong timeout=NoLimit)
Combines the behavior of Terminate() and WaitForExit().
ulong WaitForExit(ulong timeout=NoLimit)
Blocks the calling thread until the internal thread exits or until the time specified by timeout,...
THandle Start()
Starts the thread executing.
int SetPriority(int)
Can pass a TPriority for simplicity.
TStatus GetStatus() const
Gets the current status of the thread.
virtual ~TThread()
TThread destructor.
const TThread & operator=(const TThread &)
TThread assignment operator.
ulong Suspend()
Suspends execution of the thread.
ulong Resume()
Resumes execution of a suspended thread.
void Exit(ulong code)
Alternative to returning from Run()
virtual void Terminate()
Mark the thread for termination.
TStatus
Identifies the states that the class can be in.
@ Created
The class has been created but the thread has not been started.
@ Finished
The thread has finished execution.
@ Suspended
The thread has been suspended.
@ Invalid
The object is invalid. Currently this happens only when the operating system is unable to start the t...
@ Running
The thread is running.
bool Set(const TFileTime &duetime, int32 period=0, PTIMERAPCROUTINE compFunc=nullptr, void *param=nullptr, bool resume=false)
TWaitableTimer(bool manualReset=false, LPCTSTR name=nullptr, LPSECURITY_ATTRIBUTES sa=nullptr)
Derived from xmsg, TXBase is the base class for ObjectWindows and ObjectComponents exception-handling...
TXOwl is root class of the ObjectWindows exception hierarchy.
VOID(APIENTRY * PTIMERAPCROUTINE)(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue, DWORD dwTimerHighValue)
Encapsulation of Waitable Timer over Borland Classlib TSemaphore hierarchy.
Definition of class TModule.
Object Windows Library (OWLNext Core)
ObjectWindows exception class & function definitions.
#define CONST_CAST(targetType, object)
#define STATIC_CAST(targetType, object)
Various types of smart pointer templatized classes.