Unit Threads

From Ultibo.org
Revision as of 01:56, 22 April 2022 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


Ultibo Threads Interface unit

Locking Primitives

Spin -

A simple spin lock for fast mutually exclusive access to data. Threads "spin" while waiting to acquire the lock and do not yield the CPU unless pre-empted.

Non recursive (can only be acquired once by the same thread)

Includes IRQ/FIQ entry and exit routines to Save/Restore the IRQ/FIQ state.

Suitable for use by Interrupt handlers if non interrupt callers use the IRQ/FIQ entry and exit routines to Lock and Unlock.

Suitable for use on multiprocessor systems if the lock is allocated from shared memory (Determined during initialization).

Not recommended for long held operations or holding during I/O operations.

Access is not serialized, the next thread to try obtaining the lock when it is released will succeed even if that thread was not the first waiting.

Usage:

Create/Destroy

Spin locks are created using SpinCreate() and destroyed using SpinDestroy(), these functions should not be called from within an Interrupt handler. Lock/Unlock (Data accessed only by threads)

To synchronize data access between threads each thread should call SpinLock() before accessing the data and SpinUnlock() when finished accessing the data. These calls do not affect the state of IRQs or FIQs and therefore do not impact interrupt latency. Lock/Unlock (Data accessed by threads and interrupt handlers)

To use a Spin lock to synchronize data access between threads and an interrupt handler each thread should call SpinLockIRQ() or SpinLockFIQ(), depending on whether the interrupt handler is servicing IRQ or FIQ requests, before accessing the data and SpinUnlockIRQ() or SpinUnlockFIQ() when finished accessing the data. These calls disable interrupts before acquiring the lock (with deadlock protection) and restore interrupts after releasing the lock and therefore should only be used to protect very short sections of code accessing shared data to minimize the impact on interrupt latency.

Interrupt handlers should call SpinLock() before accessing the data and SpinUnlock() when finished accessing the data. In a Uniprocessor system it is technically not necessary for interrupt handlers to call lock/unlock as the use of IRQ/FIQ disable/enable will prevent interrupt handlers from executing while a thread has the lock. On a Multiprocessor system however interrupt handlers can execute on one processor while a thread is executing on another (which will not deadlock), to correctly synchronize data access both threads and interrupt handlers should call the appropriate lock/unlock before and after access to the data.

Lock Hierarchy -

It is safe to acquire one lock using SpinLock() then another lock using SpinLock() and then release them in reverse order.

It is also safe to acquire one lock using SpinLock() then another lock using SpinLockIRQ(or FIQ)() and then release them in reverse order.

It is NOT safe to acquire one lock using SpinLockIRQ(or FIQ)() then another lock using SpinLock() and then release them in reverse order. This is because the first SpinLockIRQ(or FIQ)() can disable the scheduling and prevent thread preemption. If another thread is already holding the second lock then this sequence will deadlock (except on a multicore system where the other thread is running on a different CPU).

It is also safe to acquire one lock using SpinLockIRQ(or FIQ)() then another lock using SpinLockIRQ(or FIQ)() and then release them in reverse order. In this case you must ensure that any thread acquiring the second lock also calls SpinLockIRQ(or FIQ)() to thereby avoid the deadlock.

It is NOT safe to acquire one lock using SpinLockIRQ(or FIQ)() then another lock using SpinLockIRQ(or FIQ)() and then release them in the SAME order. If the situation absolutely requires this behaviour then you must use SpinExchangeIRQ(or FIQ)() when holding both locks in order to reverse the order of the IRQ or FIQ re-enabling.

Mutex -

A mutually exclusive lock for controlling access to data. Threads yield while waiting to acquire the lock.

Non recursive (can only be acquired once by the same thread) (Recursive if MUTEX_FLAG_RECURSIVE specified)

Not suitable for use by Interrupt handlers.

Suitable for use on multiprocessor systems if the lock is allocated from shared memory (Determined during initialization).

Recommended for long held operations or holding during I/O operations.

Access is not serialized, the next thread to try obtaining the lock when it is released will succeed even if that thread was not the first waiting.

CriticalSection -

A mutually exclusive lock for serializing access to data. Threads are placed on a wait list while waiting to acquire the lock.

Recursive (can be acquired multiple times by the same thread)

Not suitable for use by Interrupt handlers.

Suitable for use on multiprocessor systems.

Recommended for long held operations or holding during I/O operations.

Access is serialized, the next thread to obtain the lock when it is released will be the thread that has been waiting longest (See also stolen wakeups below).

Semaphore -

Suitable for use by Interrupt handlers for signaling only if created with SEMAPHORE_FLAG_IRQ or FIQ (Interrupt handlers must not call wait).

Suitable for use on multiprocessor systems.

Access is serialized, the next thread to acquire the semaphore when it is signaled will be the thread that has been waiting longest (See also stolen wakeups below).

Synchronizer -

A reader/writer lock for serializing multiple concurrent reads and single writes to data. Threads are placed on a wait list while waiting to acquire the lock.

Recursive (reader lock can be acquired multiple times by the same thread or by other threads/writer lock can be acquired multiple times by the same thread).

Not suitable for use by Interrupt handlers.

Suitable for use on multiprocessor systems.

Recommended for long held operations or holding during I/O operations.

Access is serialized, the next thread to obtain the lock when it is released will be the thread that has been waiting longest (See also stolen wakeups below).

Condition -

A condition variable for coordinating synchronized access to resources by multiple threads. Condition variables are similar in concept to both Semaphores and Events but do not retain any internal state information so threads always wait until they are woken or the specified timeout interval expires.

Not suitable for use by Interrupt handlers.

Suitable for use on multiprocessor systems.

Access is serialized, the next thread released when a condition is woken will be the thread that has been waiting longest (See also stolen wakeups below).

Completion -

A completion is similar in concept to both condition variables and events but behaves differently to each of them. Completions are designed to be similar to the Linux synchronization object of the same name and provide a light weight mechanism for allowing one or more threads to wait for a signal that they can proceed. The completion differs from a condition variable because it maintains an internal state, once the state has been set (complete) threads pass through the completion without waiting (until the state is reset). This is similar to an event (see below) but in the case of a completion the state remains set indefinitely or until reset is called, a completion also allows explicitly releasing one thread at a time or all threads at once. More generally the event was created to model a behaviour that is similar to the same object in Windows and the completion models the Linux object instead.

Completions can use a counted state rather than a single state if they are created with COMPLETION_FLAG_COUNTED, this is to mimic the implementation of the Linux variation however there is a slight but important change in the way counted completions are implemented in Ultibo. The Linux completion sets the count to UMAX_INT / 2 on complete_all() which is documented as "effectively infinite". This is of course incorrect and seriously flawed because the count value is only set to a little over 2 billion, a long running application could easily consume this count with calls to wait_for_completion() and then the application would potentially fail without explanation.

To prevent this same fatal flaw the Ultibo implementation sets the count at LongWord(-1) on CompletionCompleteAll() and all other operations check for this value before incrementing or decrementing the count further. In this way the setting of complete all is genuinely infinite and will not fail on a long running application.

Suitable for use by Interrupt handlers to call complete only if created with COMPLETION_FLAG_IRQ or FIQ (Interrupt handlers must not call wait).

Suitable for use on multiprocessor systems.

Access is serialized, the next thread released when a completion is set will be the thread that has been waiting longest (See also stolen wakeups below).

Stolen wakeups:

Locking and synchronization types such as CriticalSection, Semaphore, Condition, Event, Messageslot and Mailslot use a wait queue internally to determine which thread has been waiting the longest. When a thread is removed from the wait queue so it can obtain the lock, semaphore, event etc there is a small window where the lock, semaphore or event may be acquired by another thread before the thread that was just woken from the wait queue. This is called a stolen wakeup and can happen in many systems including Windows and Linux, in some systems the caller is expected to check the state of a predicate value on return in order to detect a stolen wakeup. In Ultibo the code within the lock, semaphore, event etc functions automatically checks for a stolen wakeup and takes appropriate action to either return the thread to the wait queue or return with a timeout (where appropriate) so that the caller can respond accordingly.

In no case will a call to a locking or synchronization function fail due to a stolen wakeup, the worst case scenario is that a thread may wait longer than it should have (ie it is returned to the back of the queue) or it may return with a timeout before the specified timeout value has expired.

Constants



[Expand]
Lock flag LOCK_FLAG_*


[Expand]
Spin signature SPIN_SIGNATURE_*


[Expand]
Spin state SPIN_STATE_*


[Expand]
Mutex signature MUTEX_SIGNATURE_*


[Expand]
Mutex state MUTEX_STATE_*


[Expand]
Mutex flags MUTEX_FLAG_*


[Expand]
Critical section signature CRITICAL_SECTION_SIGNATURE_*


[Expand]
Critical section state CRITICAL_SECTION_STATE_*


[Expand]
Semaphore signature SEMAPHORE_SIGNATURE_*


[Expand]
Semaphore flag SEMAPHORE_FLAG_*


[Expand]
Synchronizer signature SYNCHRONIZER_SIGNATURE_*


[Expand]
Synchronizer state SYNCHRONIZER_STATE_*


[Expand]
Synchronizer flag SYNCHRONIZER_FLAG_*


[Expand]
Condition constants CONDITION_*


[Expand]
Condition flags CONDITION_FLAG_*


[Expand]
Condition lock flags CONDITION_LOCK_FLAG_*


[Expand]
Completion constants COMPLETION_*


[Expand]
Completion state COMPLETION_STATE_*


[Expand]
Completion flag COMPLETION_FLAG_*


[Expand]
List signature LIST_SIGNATURE_*


[Expand]
List type LIST_TYPE_*


[Expand]
List flag LIST_FLAG_*


[Expand]
Queue signature QUEUE_SIGNATURE_*


[Expand]
Queue type QUEUE_TYPE_*


[Expand]
Queue flag QUEUE_FLAG_*


[Expand]
Queue key QUEUE_KEY_*


[Expand]
Thread signature THREAD_SIGNATURE_*


[Expand]
Thread type THREAD_TYPE_*


[Expand]
Thread flag THREAD_FLAG_*


[Expand]
Thread state THREAD_STATE_*


[Expand]
Thread priority THREAD_PRIORITY_*


[Expand]
Thread name THREAD_NAME_*


[Expand]
Thread priority *_THREAD_PRIORITY


[Expand]
Thread create THREAD_CREATE_*


[Expand]
Thread TLS THREAD_TLS_*


[Expand]
Thread TLS flag THREAD_TLS_FLAG_*


[Expand]
Thread wait THREAD_LISTS_*


[Expand]
Messageslot signature MESSAGESLOT_SIGNATURE_*


[Expand]
Messageslot flag MESSAGESLOT_FLAG_*


[Expand]
Mailslot signature MAILSLOT_SIGNATURE_*


[Expand]
Buffer signature BUFFER_SIGNATURE_*


[Expand]
Buffer flag BUFFER_FLAG_*


[Expand]
Event signature EVENT_SIGNATURE_*


[Expand]
Event state EVENT_STATE_*


[Expand]
Event flag EVENT_FLAG_*


[Expand]
Timer signature TIMER_SIGNATURE_*


[Expand]
Timer state TIMER_STATE_*


[Expand]
Timer flag TIMER_FLAG_*


[Expand]
Timer key TIMER_KEY_*


[Expand]
Worker signature WORKER_SIGNATURE_*


[Expand]
Worker flag WORKER_FLAG_*


[Expand]
Tasker task TASKER_TASK_*


[Expand]
Scheduler migration SCHEDULER_MIGRATION_*


[Expand]
Scheduler preempt SCHEDULER_PREEMPT_*


[Expand]
Scheduler allocation SCHEDULER_ALLOCATION_*


[Expand]
Scheduler mask SCHEDULER_MASK_*


[Expand]
Scheduler quantum SCHEDULER_QUANTUM_*


[Expand]
Thread logging THREAD_LOG_*


Type definitions



Spin entry

[Expand]

PSpinEntry = ^TSpinEntry;

TSpinEntry = record

Mutex entry

[Expand]

PMutexEntry = ^TMutexEntry;

TMutexEntry = record

Critical section entry

[Expand]

PCriticalSectionEntry = ^TCriticalSectionEntry;

TCriticalSectionEntry = record

Semaphore entry

[Expand]

PSemaphoreEntry = ^TSemaphoreEntry;

TSemaphoreEntry = record

Synchronizer entry

[Expand]

PSynchronizerEntry = ^TSynchronizerEntry;

TSynchronizerEntry = record

Condition entry

[Expand]

PConditionEntry = ^TConditionEntry;

TConditionEntry = record

Completion entry

[Expand]

PCompletionEntry = ^TCompletionEntry;

TCompletionEntry = record

List entry

[Expand]

PListEntry = ^TListEntry;

TListEntry = record

List element

[Expand]

PListElement = ^TListElement;

TListElement = record

List handles

[Expand]

PListHandles = ^TListHandles;

TListHandles = array[0..THREAD_LISTS_MAXIMUM - 1] of TListHandle;

Queue entry

[Expand]

PQueueEntry = ^TQueueEntry;

TQueueEntry = record

Queue element

[Expand]

PQueueElement = ^TQueueElement;

TQueueElement = record

Message list

[Expand]

PMessageList = ^TMessageList;

TMessageList = record

Message

[Expand]

PMessage = ^TMessage;

TMessage = record

Thread entry

[Expand]

PThreadEntry = ^TThreadEntry;

TThreadEntry = record

Thread snapshot

[Expand]

PThreadSnapshot = ^TThreadSnapshot;

TThreadSnapshot = record

Messageslot entry

[Expand]

PMessageslotEntry = ^TMessageslotEntry;

TMessageslotEntry = record

Mailslot entry

[Expand]

PMailslotEntry = ^TMailslotEntry;

TMailslotEntry = record

Buffer entry

[Expand]

PBufferEntry = ^TBufferEntry;

TBufferEntry = record

Buffer item

[Expand]

PBufferItem = ^TBufferItem;

TBufferItem = record

Event entry

[Expand]

PEventEntry = ^TEventEntry;

TEventEntry = record

Timer list

[Expand]

PTimerList = ^TTimerList;

TTimerList = record

Timer item

[Expand]

PTimerItem = ^TTimerItem;

TTimerItem = record

Timer entry

[Expand]

PTimerEntry = ^TTimerEntry;

TTimerEntry = record

Worker request

[Expand]

PWorkerRequest = ^TWorkerRequest;

TWorkerRequest = record

Tasker list

[Expand]

PTaskerList = ^TTaskerList;

TTaskerList = record

Tasker task

[Expand]

PTaskerTask = ^TTaskerTask;

TTaskerTask = record

Tasker thread send message

[Expand]

PTaskerThreadSendMessage = ^TTaskerThreadSendMessage;

TTaskerThreadSendMessage = record

Tasker messageslot send

[Expand]

PTaskerMessageslotSend = ^TTaskerMessageslotSend;

TTaskerMessageslotSend = record

Tasker semaphore signal

[Expand]

PTaskerSemaphoreSignal = ^TTaskerSemaphoreSignal;

TTaskerSemaphoreSignal = record

Thread info

[Expand]

PThreadInfo = ^TThreadInfo;

TThreadInfo = record

CPU start

TCPUStart = procedure(CPUID:LongWord);

Primary initialization

TPrimaryInit = procedure;

Scheduler initialization

TSchedulerInit = procedure;

Scheduler start

TSchedulerStart = procedure(CPUID:LongWord);

Secondary initialization

TSecondaryInit = procedure;

Secondary boot

TSecondaryBoot = procedure(CPUID:LongWord);

Spin lock

TSpinLock = function(Spin:PSpinEntry):LongWord;

Spin unlock

TSpinUnlock = function(Spin:PSpinEntry):LongWord;

Spin lock IRQ

TSpinLockIRQ = function(Spin:PSpinEntry):LongWord;

Spin unlock IRQ

TSpinUnlockIRQ = function(Spin:PSpinEntry):LongWord;

Spin lock FIQ

TSpinLockFIQ = function(Spin:PSpinEntry):LongWord;

Spin unlock FIQ

TSpinUnlockFIQ = function(Spin:PSpinEntry):LongWord;

Spin lock IRQ/FIQ

TSpinLockIRQFIQ = function(Spin:PSpinEntry):LongWord;

Spin unlock IRQ/FIQ

TSpinUnlockIRQFIQ = function(Spin:PSpinEntry):LongWord;

Spin check IRQ

TSpinCheckIRQ = function(Spin:PSpinEntry):Boolean;

Spin check FIQ

TSpinCheckFIQ = function(Spin:PSpinEntry):Boolean;

Spin exchange IRQ

TSpinExchangeIRQ = function(Spin1,Spin2:PSpinEntry):LongWord;

Spin exchange FIQ

TSpinExchangeFIQ = function(Spin1,Spin2:PSpinEntry):LongWord;

Spin mask exchange

TSpinMaskExchange = function(Spin1,Spin2:PSpinEntry):LongWord;

Mutex lock

TMutexLock = function(Mutex:PMutexEntry):LongWord;

Mutex unlock

TMutexUnlock = function(Mutex:PMutexEntry):LongWord;

Mutex try lock

TMutexTryLock = function(Mutex:PMutexEntry):LongWord;

Critical section lock

TCriticalSectionLock = function(CriticalSection:PCriticalSectionEntry):LongWord;

Critical section lock ex

TCriticalSectionLockEx = function(CriticalSection:PCriticalSectionEntry; Timeout:LongWord):LongWord;

Critical section unlock

TCriticalSectionUnlock = function(CriticalSection:PCriticalSectionEntry):LongWord;

Critical section try lock

TCriticalSectionTryLock = function(CriticalSection:PCriticalSectionEntry):LongWord;

Semaphore wait

TSemaphoreWait = function(Semaphore:PSemaphoreEntry):LongWord;

Semaphore wait ex

TSemaphoreWaitEx = function(Semaphore:PSemaphoreEntry; Timeout:LongWord):LongWord;

Semaphore signal

TSemaphoreSignal = function(Semaphore:PSemaphoreEntry):LongWord;

Synchronizer lock

TSynchronizerLock = function(Synchronizer:PSynchronizerEntry):LongWord;

Synchronizer lock ex

TSynchronizerLockEx = function(Synchronizer:PSynchronizerEntry; Timeout:LongWord):LongWord;

Synchronizer unlock

TSynchronizerUnlock = function(Synchronizer:PSynchronizerEntry):LongWord;

Synchronizer convert

TSynchronizerConvert = function(Synchronizer:PSynchronizerEntry):LongWord;

Synchronizer convert ex

TSynchronizerConvertEx = function(Synchronizer:PSynchronizerEntry; Timeout:LongWord):LongWord;

Condition wait

TConditionWait = function(Condition:PConditionEntry; Timeout:LongWord):LongWord;

Condition wait mutex

TConditionWaitMutex = function(Condition:PConditionEntry; Mutex:TMutexHandle; Timeout:LongWord):LongWord;

Condition wait synchronizer

TConditionWaitSynchronizer = function(Condition:PConditionEntry; Synchronizer:TSynchronizerHandle; Flags,Timeout:LongWord):LongWord;

Condition wait critical section

TConditionWaitCriticalSection = function(Condition:PConditionEntry; CriticalSection:TCriticalSectionHandle; Timeout:LongWord):LongWord;

Condition wake

TConditionWake = function(Condition:PConditionEntry):LongWord;

Condition wake all

TConditionWakeAll = function(Condition:PConditionEntry):LongWord;

Completion wait

TCompletionWait = function(Completion:PCompletionEntry; Timeout:LongWord):LongWord;

Completion try wait

TCompletionTryWait = function(Completion:PCompletionEntry):LongWord;

Completion reset

TCompletionReset = function(Completion:PCompletionEntry):LongWord;

Completion complete

TCompletionComplete = function(Completion:PCompletionEntry):LongWord;

Completion complete all

TCompletionCompleteAll = function(Completion:PCompletionEntry):LongWord;

Messageslot send

TMessageslotSend = function(Messageslot:PMessageslotEntry; Message:PMessage):LongWord;

Messageslot receive

TMessageslotReceive = function(Messageslot:PMessageslotEntry; Message:PMessage):LongWord;

Messageslot receive ex

TMessageslotReceiveEx = function(Messageslot:PMessageslotEntry; Message:PMessage; Timeout:LongWord):LongWord;

Mailslot send

TMailslotSend = function(Mailslot:PMailslotEntry; Data:PtrInt):LongWord;

Mailslot send ex

TMailslotSendEx = function(Mailslot:PMailslotEntry; Data:PtrInt; Timeout:LongWord):LongWord;

Mailslot receive

TMailslotReceive = function(Mailslot:PMailslotEntry):PtrInt;

Mailslot receive ex

TMailslotReceiveEx = function(Mailslot:PMailslotEntry; Timeout:LongWord):PtrInt;

Buffer get

TBufferGet = function(Buffer:PBufferEntry):Pointer;

Buffer get ex

TBufferGetEx = function(Buffer:PBufferEntry; Timeout:LongWord):Pointer;

Buffer free

TBufferFree = function(Buffer:Pointer):LongWord;

Buffer iterate

TBufferIterate = function(Buffer:PBufferEntry; Previous:Pointer):Pointer;

Event wait

TEventWait = function(Event:PEventEntry):LongWord;

Event wait ex

TEventWaitEx = function(Event:PEventEntry; Timeout:LongWord):LongWord;

Event set

TEventSet = function(Event:PEventEntry):LongWord;

Event reset

TEventReset = function(Event:PEventEntry):LongWord;

Event pulse

TEventPulse = function(Event:PEventEntry):LongWord;

Timer enable

TTimerEnable = function(Timer:PTimerEntry):LongWord;

Timer enable ex

TTimerEnableEx = function(Timer:PTimerEntry; Interval:LongWord; Event:TTimerEvent; Data:Pointer):LongWord;

Timer disable

TTimerDisable = function(Timer:PTimerEntry):LongWord;

Timer check

TTimerCheck = function:LongWord;

Timer trigger

TTimerTrigger = function:LongWord;

Tasker check

TTaskerCheck = function:LongWord;

Tasker trigger

TTaskerTrigger = function:LongWord;

Thread get current

TThreadGetCurrent = function:TThreadHandle;

Thread set current

TThreadSetCurrent = function(Thread:TThreadHandle):LongWord;

Thread start

TThreadStart = function(Parameter:Pointer):PtrInt;

Thread end

TThreadEnd = procedure(ExitCode:LongWord);

Scheduler check

TSchedulerCheck = function(CPUID:LongWord):LongWord;

Scheduler wakeup

TSchedulerWakeup = function(CPUID:LongWord):LongWord;

Scheduler expire

TSchedulerExpire = function(CPUID:LongWord):LongWord;

Scheduler switch

TSchedulerSwitch = function(CPUID:LongWord; Thread:TThreadHandle):TThreadHandle;

Scheduler select

TSchedulerSelect = function(CPUID:LongWord; Thread:TThreadHandle; Yield:Boolean):TThreadHandle;

Scheduler reschedule

TSchedulerReschedule = function (Yield:Boolean):LongWord;

Scheduler migration enable

TSchedulerMigrationEnable = function:LongWord;

Scheduler migration disable

TSchedulerMigrationDisable = function:LongWord;

Scheduler preempt enable

TSchedulerPreemptEnable = function(CPUID:LongWord):LongWord;

Scheduler preempt disable

TSchedulerPreemptDisable = function(CPUID:LongWord):LongWord;

Scheduler allocation enable

TSchedulerAllocationEnable = function(CPUID:LongWord):LongWord;

Scheduler allocation disable

TSchedulerAllocationDisable = function(CPUID:LongWord):LongWord;

Thread setup stack

TThreadSetupStack = function(StackBase:Pointer; StartProc:TThreadStart; ReturnProc:TThreadEnd; Parameter:Pointer):Pointer;


Public variables



Thread logging

THREAD_DEFAULT_LOG_LEVEL:LongWord = THREAD_LOG_LEVEL_DEBUG; Minimum level for Thread messages. Only messages with level greater than or equal to this will be printed.
THREAD_LOG_ENABLED:Boolean;

Scheduler variables

SchedulerThreadNext:LongWord; The CPU to assign the next created thread to, round robin incremented on each create (Protected by ThreadTableLock)
SchedulerThreadMigration:LongWord; Enable or Disable thread migration (SCHEDULER_MIGRATION_DISABLED or SCHEDULER_MIGRATION_ENABLED
SchedulerMigrationQuantum:LongWord; Quantum for thread migration checks (CPU 0 only)
SchedulerThreadCount:array of LongWord; Current number of ready threads per CPU (One per CPU, allocated by scheduler initialization) (Protected by InterlockedIncrement/Decrement)
SchedulerThreadQuantum:array of LongWord; Quantum of current thread per CPU (One per CPU, allocated by scheduler initialization)
SchedulerThreadPreempt:array of LongWord; Current state of thread preemption per CPU (eg SCHEDULER_PREEMPT_DISABLED) (One per CPU, allocated by scheduler initialization)
SchedulerThreadAllocation:array of LongWord; Current state of thread allocation per CPU (eg SCHEDULER_ALLOCATION_DISABLED) (One per CPU, allocated by scheduler initialization)
SchedulerPriorityMask:array of LongWord; Mask of ready threads at each priority level (One per CPU, allocated by scheduler initialization) (Protected by InterlockedOr/And)
SchedulerYieldCurrent:array of LongBool; Scheduler yield to current priority level status (One per CPU, allocated by scheduler initialization)
SchedulerStarvationNext:array of LongWord; Scheduler starvation priority round robin (One per CPU, allocated by scheduler initialization)
SchedulerStarvationQuantum:array of LongWord; Quantum for thread starvation checks per CPU (One per CPU, allocated by scheduler initialization)
SchedulerNoneQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level none (One per CPU, allocated by scheduler initialization)
SchedulerIdleQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level idle (One per CPU, allocated by scheduler initialization)
SchedulerLowestQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level lowest (One per CPU, allocated by scheduler initialization)
SchedulerLowerQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level lower (One per CPU, allocated by scheduler initialization)
SchedulerNormalQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level normal (One per CPU, allocated by scheduler initialization)
SchedulerHigherQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level higher (One per CPU, allocated by scheduler initialization)
SchedulerHighestQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level highest (One per CPU, allocated by scheduler initialization)
SchedulerCriticalQueue:array of TQueueHandle; Queue of threads that are ready to run at priority level critical (One per CPU, allocated by scheduler initialization)
SchedulerSleepQueue:array of TQueueHandle; Queue of threads that are currently sleeping (One per CPU, allocated by scheduler initialization)
SchedulerTimeoutQueue:array of TQueueHandle; Queue of threads that are currently waiting with a timeout (One per CPU, allocated by scheduler initialization)
SchedulerTerminationQueue:array of TQueueHandle; Queue of threads that have been terminated (One per CPU, allocated by scheduler initialization)
SchedulerLast:array of LongWord; The timer value of the last scheduler interrupt (One per CPU, allocated by scheduler initialization)
SchedulerInterrupts:array of LongWord; Current number of scheduler interrupts per CPU (When this reaches SCHEDULER_INTERRUPTS_PER_SECOND then UtilizationLast is updated and UtilizationCurrent is reset) (One per CPU, allocated by scheduler initialization)

Scheduler debug

SchedulerInterruptCounter:array of Int64;
SchedulerInterruptOffset:array of LongWord;
SchedulerInterruptMinOffset:array of LongWord;
SchedulerInterruptMaxOffset:array of LongWord;
SchedulerInterruptRollover:array of LongWord;
SchedulerSelectEntry:array of Int64; Number of times the scheduler select routine has been called (One per CPU)
SchedulerSelectYield:array of Int64; Number of times the scheduler select routine has been called with yield equal to true (One per CPU)
SchedulerSelectForce:array of Int64; Number of times the scheduler forced a thread switch due to starvation quantum (One per CPU)
SchedulerSelectNoMask:array of Int64; Number of times the scheduler selection encountered an empty priority mask (Should never happen)(One per CPU)
SchedulerSelectNormal:array of Int64; Number of times the scheduler selection used normal next highest priority to select thread (One per CPU)
SchedulerSelectInvalid:array of Int64; Number of times the scheduler selection resulted in INVALID_THREAD_HANDLE (Should never happen)(One per CPU)
SchedulerSelectFailure:array of Int64; Number of times the scheduler failed to enqueue the currently running thread (Should never happen)(One per CPU)
SchedulerSelectNoReady:array of Int64; Number of times the scheduler selection found no ready thread available to run (Should never happen)(One per CPU)
SchedulerSelectDefaulted:array of Int64; Number of times the scheduler selection defaulted to an IDLE or NONE thread (Should never happen)(One per CPU)
SchedulerStarvationReset:array of Int64; Number of times the scheduler reset the starvation quantum (One per CPU)
SchedulerStarvationDecrement:array of Int64; Number of times the scheduler decremented the starvation quantum (One per CPU)
SchedulerSelectCPU:array of Int64; Number of times the scheduler selection changed the CurrentCPU on a running thread (One per CPU)
SchedulerSelectPriority:array of Int64; Number of times the scheduler selection changed the Priority on a running thread (One per CPU)
SchedulerSelectAffinity:array of Int64; Number of times the scheduler selection changed the CurrentCPU on a running thread due to Affinity mismatch (One per CPU)
SchedulerSwitchEntry:array of Int64; Number of times the scheduler switch routine has been called (One per CPU)
SchedulerSwitchThread:array of TThreadHandle; The thread returned by scheduler select on the last scheduler switch call (One per CPU)
SchedulerSwitchCounter:array of Int64; Number of times the scheduler switch resulted in a thread switch (One per CPU)
SchedulerSwitchCurrent:array of Int64; Number of times the scheduler switch resulted in the current thread continuing (One per CPU)
SchedulerSwitchInvalid:array of Int64; Number of times the scheduler switch was returned INVALID_THREAD_HANDLE by scheduler select (Should never happen)(One per CPU)
SchedulerRescheduleEntry:array of Int64; Number of times the scheduler reschedule routine has been called (One per CPU)
SchedulerRescheduleThread:array of TThreadHandle; The thread returned by scheduler select on the last scheduler reschedule call (One per CPU)
SchedulerRescheduleCounter:array of Int64; Number of times the scheduler reschedule resulted in a thread switch (One per CPU)
SchedulerRescheduleCurrent:array of Int64; Number of times the scheduler reschedule resulted in the current thread continuing (One per CPU)
SchedulerRescheduleInvalid:array of Int64; Number of times the scheduler reschedule was returned INVALID_THREAD_HANDLE by scheduler select (Should never happen)(One per CPU)
SchedulerMigrationCounter:Int64; Number of times scheduler select invoked a thread migration (CPU 0 only)
SchedulerTerminationCounter:array of Int64; Number of threads destroyed by scheduler reschedule (After termination quantum)(One per CPU)
SchedulerSecondaryWaitCounter:array of Int64; Number of wait cycles performed by secondary CPUs while waiting for init completion (One per CPU)

Lock debug

SpinDeadlockCounter:Int64;
SpinRecursionCounter:Int64;
SpinRecursionThread:TThreadHandle;
SpinIRQThreadCounter:Int64;
SpinFIQThreadCounter:Int64;
SpinSWIThreadCounter:Int64;
SpinIdleThreadCounter:Int64;
MutexDeadlockCounter:Int64;
MutexRecursionCounter:Int64;
MutexRecursionThread:TThreadHandle;
MutexIRQThreadCounter:Int64;
MutexFIQThreadCounter:Int64;
MutexSWIThreadCounter:Int64;
MutexIdleThreadCounter:Int64;
CriticalSectionDeadlockCounter:Int64;
SemaphoreDeadlockCounter:Int64;
SynchronizerDeadlockCounter:Int64;
SynchronizerRecursionCounter:Int64;
ConditionDeadlockCounter:Int64;
CompletionDeadlockCounter:Int64;
MessageslotDeadlockCounter:Int64;
MailslotDeadlockCounter:Int64;
BufferDeadlockCounter:Int64;
EventDeadlockCounter:Int64;

Spin debug

SpinLockEntry:LongWord;
SpinUnlockEntry:LongWord;
SpinLockExit:LongWord;
SpinUnlockExit:LongWord;
SpinUnlockNoLock:LongWord;
SpinUnlockNoOwner:LongWord;
SpinLockCounter:LongWord;
SpinUnlockCounter:LongWord;
SpinDestroyCounter:LongWord;
SpinLockIRQCounter:LongWord;
SpinUnlockIRQCounter:LongWord;
SpinLockFIQCounter:LongWord;
SpinUnlockFIQCounter:LongWord;
SpinLockIRQFIQCounter:LongWord;
SpinUnlockIRQFIQCounter:LongWord;

Mutex debug

MutexLockEntry:LongWord;
MutexUnlockEntry:LongWord;
MutexLockExit:LongWord;
MutexUnlockExit:LongWord;
MutexUnlockNoLock:LongWord;
MutexUnlockNoOwner:LongWord;
MutexLockCounter:LongWord;
MutexUnlockCounter:LongWord;
MutexDestroyCounter:LongWord;

Heap manager variables

HeapLock:THeapLock;

RTL thread manager variables

ThreadVarBlockSize:DWORD;

Initialization handlers

PrimaryInitHandler:TPrimaryInit;
SchedulerInitHandler:TSchedulerInit;
SchedulerStartHandler:TSchedulerStart;
SecondaryInitHandler:TSecondaryInit;
SecondaryBootHandler:TSecondaryBoot;

SpinLock/Unlock handlers

SpinLockHandler:TSpinLock;
SpinUnlockHandler:TSpinUnlock;
SpinLockIRQHandler:TSpinLockIRQ;
SpinUnlockIRQHandler:TSpinUnlockIRQ;
SpinLockFIQHandler:TSpinLockFIQ;
SpinUnlockFIQHandler:TSpinUnlockFIQ;
SpinLockIRQFIQHandler:TSpinLockIRQFIQ;
SpinUnlockIRQFIQHandler:TSpinUnlockIRQFIQ;
SpinCheckIRQHandler:TSpinCheckIRQ;
SpinCheckFIQHandler:TSpinCheckFIQ;
SpinExchangeIRQHandler:TSpinExchangeIRQ;
SpinExchangeFIQHandler:TSpinExchangeFIQ;
SpinMaskExchangeHandler:TSpinMaskExchange;

MutexLock/Unlock handlers

MutexLockHandler:TMutexLock;
MutexUnlockHandler:TMutexUnlock;
MutexTryLockHandler:TMutexTryLock;

CriticalSection Lock/Unlock/TryLock handlers

CriticalSectionLockHandler:TCriticalSectionLock;
CriticalSectionLockExHandler:TCriticalSectionLockEx;
CriticalSectionUnlockHandler:TCriticalSectionUnlock;
CriticalSectionTryLockHandler:TCriticalSectionTryLock;

Semaphore Wait/Signal handlers

SemaphoreWaitHandler:TSemaphoreWait;
SemaphoreWaitExHandler:TSemaphoreWaitEx;
SemaphoreSignalHandler:TSemaphoreSignal;

Synchronizer Reader/WriterLock/Unlock handlers

SynchronizerReaderLockHandler:TSynchronizerLock;
SynchronizerWriterLockHandler:TSynchronizerLock;
SynchronizerReaderLockExHandler:TSynchronizerLockEx;
SynchronizerWriterLockExHandler:TSynchronizerLockEx;
SynchronizerReaderUnlockHandler:TSynchronizerUnlock;
SynchronizerWriterUnlockHandler:TSynchronizerUnlock;
SynchronizerReaderConvertHandler:TSynchronizerConvert;
SynchronizerWriterConvertHandler:TSynchronizerConvert;
SynchronizerReaderConvertExHandler:TSynchronizerConvertEx;

Condition Wait/Wake/WakeAll Handlers

ConditionWaitHandler:TConditionWait;
ConditionWaitMutexHandler:TConditionWaitMutex;
ConditionWaitSynchronizerHandler:TConditionWaitSynchronizer;
ConditionWaitCriticalSectionHandler:TConditionWaitCriticalSection;
ConditionWakeHandler:TConditionWake;
ConditionWakeAllHandler:TConditionWakeAll;

Completion Wait/TryWait/Reset/Complete/CompleteAll Handlers

CompletionWaitHandler:TCompletionWait;
CompletionTryWaitHandler:TCompletionTryWait;
CompletionResetHandler:TCompletionReset;
CompletionCompleteHandler:TCompletionComplete;
CompletionCompleteAllHandler:TCompletionCompleteAll;

Messageslot send and receive handlers

MessageslotSendHandler:TMessageslotSend;
MessageslotReceiveHandler:TMessageslotReceive;
MessageslotReceiveExHandler:TMessageslotReceiveEx;

Mailslot send and receive handlers

MailslotSendHandler:TMailslotSend;
MailslotSendExHandler:TMailslotSendEx;
MailslotReceiveHandler:TMailslotReceive;
MailslotReceiveExHandler:TMailslotReceiveEx;

Buffer Get/GetEx/Free handlers

BufferGetHandler:TBufferGet;
BufferGetExHandler:TBufferGetEx;
BufferFreeHandler:TBufferFree;
BufferIterateHandler:TBufferIterate;

Event Wait/Set/Reset/Pulse handlers

EventWaitHandler:TEventWait;
EventWaitExHandler:TEventWaitEx;
EventSetHandler:TEventSet;
EventResetHandler:TEventReset;
EventPulseHandler:TEventPulse;

Timer Enable/Disable/Check/Trigger handlers

TimerEnableHandler:TTimerEnable;
TimerEnableExHandler:TTimerEnableEx;
TimerDisableHandler:TTimerDisable;
TimerCheckHandler:TTimerCheck;
TimerTriggerHandler:TTimerTrigger;

Tasker Check/Trigger handlers

TaskerCheckHandler:TTaskerCheck;
TaskerTriggerHandler:TTaskerTrigger;

Thread Get/SetCurrent handlers

ThreadGetCurrentHandler:TThreadGetCurrent;
ThreadSetCurrentHandler:TThreadSetCurrent;

Scheduler Check/Wakeup/Expire/Select/Switch handlers

SchedulerCheckHandler:TSchedulerCheck;
SchedulerWakeupHandler:TSchedulerWakeup;
SchedulerExpireHandler:TSchedulerExpire;
SchedulerSwitchHandler:TSchedulerSwitch;
SchedulerSelectHandler:TSchedulerSelect;
SchedulerRescheduleHandler:TSchedulerReschedule;
SchedulerMigrationEnableHandler:TSchedulerMigrationEnable;
SchedulerMigrationDisableHandler:TSchedulerMigrationDisable;
SchedulerPreemptEnableHandler:TSchedulerPreemptEnable;
SchedulerPreemptDisableHandler:TSchedulerPreemptDisable;
SchedulerAllocationEnableHandler:TSchedulerAllocationEnable;
SchedulerAllocationDisableHandler:TSchedulerAllocationDisable;

Thread SetupStack handlers

ThreadSetupStackHandler:TThreadSetupStack;


Function declarations



Initialization functions

[Expand]
procedure LocksInit;
Description: Initialize Locks


[Expand]
procedure ThreadsInit;
Description: Initialize Threading


[Expand]
procedure PrimaryInit;
Description: Initialize the primary CPU


[Expand]
procedure SchedulerInit;
Description: Initialize the thread scheduler


[Expand]
procedure SchedulerStart(CPUID:LongWord);
Description: Initialize the thread scheduler for secondary CPUs (Where Applicable)


[Expand]
procedure SecondaryInit;
Description: Initialize the secondary CPUs (Where Applicable)


[Expand]
procedure SecondaryBoot(CPUID:LongWord);
Description: Boot the specified secondary CPU (Where Applicable)


[Expand]
procedure SecondaryStart(CPUID:LongWord);
Description: Startup procedure for secondary CPUs (Where Applicable)


[Expand]
function IRQExecute(Parameter:Pointer):PtrInt;
Description: IRQ thread function


[Expand]
function FIQExecute(Parameter:Pointer):PtrInt;
Description: FIQ thread function


[Expand]
function SWIExecute(Parameter:Pointer):PtrInt;
Description: SWI thread function


[Expand]
function IdleExecute(Parameter:Pointer):PtrInt;
Description: Idle thread function


[Expand]
function MainExecute(Parameter:Pointer):PtrInt;
Description: Main thread function


[Expand]
function TimerExecute(Parameter:Pointer):PtrInt;
Description: Timer thread function


[Expand]
function WorkerExecute(Parameter:Pointer):PtrInt;
Description: Worker thread function


[Expand]
function TimerPriorityExecute(Parameter:Pointer):PtrInt;
Description: Priority Timer thread function


[Expand]
function WorkerPriorityExecute(Parameter:Pointer):PtrInt;
Description: Priority Worker thread function


[Expand]
function IdleCalibrate:LongWord;
Description: Calibrate the idle thread loop by counting the number of loops in 100ms


Spin functions

[Expand]
function SpinCreate:TSpinHandle; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Create and insert a new Spin entry


[Expand]
function SpinCreateEx(InitialOwner:Boolean):TSpinHandle;
Description: Create and insert a new Spin entry


[Expand]
function SpinDestroy(Spin:TSpinHandle):LongWord;
Description: Destroy and remove an existing Spin entry


[Expand]
function SpinOwner(Spin:TSpinHandle):TThreadHandle;
Description: Get the current owner of an existing Spin entry


[Expand]
function SpinLock(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Lock an existing Spin entry


[Expand]
function SpinUnlock(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Unlock an existing Spin entry


[Expand]
function SpinLockIRQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Lock an existing Spin entry, disable IRQ and save the previous IRQ state


[Expand]
function SpinUnlockIRQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Unlock an existing Spin entry and restore the previous IRQ state


[Expand]
function SpinLockFIQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Lock an existing Spin entry, disable FIQ and save the previous FIQ state


[Expand]
function SpinUnlockFIQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Unlock an existing Spin entry and restore the previous FIQ state


[Expand]
function SpinLockIRQFIQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Lock an existing Spin entry, disable IRQ and FIQ and save the previous IRQ and FIQ state


[Expand]
function SpinUnlockIRQFIQ(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Unlock an existing Spin entry and restore the previous IRQ and FIQ state


[Expand]
function SpinLockPreempt(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Lock an existing Spin entry, disable IRQ or IRQ/FIQ and save the previous IRQ or IRQ/FIQ state


[Expand]
function SpinUnlockPreempt(Spin:TSpinHandle):LongWord; {$IFDEF SPIN_INLINE}inline; {$ENDIF}
Description: Unlock an existing Spin entry and restore the previous IRQ or IRQ/FIQ state


[Expand]
function SpinCheckIRQ(Spin:TSpinHandle):Boolean;
Description: Check the mask that stores the previous IRQ state to determine if IRQ is enabled


[Expand]
function SpinCheckFIQ(Spin:TSpinHandle):Boolean;
Description: Check the mask that stores the previous FIQ state to determine if FIQ is enabled


[Expand]
function SpinExchangeIRQ(Spin1,Spin2:TSpinHandle):LongWord;
Description: Exchange the previous IRQ state between two Spin entries


[Expand]
function SpinExchangeFIQ(Spin1,Spin2:TSpinHandle):LongWord;
Description: Exchange the previous FIQ state between two Spin entries


[Expand]
function SpinLockDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinLock function used if no handler is registered


[Expand]
function SpinUnlockDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinUnlock function used if no handler is registered


[Expand]
function SpinLockIRQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinLockIRQ function used if no handler is registered


[Expand]
function SpinUnlockIRQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinUnlockIRQ function used if no handler is registered


[Expand]
function SpinLockFIQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinLockFIQ function used if no handler is registered


[Expand]
function SpinUnlockFIQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinUnlockFIQ function used if no handler is registered


[Expand]
function SpinLockIRQFIQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinLockIRQFIQ function used if no handler is registered


[Expand]
function SpinUnlockIRQFIQDefault(SpinEntry:PSpinEntry):LongWord;
Description: Default version of SpinUnlockIRQFIQ function used if no handler is registered


Mutex functions

[Expand]
function MutexCreate:TMutexHandle; {$IFDEF MUTEX_INLINE}inline; {$ENDIF}
Description: Create and insert a new Mutex entry


[Expand]
function MutexCreateEx(InitialOwner:Boolean; SpinCount:LongWord; Flags:LongWord):TMutexHandle;
Description: Create and insert a new Mutex entry


[Expand]
function MutexDestroy(Mutex:TMutexHandle):LongWord;
Description: Destroy and remove an existing Mutex entry


[Expand]
function MutexFlags(Mutex:TMutexHandle):LongWord;
Description: Get the current flags of an existing Mutex entry


[Expand]
function MutexCount(Mutex:TMutexHandle):LongWord;
Description: Get the current lock count of an existing Mutex entry


[Expand]
function MutexOwner(Mutex:TMutexHandle):TThreadHandle;
Description: Get the current owner of an existing Mutex entry


[Expand]
function MutexLock(Mutex:TMutexHandle):LongWord; {$IFDEF MUTEX_INLINE}inline; {$ENDIF}
Description: Lock an existing Mutex entry


[Expand]
function MutexUnlock(Mutex:TMutexHandle):LongWord; {$IFDEF MUTEX_INLINE}inline; {$ENDIF}
Description: Unlock an existing Mutex entry


[Expand]
function MutexTryLock(Mutex:TMutexHandle):LongWord; {$IFDEF MUTEX_INLINE}inline; {$ENDIF}
Description: Try to lock an existing Mutex entry. If the Mutex is not locked then lock it and mark the owner as the current thread. If the Mutex is already locked then return immediately with an error and do not wait for it to be unlocked.


[Expand]
function MutexLockDefault(MutexEntry:PMutexEntry):LongWord;
Description: Default version of MutexLock function used if no handler is registered


[Expand]
function MutexUnlockDefault(MutexEntry:PMutexEntry):LongWord;
Description: Default version of MutexUnlock function used if no handler is registered


[Expand]
function MutexTryLockDefault(MutexEntry:PMutexEntry):LongWord;
Description: Default version of MutexTryLock function used if no handler is registered


Critical section functions

[Expand]
function CriticalSectionCreate:TCriticalSectionHandle;
Description: Create and insert a new CriticalSection entry


[Expand]
function CriticalSectionCreateEx(InitialOwner:Boolean; SpinCount:LongWord):TCriticalSectionHandle;
Description: Create and insert a new CriticalSection entry


[Expand]
function CriticalSectionDestroy(CriticalSection:TCriticalSectionHandle):LongWord;
Description: Destroy and remove an existing CriticalSection entry


[Expand]
function CriticalSectionCount(CriticalSection:TCriticalSectionHandle):LongWord;
Description: Get the current lock count of an existing CriticalSection entry


[Expand]
function CriticalSectionOwner(CriticalSection:TCriticalSectionHandle):TThreadHandle;
Description: Get the current owner of an existing CriticalSection entry


[Expand]
function CriticalSectionSetSpinCount(CriticalSection:TCriticalSectionHandle; SpinCount:LongWord):LongWord;
Description: Set the spin count of an existing CriticalSection entry


[Expand]
function CriticalSectionLock(CriticalSection:TCriticalSectionHandle):LongWord;
Description: Lock an existing CriticalSection entry


[Expand]
function CriticalSectionLockEx(CriticalSection:TCriticalSectionHandle; Timeout:LongWord):LongWord;
Description: Lock an existing CriticalSection entry


[Expand]
function CriticalSectionUnlock(CriticalSection:TCriticalSectionHandle):LongWord;
Description: Unlock an existing CriticalSection entry


[Expand]
function CriticalSectionTryLock(CriticalSection:TCriticalSectionHandle):LongWord;
Description: Try to lock an existing CriticalSection entry


Semaphore functions

[Expand]
function SemaphoreCreate(Count:LongWord):TSemaphoreHandle;
Description: Create and insert a new Semaphore entry


[Expand]
function SemaphoreCreateEx(Count,Maximum:LongWord; Flags:LongWord):TSemaphoreHandle;
Description: Create and insert a new Semaphore entry


[Expand]
function SemaphoreDestroy(Semaphore:TSemaphoreHandle):LongWord;
Description: Destroy and remove an existing Semaphore entry


[Expand]
function SemaphoreCount(Semaphore:TSemaphoreHandle):LongWord;
Description: Get the current count of an existing Semaphore entry


[Expand]
function SemaphoreWait(Semaphore:TSemaphoreHandle):LongWord;
Description: Wait on an existing Semaphore entry


[Expand]
function SemaphoreWaitEx(Semaphore:TSemaphoreHandle; Timeout:LongWord):LongWord;
Description: Wait on an existing Semaphore entry


[Expand]
function SemaphoreSignal(Semaphore:TSemaphoreHandle):LongWord;
Description: Signal an existing Semaphore entry


[Expand]
function SemaphoreSignalEx(Semaphore:TSemaphoreHandle; Count:LongWord; Previous:PLongWord):LongWord;
Description: Signal an existing Semaphore entry one or more times


Synchronizer functions

[Expand]
function SynchronizerCreate:TSynchronizerHandle;
Description: Create and insert a new Synchronizer entry


[Expand]
function SynchronizerCreateEx(InitialReader,InitialWriter:Boolean):TSynchronizerHandle;
Description: Create and insert a new Synchronizer entry


[Expand]
function SynchronizerDestroy(Synchronizer:TSynchronizerHandle):LongWord;
Description: Destroy and remove an existing Synchronizer entry


[Expand]
function SynchronizerReaderCount(Synchronizer:TSynchronizerHandle):LongWord;
Description: Get the current reader count of an existing Synchronizer entry


[Expand]
function SynchronizerReaderLast(Synchronizer:TSynchronizerHandle):TThreadHandle;
Description: Get the last reader thread of an existing Synchronizer entry


[Expand]
function SynchronizerReaderLock(Synchronizer:TSynchronizerHandle):LongWord;
Description: Lock an existing Synchronizer entry for reading


[Expand]
function SynchronizerReaderLockEx(Synchronizer:TSynchronizerHandle; Timeout:LongWord):LongWord;
Description: Lock an existing Synchronizer entry for reading


[Expand]
function SynchronizerReaderUnlock(Synchronizer:TSynchronizerHandle):LongWord;
Description: Unlock an existing Synchronizer entry


[Expand]
function SynchronizerReaderConvert(Synchronizer:TSynchronizerHandle):LongWord;
Description: Convert a reader lock on an existing Synchronizer entry to a writer lock


[Expand]
function SynchronizerReaderConvertEx(Synchronizer:TSynchronizerHandle; Timeout:LongWord):LongWord;
Description: Convert a reader lock on an existing Synchronizer entry to a writer lock


[Expand]
function SynchronizerWriterCount(Synchronizer:TSynchronizerHandle):LongWord;
Description: Get the current writer count of an existing Synchronizer entry


[Expand]
function SynchronizerWriterOwner(Synchronizer:TSynchronizerHandle):TThreadHandle;
Description: Get the current writer owner of an existing Synchronizer entry


[Expand]
function SynchronizerWriterLock(Synchronizer:TSynchronizerHandle):LongWord;
Description: Lock an existing Synchronizer entry for writing


[Expand]
function SynchronizerWriterLockEx(Synchronizer:TSynchronizerHandle; Timeout:LongWord):LongWord;
Description: Lock an existing Synchronizer entry for writing


[Expand]
function SynchronizerWriterUnlock(Synchronizer:TSynchronizerHandle):LongWord;
Description: Unlock an existing Synchronizer entry


[Expand]
function SynchronizerWriterConvert(Synchronizer:TSynchronizerHandle):LongWord;
Description: Convert a writer lock on an existing Synchronizer entry to a reader lock


Condition functions

[Expand]
function ConditionCreate:TConditionHandle;
Description: Create and insert a new Condition entry


[Expand]
function ConditionDestroy(Condition:TConditionHandle):LongWord;
Description: Destroy and remove an existing Condition entry


[Expand]
function ConditionWait(Condition:TConditionHandle; Timeout:LongWord = INFINITE):LongWord;
Description: Wait on an existing Condition


[Expand]
function ConditionWaitMutex(Condition:TConditionHandle; Mutex:TMutexHandle; Timeout:LongWord = INFINITE):LongWord;
Description: Release a Mutex and Wait on an existing Condition in an atomic operation


[Expand]
function ConditionWaitSynchronizer(Condition:TConditionHandle; Synchronizer:TSynchronizerHandle; Flags:LongWord; Timeout:LongWord = INFINITE):LongWord;
Description: Release a Synchronizer and Wait on an existing Condition in an atomic operation


[Expand]
function ConditionWaitCriticalSection(Condition:TConditionHandle; CriticalSection:TCriticalSectionHandle; Timeout:LongWord = INFINITE):LongWord;
Description: Release a Critical Section and Wait on an existing Condition in an atomic operation


[Expand]
function ConditionWake(Condition:TConditionHandle):LongWord;
Description: Wake one thread waiting on an existing Condition


[Expand]
function ConditionWakeAll(Condition:TConditionHandle):LongWord;
Description: Wake all threads waiting on an existing Condition


Completion functions

[Expand]
function CompletionLock(Completion:PCompletionEntry):LongWord; {$IFDEF COMPLETION_INLINE}inline; {$ENDIF}
Description: Internal function to lock an existing Completion entry based on the entry flags


[Expand]
function CompletionUnlock(Completion:PCompletionEntry):LongWord; {$IFDEF COMPLETION_INLINE}inline; {$ENDIF}
Description: Internal function to unlock an existing Completion entry based on the entry flags


[Expand]
function CompletionCreate(Flags:LongWord = COMPLETION_FLAG_NONE):TCompletionHandle;
Description: Create and insert a new Completion entry


[Expand]
function CompletionDestroy(Completion:TCompletionHandle):LongWord;
Description: Destroy and remove an existing Completion entry


[Expand]
function CompletionState(Completion:TCompletionHandle):LongWord;
Description: Get the current state of an existing Completion entry


[Expand]
function CompletionWait(Completion:TCompletionHandle; Timeout:LongWord = INFINITE):LongWord;
Description: Wait on an existing Completion


[Expand]
function CompletionTryWait(Completion:TCompletionHandle):LongWord;
Description: Try an existing Completion to see if it is completed


[Expand]
function CompletionReset(Completion:TCompletionHandle):LongWord;
Description: Reset (uncomplete) the state of an existing Completion entry


[Expand]
function CompletionComplete(Completion:TCompletionHandle):LongWord;
Description: Set (complete) the state of an existing Completion entry


[Expand]
function CompletionCompleteAll(Completion:TCompletionHandle):LongWord;
Description: Set (complete) the state of an existing Completion entry


List functions

[Expand]
function ListCreate:TListHandle; {$IFDEF LIST_INLINE}inline; {$ENDIF}
Description: Create and insert a new List entry


[Expand]
function ListCreateEx(ListType:LongWord; Flags:LongWord):TListHandle;
Description: Create and insert a new List entry


[Expand]
function ListDestroy(List:TListHandle):LongWord;
Description: Destroy and remove an existing List entry


[Expand]
function ListCount(List:TListHandle):LongWord;
Description: Get the current count from the supplied list


[Expand]
function ListAddFirst(List:TListHandle; Element:PListElement):LongWord;
Description: Add the supplied element as the first item in the List


[Expand]
function ListAddLast(List:TListHandle; Element:PListElement):LongWord;
Description: Add the supplied element as the last item in the List


[Expand]
function ListGetThread(List:TListHandle; Thread:TThreadHandle):PListElement;
Description: Find the supplied thread in the List and return its element


[Expand]
function ListGetFirst(List:TListHandle):PListElement;
Description: Get the first element from the List


[Expand]
function ListGetFirstEx(List:TListHandle; Remove:Boolean):PListElement;
Description: Get the first element from the List


[Expand]
function ListGetLast(List:TListHandle):PListElement;
Description: Get the last element from the List


[Expand]
function ListGetLastEx(List:TListHandle; Remove:Boolean):PListElement;
Description: Get the last element from the List


[Expand]
function ListInsert(List:TListHandle; Previous,Element:PListElement):LongWord;
Description: Insert a new element in the List


[Expand]
function ListRemove(List:TListHandle; Element:PListElement):LongWord;
Description: Remove an element from the List


[Expand]
function ListIsEmpty(List:TListHandle):Boolean;
Description: Check if the supplied List is empty


[Expand]
function ListNotEmpty(List:TListHandle):Boolean;
Description: Check if the supplied List is empty


[Expand]
function ListLock(List:TListHandle):LongWord;
Description: Lock the supplied List


[Expand]
function ListUnlock(List:TListHandle):LongWord;
Description: Unlock the supplied List


[Expand]
function ListLock(List:TListHandle):LongWord; {$IFDEF LIST_INLINE}inline; {$ENDIF}
Description: Lock the supplied List


[Expand]
function ListUnlock(List:TListHandle):LongWord; {$IFDEF LIST_INLINE}inline; {$ENDIF}
Description: Unlock the supplied List


Queue functions

[Expand]
function QueueCreate:TQueueHandle; {$IFDEF QUEUE_INLINE}inline; {$ENDIF}
Description: Create and insert a new Queue entry


[Expand]
function QueueCreateEx(QueueType:LongWord; Flags:LongWord):TQueueHandle;
Description: Create and insert a new Queue entry}


[Expand]
function QueueDestroy(Queue:TQueueHandle):LongWord;
Description: Destroy and remove an existing Queue entry


[Expand]
function QueueCount(Queue:TQueueHandle):LongWord;
Description: Get the current count from the supplied queue


[Expand]
function QueueEnqueue(Queue:TQueueHandle; Thread:TThreadHandle):LongWord;
Description: Add the supplied thread as the last item in the Queue


[Expand]
function QueueDequeue(Queue:TQueueHandle):TThreadHandle;
Description: Get and remove the first thread from the Queue


[Expand]
function QueueFirstKey(Queue:TQueueHandle):Integer;
Description: Get the first Key value from the Queue


[Expand]
function QueueLastKey(Queue:TQueueHandle):Integer;
Description: Get the last Key value from the Queue


[Expand]
function QueueInsertKey(Queue:TQueueHandle; Thread:TThreadHandle; Key:Integer):LongWord;
Description: Insert the supplied thread in the Queue ordered based on Key and the flags of the Queue


[Expand]
function QueueDeleteKey(Queue:TQueueHandle; Thread:TThreadHandle):LongWord;
Description: Delete the supplied thread from the Queue based on the flags of the Queue


[Expand]
function QueueIncrementKey(Queue:TQueueHandle):Integer;
Description: Increment the first Key value in the Queue


[Expand]
function QueueDecrementKey(Queue:TQueueHandle):Integer;
Description: Decrement the first Key value in the Queue


[Expand]
function QueueIsEmpty(Queue:TQueueHandle):Boolean;
Description: Check if the supplied Queue is empty


[Expand]
function QueueNotEmpty(Queue:TQueueHandle):Boolean;
Description: Check if the supplied Queue is not empty


[Expand]
function QueueLock(Queue:TQueueHandle):LongWord; {$IFDEF QUEUE_INLINE}inline; {$ENDIF}
Description: Lock the supplied Queue


[Expand]
function QueueUnlock(Queue:TQueueHandle):LongWord; {$IFDEF QUEUE_INLINE}inline; {$ENDIF}
Description: Unlock the supplied Queue


Thread functions

[Expand]
function ThreadCreate(StartProc:TThreadStart; StackSize,Priority:LongWord; Name:PChar; Parameter:Pointer):TThreadHandle;
Description: Create and insert a new Thread entry


[Expand]
function ThreadCreateEx(StartProc:TThreadStart; StackSize,Priority,Affinity,CPU:LongWord; Name:PChar; Parameter:Pointer):TThreadHandle;
Description: Create and insert a new Thread entry


[Expand]
function ThreadDestroy(Thread:TThreadHandle):LongWord;
Description: Destroy and remove an existing Thread entry


[Expand]
function ThreadGetCurrent:TThreadHandle; inline;
Description: Get the Handle of currently executing thread


[Expand]
function ThreadSetCurrent(Thread:TThreadHandle):LongWord; inline;
Description: Set the Handle of currently executing thread


[Expand]
function ThreadGetName(Thread:TThreadHandle):String;
Description: Get the name of a Thread}


[Expand]
function ThreadSetName(Thread:TThreadHandle; const Name:String):LongWord;
Description: Set the name of a Thread


[Expand]
function ThreadGetCPU(Thread:TThreadHandle):LongWord;
Description: Get the current CPU of a thread (eg CPU_ID_0)


[Expand]
function ThreadSetCPU(Thread:TThreadHandle; CPU:LongWord):LongWord;
Description: Set the current CPU of a thread (eg CPU_ID_0)


[Expand]
function ThreadGetState(Thread:TThreadHandle):LongWord;
Description: Get the current state of a thread (eg THREAD_STATE_SUSPENDED)


[Expand]
function ThreadGetFlags(Thread:TThreadHandle):LongWord;
Description: Get the current flags of a thread


[Expand]
function ThreadSetFlags(Thread:TThreadHandle; Flags:LongWord):LongWord;
Description: Set the current flags of a thread


[Expand]
function ThreadAddFlags(Thread:TThreadHandle; Flags:LongWord):LongWord;
Description: Add flags to the current flags of a thread


[Expand]
function ThreadRemoveFlags(Thread:TThreadHandle; Flags:LongWord):LongWord;
Description: Remove flags from the current flags of a thread


[Expand]
function ThreadGetLocale(Thread:TThreadHandle):LCID;
Description: Get the current locale of a thread


[Expand]
function ThreadSetLocale(Thread:TThreadHandle; Locale:LCID):LongWord;
Description: Set the locale of a thread


[Expand]
function ThreadGetTimes(Thread:TThreadHandle; var CreateTime,ExitTime,KernelTime:Int64):LongWord;
Description: Get the current times of a thread


[Expand]
function ThreadGetSwitchCount(Thread:TThreadHandle; var SwitchCount:Int64):LongWord;
Description: Get the current context switch count of a thread (How many times the thread has been scheduled)


[Expand]
function ThreadGetStackFree:LongWord;
Description: Get the free stack size of the current thread


[Expand]
function ThreadGetStackSize(Thread:TThreadHandle):LongWord;
Description: Get the current stack size of a thread


[Expand]
function ThreadGetStackBase(Thread:TThreadHandle):PtrUInt;
Description: Get the current stack base of a thread


[Expand]
function ThreadSetStackBase(Thread:TThreadHandle; StackBase:PtrUInt):LongWord;
Description: Set the current stack base of a thread


[Expand]
function ThreadGetStackPointer(Thread:TThreadHandle):PtrUInt;
Description: Get the current stack pointer of a thread


[Expand]
function ThreadGetExitCode(Thread:TThreadHandle):LongWord;
Description: Get the exit code of a Thread


[Expand]
function ThreadGetAffinity(Thread:TThreadHandle):LongWord;
Description: Get the scheduling affinity of a Thread


[Expand]
function ThreadSetAffinity(Thread:TThreadHandle; Affinity:LongWord):LongWord;
Description: Set the scheduling affinity of a Thread


[Expand]
function ThreadGetPriority(Thread:TThreadHandle):LongWord;
Description: Get the scheduling priority of a Thread


[Expand]
function ThreadSetPriority(Thread:TThreadHandle; Priority:LongWord):LongWord;
Description: Set the scheduling priority of a Thread


[Expand]
function ThreadGetLastError:LongWord;
Description: Get the last error value for the current Thread


[Expand]
procedure ThreadSetLastError(LastError:LongWord);
Description: Set the last error value for the current Thread


[Expand]
function ThreadSetLastErrorEx(LastError:LongWord):LongWord;
Description: Set the last error value for the current Thread


[Expand]
function ThreadGetWaitResult:LongWord;
Description: Get the result of the last wait timeout for the current Thread


[Expand]
function ThreadGetReceiveResult:LongWord;
Description: Get the result of the last receive timeout for the current Thread


[Expand]
function ThreadGetTlsIndex(TlsIndex:LongWord):LongWord;
Description: Get the current status of a TLS index in the TLS index table


[Expand]
function ThreadAllocTlsIndex:LongWord; inline;
Description: Allocate a TLS index in the TLS index table


[Expand]
function ThreadAllocTlsIndexEx(Flags:LongWord):LongWord;
Description: Allocate a TLS index in the TLS index table


[Expand]
function ThreadReleaseTlsIndex(TlsIndex:LongWord):LongWord;
Description: Deallocate a TLS index from the TLS index table


[Expand]
function ThreadGetTlsValue(TlsIndex:LongWord):Pointer;
Description: Get the pointer associated with the TLS index for the current thread


[Expand]
function ThreadSetTlsValue(TlsIndex:LongWord; TlsValue:Pointer):LongWord;
Description: Set the pointer associated with the TLS index for the current thread


[Expand]
function ThreadGetTlsPointer(Thread:TThreadHandle):Pointer;
Description: Get the RTL TLS (Thread Local Storage) pointer of a Thread


[Expand]
function ThreadSetTlsPointer(Thread:TThreadHandle; TlsPointer:Pointer):LongWord;
Description: Set the RTL TLS (Thread Local Storage) pointer of a Thread


[Expand]
function ThreadReady(Thread:TThreadHandle; Reschedule:Boolean):LongWord;
Description: Place the supplied Thread on the ready queue


[Expand]
function ThreadTimeout(Thread:TThreadHandle):LongWord;
Description: Place the supplied Thread on the ready queue after a timeout waiting on a resource


[Expand]
function ThreadWake(Thread:TThreadHandle):LongWord;
Description: Remove a thread prematurely from the sleep or timeout queues


[Expand]
function ThreadMigrate(Thread:TThreadHandle; CPU:LongWord):LongWord;
Description: Migrate a thread to a new CPU


[Expand]
procedure ThreadEnd(ExitCode:LongWord);
Description: Terminate the current Thread


[Expand]
function ThreadHalt(ExitCode:LongWord):LongWord;
Description: Halt the current thread so it will never be rescheduled


[Expand]
function ThreadTerminate(Thread:TThreadHandle; ExitCode:LongWord):LongWord;
Description: Terminate but do not destroy the supplied Thread


[Expand]
function ThreadYield:LongWord;
Description: Make the current thread yield the processor (Same as ThreadSleep(0))


[Expand]
function ThreadSleep(Milliseconds:LongWord):LongWord;
Description: Place the current thread on the sleep queue for a specified number of milliseconds


[Expand]
function ThreadWait(List:TListHandle; Lock:TSpinHandle; Flags:LongWord):LongWord;
Description: Put the current thread into a wait state on the supplied list


[Expand]
function ThreadWaitEx(List:TListHandle; Lock:TSpinHandle; Flags,Timeout:LongWord):LongWord;
Description: Put the current thread into a wait state with timeout on the supplied list


[Expand]
function ThreadRelease(List:TListHandle):LongWord;
Description: Release the first thread waiting on the supplied list


[Expand]
function ThreadAbandon(List:TListHandle):LongWord;
Description: Release the first thread waiting on the supplied list and return with WAIT_ABANDONED


[Expand]
function ThreadWaitTerminate(Thread:TThreadHandle; Timeout:LongWord):LongWord;
Description: Make the current thread wait until the specified thread has terminated


[Expand]
function ThreadSuspend(Thread:TThreadHandle):LongWord;
Description: Suspend a thread, placing it in hibernation


[Expand]
function ThreadResume(Thread:TThreadHandle):LongWord;
Description: Resume a suspended thread, making it ready


[Expand]
function ThreadWaitMessage:LongWord;
Description: Make the current thread wait until a message is received (indefinitely)


[Expand]
function ThreadSendMessage(Thread:TThreadHandle; const Message:TMessage):LongWord;
Description: Send a message to another thread


[Expand]
function ThreadReceiveMessage(var Message:TMessage):LongWord;
Description: Make the current thread wait to receive a message (indefinitely)


[Expand]
function ThreadReceiveMessageEx(var Message:TMessage; Timeout:LongWord; Remove:Boolean):LongWord;
Description: Make the current thread wait to receive a message


[Expand]
function ThreadAbandonMessage(Thread:TThreadHandle):LongWord;
Description: Tell another thread to abandon waiting for a message


[Expand]
function ThreadLock(Thread:TThreadHandle):LongWord;
Description: Lock a thread allowing access to internal structures such as the thread stack


[Expand]
function ThreadUnlock(Thread:TThreadHandle):LongWord;
Description: Unlock a thread that was locked by ThreadLock


[Expand]
procedure ThreadTimer(Data:Pointer);
Description: Procedure called internally to process terminated threads


Scheduler functions

[Expand]
function SchedulerCheck(CPUID:LongWord):LongWord;
Description: Check if the sleep queue is empty, if not then decrement the first key. Note: Then check if the timeout queue is empty, if not then decrement the first key. If either key reaches zero, return success to indicate there are threads to be woken or threads whose timeout has expired. Finally check if the termination queue is empty, if not then decrement the first key. Items will be removed from the termination queue by SchedulerReschedule.


[Expand]
function SchedulerWakeup(CPUID:LongWord):LongWord;
Description: Remove all threads from the sleep queue that have no more time to sleep. Note: Threads will be placed back on the ready queue for rescheduling.


[Expand]
function SchedulerExpire(CPUID:LongWord):LongWord;
Description: Remove all threads from the timeout queue that have no more time to wait. Note: Threads will be placed back on the ready queue for rescheduling but will return with an error indicating the timeout expired.


[Expand]
function SchedulerSwitch(CPUID:LongWord; Thread:TThreadHandle):TThreadHandle;
Description: Perform a preemptive thread switch operation under an interrupt handler. Note: The next thread to run will be selected based on remaining quantum of the current thread, ready threads at higher priority levels and scheduler priority quantum for fair scheduling of lower priority threads.


[Expand]
function SchedulerSelect(CPUID:LongWord; Thread:TThreadHandle; Yield:Boolean):TThreadHandle;
Description: Select the next thread to be run based on state, yield, quantum and priority


[Expand]
function SchedulerReschedule(Yield:Boolean):LongWord;
Description: Perform a thread switch operation when a thread yields, sleeps or waits. Note: The next thread to run will be selected based on whether the current thread is yielding or no longer ready, remaining quantum of the current thread, ready threads at higher priority levels and scheduler priority quantum for fair scheduling of lower priority threads.


[Expand]
function SchedulerMigrationEnable:LongWord;
Description: Enable scheduler thread migration


[Expand]
function SchedulerMigrationDisable:LongWord;
Description: Disable scheduler thread migration


[Expand]
function SchedulerPreemptEnable(CPUID:LongWord):LongWord;
Description: Enable thread preemption for the specified CPU


[Expand]
function SchedulerPreemptDisable(CPUID:LongWord):LongWord;
Description: Disable thread preemption for the specified CPU


[Expand]
function SchedulerAllocationEnable(CPUID:LongWord):LongWord;
Description: Enable thread allocation for the specified CPU


[Expand]
function SchedulerAllocationDisable(CPUID:LongWord):LongWord;
Description: Disable thread allocation for the specified CPU


Messageslot functions

[Expand]
function MessageslotCreate:TMessageslotHandle;
Description: Create and insert a new Messageslot entry


[Expand]
function MessageslotCreateEx(Maximum:LongWord; Flags:LongWord):TMessageslotHandle;
Description: Create and insert a new Messageslot entry


[Expand]
function MessageslotDestroy(Messageslot:TMessageslotHandle):LongWord;
Description: Destroy and remove an existing Messageslot entry


[Expand]
function MessageslotCount(Messageslot:TMessageslotHandle):LongWord;
Description: Get the number of available messages in a Messageslot entry


[Expand]
function MessageslotSend(Messageslot:TMessageslotHandle; const Message:TMessage):LongWord;
Description: Send a message to a Messageslot


[Expand]
function MessageslotReceive(Messageslot:TMessageslotHandle; var Message:TMessage):LongWord;
Description: Receive a message from a Messageslot


[Expand]
function MessageslotReceiveEx(Messageslot:TMessageslotHandle; var Message:TMessage; Timeout:LongWord):LongWord;
Description: Receive a message from a Messageslot


Mailslot functions

[Expand]
function MailslotCreate(Maximum:LongWord):TMailslotHandle;
Description: Create and insert a new Mailslot entry


[Expand]
function MailslotDestroy(Mailslot:TMailslotHandle):LongWord;
Description: Destroy and remove an existing Mailslot entry


[Expand]
function MailslotCount(Mailslot:TMailslotHandle):LongWord;
Description: Get the number of available messages in a Mailslot entry


[Expand]
function MailslotSend(Mailslot:TMailslotHandle; Data:PtrInt):LongWord;
Description: Send a message to a Mailslot


[Expand]
function MailslotSendEx(Mailslot:TMailslotHandle; Data:PtrInt; Timeout:LongWord):LongWord;
Description: Send a message to a Mailslot


[Expand]
function MailslotReceive(Mailslot:TMailslotHandle):PtrInt;
Description: Receive a message from a Mailslot


[Expand]
function MailslotReceiveEx(Mailslot:TMailslotHandle; Timeout:LongWord):PtrInt;
Description: Receive a message from a Mailslot


Buffer functions

[Expand]
function BufferCreate(Size,Count:LongWord):TBufferHandle;
Description: To be documented


[Expand]
function BufferCreateEx(Size,Count,Flags:LongWord):TBufferHandle;
Description: To be documented


[Expand]
function BufferDestroy(Buffer:TBufferHandle):LongWord;
Description: To be documented


[Expand]
function BufferCount(Buffer:TBufferHandle):LongWord;
Description: To be documented


[Expand]
function BufferAvailable(Buffer:TBufferHandle):LongWord;
Description: To be documented


[Expand]
function BufferGet(Buffer:TBufferHandle):Pointer;
Description: To be documented


[Expand]
function BufferGetEx(Buffer:TBufferHandle; Timeout:LongWord):Pointer;
Description: To be documented


[Expand]
function BufferFree(Buffer:Pointer):LongWord;
Description: To be documented


[Expand]
function BufferIterate(Buffer:TBufferHandle; Previous:Pointer):Pointer;
Description: To be documented


Event functions

[Expand]
function EventCreate(ManualReset,InitialState:Boolean):TEventHandle;
Description: To be documented


[Expand]
function EventCreateEx(Flags:LongWord):TEventHandle;
Description: To be documented


[Expand]
function EventDestroy(Event:TEventHandle):LongWord;
Description: To be documented


[Expand]
function EventState(Event:TEventHandle):LongWord;
Description: To be documented


[Expand]
function EventWait(Event:TEventHandle):LongWord;
Description: To be documented


[Expand]
function EventWaitEx(Event:TEventHandle; Timeout:LongWord):LongWord;
Description: To be documented


[Expand]
function EventSet(Event:TEventHandle):LongWord;
Description: To be documented


[Expand]
function EventReset(Event:TEventHandle):LongWord;
Description: To be documented


[Expand]
function EventPulse(Event:TEventHandle):LongWord;
Description: To be documented


Timer functions

[Expand]
function TimerCreate(Interval:LongWord; Enabled,Reschedule:Boolean; Event:TTimerEvent; Data:Pointer):TTimerHandle;
Description: To be documented


[Expand]
function TimerCreateEx(Interval,State,Flags:LongWord; Event:TTimerEvent; Data:Pointer):TTimerHandle;
Description: To be documented


[Expand]
function TimerDestroy(Timer:TTimerHandle):LongWord;
Description: To be documented


[Expand]
function TimerEnable(Timer:TTimerHandle):LongWord;
Description: To be documented


[Expand]
function TimerEnableEx(Timer:TTimerHandle; Interval:LongWord; Event:TTimerEvent; Data:Pointer):LongWord;
Description: To be documented


[Expand]
function TimerDisable(Timer:TTimerHandle):LongWord;
Description: To be documented


[Expand]
function TimerDequeue:TTimerHandle;
Description: To be documented


[Expand]
function TimerFirstKey:Integer;
Description: To be documented


[Expand]
function TimerInsertKey(Timer:TTimerHandle; Key:Integer):LongWord;
Description: To be documented


[Expand]
function TimerDeleteKey(Timer:TTimerHandle):LongWord;
Description: To be documented


[Expand]
function TimerDecrementKey:Integer;
Description: To be documented


[Expand]
function TimerIsEmpty:Boolean;
Description: To be documented


[Expand]
function TimerNotEmpty:Boolean;
Description: To be documented


[Expand]
function TimerCheck:LongWord;
Description: To be documented


[Expand]
function TimerTrigger:LongWord;
Description: To be documented


Worker functions

[Expand]
function WorkerSchedule(Interval:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):LongWord;
Description: To be documented


[Expand]
function WorkerScheduleEx(Interval,Flags:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):TWorkerHandle;
Description: To be documented


[Expand]
function WorkerCancel(Worker:TWorkerHandle):LongWord;
Description: To be documented


[Expand]
function WorkerScheduleIRQ(Affinity:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):LongWord;
Description: To be documented


[Expand]
function WorkerScheduleIRQEx(Affinity,Flags:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):LongWord;
Description: To be documented


[Expand]
function WorkerScheduleFIQ(Affinity:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):LongWord;
Description: To be documented


[Expand]
function WorkerScheduleFIQEx(Affinity,Flags:LongWord; Task:TWorkerTask; Data:Pointer; Callback:TWorkerCallback):LongWord;
Description: To be documented


[Expand]
function WorkerIncrease(Count:LongWord):LongWord; inline;
Description: To be documented


[Expand]
function WorkerIncreaseEx(Count:LongWord; Priority:Boolean):LongWord;
Description: To be documented


[Expand]
function WorkerDecrease(Count:LongWord):LongWord; inline;
Description: To be documented


[Expand]
function WorkerDecreaseEx(Count:LongWord; Priority:Boolean):LongWord;
Description: To be documented


[Expand]
procedure WorkerTimer(WorkerRequest:PWorkerRequest);
Description: Procedure called internally to schedule worker threads


Tasker functions

[Expand]
function TaskerThreadSendMessage(Thread:TThreadHandle; const Message:TMessage):LongWord;
Description: Perform a ThreadSendMessage() function call using the tasker list


[Expand]
function TaskerMessageslotSend(Messageslot:TMessageslotHandle; const Message:TMessage):LongWord;
Description: Perform a MessageslotSend() function call using the tasker list


[Expand]
function TaskerSemaphoreSignal(Semaphore:TSemaphoreHandle; Count:LongWord):LongWord;
Description: Perform a SemaphoreSignal() function call using the tasker list


[Expand]
function TaskerEnqueue(Task:PTaskerTask):LongWord;
Description: Add the supplied task to the end of the Tasker list


[Expand]
function TaskerDequeue:PTaskerTask;
Description: Get and remove the first task from the Tasker list


[Expand]
function TaskerCheck:LongWord;
Description: Check if the tasker list is empty or contains tasks


[Expand]
function TaskerTrigger:LongWord;
Description: Dequeue all tasks in the tasker list and perform the requested task for each


[Expand]
function TaskerGetCount:LongWord; inline;
Description: Get the current tasker count


RTL initialize and exit functions

[Expand]
procedure SysInitProc;
Description: To be documented


[Expand]
procedure SysExitProc;
Description: To be documented


[Expand]
function SysInitCompleted:Boolean;
Description: To be documented


RTL process functions

[Expand]
function SysGetProcessID:SizeUInt;
Description: To be documented


RTL thread manager functions

[Expand]
function ThreadMain(Parameter:Pointer):PtrInt;
Description: To be documented


[Expand]
function SysBeginThread(SignalAction:Pointer; StackSize:PtrUInt; ThreadFunction:TThreadFunc; ThreadParameter:Pointer; CreationFlags:DWORD; var ThreadId:TThreadID):TThreadID;
Description: To be documented


[Expand]
function SysBeginThreadEx(SignalAction:Pointer; StackSize:PtrUInt; ThreadFunction:TThreadFunc; ThreadParameter:Pointer; CreationFlags:DWORD; Priority,Affinity,CPU:LongWord; Name:PChar; var ThreadId:TThreadID):TThreadID;
Description: To be documented


[Expand]
procedure SysEndThread(ExitCode:DWORD);
Description: To be documented


[Expand]
function SysSuspendThread(ThreadHandle:TThreadID):DWORD;
Description: To be documented


[Expand]
function SysResumeThread(ThreadHandle:TThreadID):DWORD;
Description: To be documented


[Expand]
function SysKillThread(ThreadHandle:TThreadID):DWORD;
Description: To be documented


[Expand]
function SysCloseThread(ThreadHandle:TThreadID):DWORD;
Description: To be documented


[Expand]
procedure SysThreadSwitch;
Description: To be documented


[Expand]
function SysWaitForThreadTerminate(ThreadHandle:TThreadID; TimeoutMs:LongInt):DWORD;
Description: To be documented


[Expand]
function SysThreadSetPriority(ThreadHandle:TThreadID; Priority:LongInt):Boolean; 
Description: To be documented


[Expand]
function SysThreadGetPriority(ThreadHandle:TThreadID):LongInt;
Description: To be documented


[Expand]
function SysGetCurrentThreadId:TThreadID;
Description: To be documented


[Expand]
procedure SysSetThreadDebugNameA(ThreadHandle:TThreadID; const ThreadName:AnsiString);
Description: To be documented


[Expand]
procedure SysSetThreadDebugNameU(ThreadHandle:TThreadID; const ThreadName:UnicodeString);
Description: To be documented


[Expand]
procedure SysInitCriticalSection(var CriticalSection);
Description: To be documented


[Expand]
procedure SysDoneCriticalSection(var CriticalSection);
Description: To be documented


[Expand]
procedure SysEnterCriticalSection(var CriticalSection);
Description: To be documented


[Expand]
function SysTryEnterCriticalSection(var CriticalSection):LongInt;
Description: To be documented


[Expand]
procedure SysLeaveCriticalSection(var CriticalSection);
Description: To be documented


[Expand]
procedure SysInitThreadVar(var Offset:DWORD; Size:DWORD);
Description: To be documented


[Expand]
function SysRelocateThreadVar(Offset:DWORD):Pointer;
Description: To be documented


[Expand]
procedure SysAllocateThreadVars;
Description: To be documented


[Expand]
procedure SysReleaseThreadVars;
Description: To be documented


[Expand]
function SysBasicEventCreate(EventAttributes:Pointer; AManualReset,InitialState:Boolean; const Name:AnsiString):PEventState;
Description: To be documented


[Expand]
procedure SysBasicEventDestroy(State:PEventState);
Description: To be documented


[Expand]
procedure SysBasicEventResetEvent(State:PEventState);
Description: To be documented


[Expand]
procedure SysBasicEventSetEvent(State:PEventState);
Description: To be documented


[Expand]
function SysBasicEventWaitFor(Timeout:Cardinal; State:PEventState):LongInt; 
Description: To be documented


[Expand]
function SysRTLEventCreate:PRTLEvent;
Description: To be documented


[Expand]
procedure SysRTLEventDestroy(AEvent:PRTLEvent);
Description: To be documented


[Expand]
procedure SysRTLEventSetEvent(AEvent:PRTLEvent);
Description: To be documented


[Expand]
procedure SysRTLEventResetEvent(AEvent:PRTLEvent);
Description: To be documented


[Expand]
procedure SysRTLEventWaitFor(AEvent:PRTLEvent);
Description: To be documented


[Expand]
procedure SysRTLEventWaitForTimeout(AEvent:PRTLEvent; Timeout:LongInt);
Description: To be documented


[Expand]
function SysSemaphoreInit:Pointer;
Description: To be documented


[Expand]
procedure SysSemaphoreDestroy(const Semaphore:Pointer);
Description: To be documented


[Expand]
procedure SysSemaphorePost(const Semaphore:Pointer);
Description: To be documented


[Expand]
procedure SysSemaphoreWait(const Semaphore:Pointer);
Description: To be documented


Thread helper functions

[Expand]
function SpinGetCount:LongWord; inline;
Description: To be documented


[Expand]
function MutexGetCount:LongWord; inline;
Description: To be documented


[Expand]
function CriticalSectionGetCount:LongWord; inline;
Description: To be documented


[Expand]
function SemaphoreGetCount:LongWord; inline;
Description: To be documented


[Expand]
function SynchronizerGetCount:LongWord; inline;
Description: To be documented


[Expand]
function ConditionGetCount:LongWord; inline;
Description: Get the current condition count


[Expand]
function CompletionGetCount:LongWord; inline;
Description: Get the current completion count


[Expand]
function ListGetCount:LongWord; inline;
Description: Get the current list count


[Expand]
function QueueGetCount:LongWord; inline;
Description: To be documented


[Expand]
function ThreadGetCount:LongWord; inline;
Description: To be documented


[Expand]
function ThreadTlsGetCount:LongWord; inline;
Description: To be documented


[Expand]
function ThreadAllocateStack(StackSize:LongWord):Pointer;
Description: To be documented


[Expand]
procedure ThreadReleaseStack(StackBase:Pointer; StackSize:LongWord);
Description: To be documented


[Expand]
function ThreadSetupStack(StackBase:Pointer; StartProc:TThreadStart; ReturnProc:TThreadEnd; Parameter:Pointer):Pointer;
Description: To be documented


[Expand]
function ThreadSnapshotCreate:PThreadSnapshot;
Description: To be documented


[Expand]
function ThreadSnapshotDestroy(ASnapshot:PThreadSnapshot):LongWord;
Description: To be documented


[Expand]
function MessageslotGetCount:LongWord; inline;
Description: To be documented


[Expand]
function MailslotGetCount:LongWord; inline;
Description: To be documented


[Expand]
function BufferGetCount:LongWord; inline;
Description: To be documented


[Expand]
function EventGetCount:LongWord; inline;
Description: To be documented


[Expand]
function TimerGetCount:LongWord; inline;
Description: To be documented


[Expand]
function WorkerGetCount:LongWord; inline;
Description: To be documented


[Expand]
function WorkerGetPriorityCount:LongWord; inline;
Description: To be documented


[Expand]
function TaskerGetCount:LongWord; inline;
Description: To be documented


[Expand]
function ListTypeToString(ListType:LongWord):String;
Description: To be documented


[Expand]
function QueueTypeToString(QueueType:LongWord):String;
Description: To be documented


[Expand]
function ThreadTypeToString(ThreadType:LongWord):String;
Description: To be documented


[Expand]
function ThreadStateToString(ThreadState:LongWord):String;
Description: To be documented


[Expand]
function ThreadPriorityToString(ThreadPriority:LongWord):String;
Description: To be documented


[Expand]
procedure ThreadLog(Level:LongWord; const AText:String);
Description: To be documented


[Expand]
procedure ThreadLogInfo(const AText:String); inline;
Description: To be documented


[Expand]
procedure ThreadLogWarn(const AText:String); inline;
Description: To be documented


[Expand]
procedure ThreadLogError(const AText:String); inline;
Description: To be documented


[Expand]
procedure ThreadLogDebug(const AText:String); inline;
Description: To be documented


Scheduler helper functions

[Expand]
function SchedulerGetListFlags(ListType:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetQueueFlags(QueueType:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetQueueHandle(CPUID:LongWord; QueueType:LongWord):TQueueHandle;
Description: To be documented


[Expand]
function SchedulerGetQueueHandleEx(CPUID:LongWord; Priority:LongWord):TQueueHandle;
Description: To be documented


[Expand]
function SchedulerGetThreadCount(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadQuantum(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadHandle(CPUID:LongWord; ThreadType:LongWord):TThreadHandle;
Description: To be documented


[Expand]
function SchedulerGetPriorityMask(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetPriorityQuantum(Priority:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerSetPriorityQuantum(Priority,Quantum:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetMigrationQuantum:LongWord;
Description: To be documented


[Expand]
function SchedulerGetStarvationQuantum(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadNext:LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadMigration:LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadPreempt(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerGetThreadAllocation(CPUID:LongWord):LongWord;
Description: To be documented


[Expand]
function SchedulerMigrationToString(Migration:LongWord):String;
Description: To be documented


[Expand]
function SchedulerPreemptToString(Preempt:LongWord):String;
Description: To be documented


[Expand]
function SchedulerAllocationToString(Allocation:LongWord):String;
Description: To be documented


Timer helper functions

[Expand]
function TimerGetListFlags:LongWord;
Description: To be documented


[Expand]
function TimerGetMessageslotFlags:LongWord;
Description: To be documented


Worker helper functions

[Expand]
function WorkerGetMessageslotFlags:LongWord;
Description: To be documented


Return to Unit Reference