Difference between revisions of "Unit Threads"
From Ultibo.org
Line 474: | Line 474: | ||
! '''Note''' | ! '''Note''' | ||
| Both Spin entries must be locked by the current thread | | Both Spin entries must be locked by the current thread | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | '''Mutex functions''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexCreate:TMutexHandle;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create and insert a new Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | Handle of new Mutex entry or INVALID_HANDLE_VALUE if entry could not be created | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexCreateEx(InitialOwner:Boolean; SpinCount:LongWord; Flags:LongWord):TMutexHandle;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create and insert a new Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''InitialOwner''' | ||
+ | | If true set the state of the mutex to locked and the owner to the current thread | ||
+ | |- | ||
+ | ! '''SpinCount''' | ||
+ | | The number of times the mutex will spin before yielding (Always 0 if CPU count equals 1) | ||
+ | |- | ||
+ | ! '''Flags''' | ||
+ | | The flags for the Mutex entry (eg MUTEX_FLAG_RECURSIVE) | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | Handle of new Mutex entry or INVALID_HANDLE_VALUE if entry could not be created | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexDestroy(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Destroy and remove an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Handle of Mutex entry to destroy | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexFlags(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current flags of an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Handle of Mutex entry to get flags for | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | Current flags or INVALID_HANDLE_VALUE on error | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexCount(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current lock count of an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Mutex to get count for | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | Current lock count or INVALID_HANDLE_VALUE on error | ||
+ | |- | ||
+ | ! '''Note''' | ||
+ | | Count is only valid if Flags includes MUTEX_FLAG_RECURSIVE | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexOwner(Mutex:TMutexHandle):TThreadHandle;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current owner of an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Handle of Mutex entry to get owner for | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | Handle of owning thread or INVALID_HANDLE_VALUE if not currently owned | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexLock(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Lock an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Handle of Mutex entry to lock | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexUnlock(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Unlock an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Handle of Mutex entry to unlock | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | ERROR_SUCCESS if completed or another error code on failure | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function MutexTryLock(Mutex:TMutexHandle):LongWord;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Try to lock an existing Mutex entry</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! '''Mutex''' | ||
+ | | Mutex to try to lock | ||
+ | |- | ||
+ | ! '''Return''' | ||
+ | | ERROR_SUCCESS if completed, ERROR_LOCKED if already locked or another error code on failure | ||
+ | |- | ||
+ | ! '''Note''' | ||
+ | | 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. | ||
|- | |- | ||
|} | |} |
Revision as of 01:20, 9 September 2016
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
procedure LocksInit;
Description: Initialize Locks
Note | To be documented |
---|
procedure ThreadsInit;
Description: Initialize Threading
Note | To be documented |
---|
procedure PrimaryInit;
Description: Initialize the primary CPU
Note | To be documented |
---|
procedure SchedulerInit;
Description: Initialize the thread scheduler
Note | To be documented |
---|
procedure SchedulerStart(CPUID:LongWord);
Description: Initialize the thread scheduler for secondary CPUs (Where Applicable)
Note | To be documented |
---|
procedure SecondaryInit;
Description: Initialize the secondary CPUs (Where Applicable)
Note | To be documented |
---|
procedure SecondaryBoot(CPUID:LongWord);
Description: Boot the specified secondary CPU (Where Applicable)
Note | To be documented |
---|
procedure SecondaryStart(CPUID:LongWord);
Description: Startup procedure for secondary CPUs (Where Applicable)
Note | The Secondary Boot procedure should have already cleared L1 cache, enabled FPU, MMU, Vectors and PageTables before calling this function. The thread id of the IRQ or FIQ should also have been loaded into the appropriate registers. |
---|
function IRQExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function FIQExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function SWIExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function IdleExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function MainExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function TimerExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function WorkerExecute(Parameter:Pointer):PtrInt;
Description: To be documented
Note | To be documented |
---|
function IdleCalibrate:LongWord;
Description: Calibrate the idle thread loop by counting the number of loops in 100ms
Note | To be documented |
---|
Spin functions
function SpinCreate:TSpinHandle;
Description: Create and insert a new Spin entry
Return | Handle of new Spin entry or INVALID_HANDLE_VALUE if entry could not be created |
---|
function SpinCreateEx(InitialOwner:Boolean):TSpinHandle;
Description: Create and insert a new Spin entry
InitialOwner | If true set the state of the spin to locked and the owner to the current thread |
---|---|
Return | Handle of new Spin entry or INVALID_HANDLE_VALUE if entry could not be created |
function SpinDestroy(Spin:TSpinHandle):LongWord;
Description: Destroy and remove an existing Spin entry
Spin | Handle of Spin entry to destroy |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinOwner(Spin:TSpinHandle):TThreadHandle;
Description: Get the current owner of an existing Spin entry
Spin | Handle of Spin entry to get owner for |
---|---|
Return | Handle of owning thread or INVALID_HANDLE_VALUE if not currently owned |
function SpinLock(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry
Spin | Handle of Spin entry to lock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinUnlock(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry
Spin | Handle of Spin entry to unlock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinLockIRQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable IRQ and save the previous IRQ state
Spin | Handle of Spin entry to lock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinUnlockIRQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous IRQ state
Spin | Handle of Spin entry to unlock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinLockFIQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable FIQ and save the previous FIQ state
Spin | Handle of Spin entry to lock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinUnlockFIQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous FIQ state
Spin | Handle of Spin entry to unlock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinLockIRQFIQ(Spin:TSpinHandle):LongWord;
Description: Lock an existing Spin entry, disable IRQ and FIQ and save the previous IRQ and FIQ state
Spin | Handle of Spin entry to lock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinUnlockIRQFIQ(Spin:TSpinHandle):LongWord;
Description: Unlock an existing Spin entry and restore the previous IRQ and FIQ state
Spin | Handle of Spin entry to unlock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function SpinCheckIRQ(Spin:TSpinHandle):Boolean;
Description: Check the mask that stores the previous IRQ state to determine if IRQ is enabled
Spin | Handle of Spin entry to check |
---|---|
Return | True if the mask would enable IRQ on restore, False if it would not |
Note | The Spin entry must be locked by the current thread |
function SpinCheckFIQ(Spin:TSpinHandle):Boolean;
Description: Check the mask that stores the previous FIQ state to determine if FIQ is enabled
Spin | Handle of Spin entry to check |
---|---|
Return | True if the mask would enable FIQ on restore, False if it would not |
Note | The Spin entry must be locked by the current thread |
function SpinExchangeIRQ(Spin1,Spin2:TSpinHandle):LongWord;
Description: Exchange the previous IRQ state between two Spin entries
Spin1 | Handle of first Spin entry |
---|---|
Spin2 | Handle of second Spin entry |
Return | ERROR_SUCCESS if completed or another error code on failure |
Note | Both Spin entries must be locked by the current thread |
function SpinExchangeFIQ(Spin1,Spin2:TSpinHandle):LongWord;
Description: Exchange the previous FIQ state between two Spin entries
Spin1 | Handle of first Spin entry |
---|---|
Spin2 | Handle of second Spin entry |
Return | ERROR_SUCCESS if completed or another error code on failure |
Note | Both Spin entries must be locked by the current thread |
Mutex functions
function MutexCreate:TMutexHandle;
Description: Create and insert a new Mutex entry
Return | Handle of new Mutex entry or INVALID_HANDLE_VALUE if entry could not be created |
---|
function MutexCreateEx(InitialOwner:Boolean; SpinCount:LongWord; Flags:LongWord):TMutexHandle;
Description: Create and insert a new Mutex entry
InitialOwner | If true set the state of the mutex to locked and the owner to the current thread |
---|---|
SpinCount | The number of times the mutex will spin before yielding (Always 0 if CPU count equals 1) |
Flags | The flags for the Mutex entry (eg MUTEX_FLAG_RECURSIVE) |
Return | Handle of new Mutex entry or INVALID_HANDLE_VALUE if entry could not be created |
function MutexDestroy(Mutex:TMutexHandle):LongWord;
Description: Destroy and remove an existing Mutex entry
Mutex | Handle of Mutex entry to destroy |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function MutexFlags(Mutex:TMutexHandle):LongWord;
Description: Get the current flags of an existing Mutex entry
Mutex | Handle of Mutex entry to get flags for |
---|---|
Return | Current flags or INVALID_HANDLE_VALUE on error |
function MutexCount(Mutex:TMutexHandle):LongWord;
Description: Get the current lock count of an existing Mutex entry
Mutex | Mutex to get count for |
---|---|
Return | Current lock count or INVALID_HANDLE_VALUE on error |
Note | Count is only valid if Flags includes MUTEX_FLAG_RECURSIVE |
function MutexOwner(Mutex:TMutexHandle):TThreadHandle;
Description: Get the current owner of an existing Mutex entry
Mutex | Handle of Mutex entry to get owner for |
---|---|
Return | Handle of owning thread or INVALID_HANDLE_VALUE if not currently owned |
function MutexLock(Mutex:TMutexHandle):LongWord;
Description: Lock an existing Mutex entry
Mutex | Handle of Mutex entry to lock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function MutexUnlock(Mutex:TMutexHandle):LongWord;
Description: Unlock an existing Mutex entry
Mutex | Handle of Mutex entry to unlock |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function MutexTryLock(Mutex:TMutexHandle):LongWord;
Description: Try to lock an existing Mutex entry
Mutex | Mutex to try to lock |
---|---|
Return | ERROR_SUCCESS if completed, ERROR_LOCKED if already locked or another error code on failure |
Note | 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. |
Return to Unit Reference