Unit Threads

From Ultibo.org
Revision as of 02:04, 9 September 2016 by Ultibo (Talk | contribs)

Jump to: navigation, search

Return to Unit Reference


Description


To be documented

Constants


To be documented

Type definitions


To be documented

Public variables


To be documented

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: To be documented


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


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


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


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


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


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


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


Spin functions

[Expand]
function SpinCreate:TSpinHandle;
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;
Description: Lock an existing Spin entry


[Expand]
function SpinUnlock(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry


[Expand]
function SpinLockIRQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable IRQ and save the previous IRQ state


[Expand]
function SpinUnlockIRQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous IRQ state


[Expand]
function SpinLockFIQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable FIQ and save the previous FIQ state


[Expand]
function SpinUnlockFIQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous FIQ state


[Expand]
function SpinLockIRQFIQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable IRQ and FIQ and save the previous IRQ and FIQ state


[Expand]
function SpinUnlockIRQFIQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous IRQ and 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


Mutex functions

[Expand]
function MutexCreate:TMutexHandle;
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;
Description: Lock an existing Mutex entry


[Expand]
function MutexUnlock(Mutex:TMutexHandle):LongWord;
Description: Unlock an existing Mutex entry


[Expand]
function MutexTryLock(Mutex:TMutexHandle):LongWord;
Description: Try to lock an existing Mutex entry


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


List functions

[Expand]
function ListCreate:TListHandle;
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 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 ListInsert(List:TListHandle; Previous,Element:PListElement):LongWord;
Description: Insert a new element in 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


Queue functions

[Expand]
function QueueCreate:TQueueHandle;
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 QueueEnqueue(Queue:TQueueHandle; Thread:TThreadHandle):LongWord;
Description: Add the supplied thread as the last item in 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 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;
Description: Lock the supplied Queue


[Expand]
function QueueUnlock(Queue:TQueueHandle):LongWord;
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 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 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]
function ThreadSetLastError(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 ThreadAllocTlsIndex:LongWord;
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 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 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



Return to Unit Reference