set the task specific value associated with a given Thread-Local Storage index (V51.46)
Source position: exec.pas line 2348
function TLSSetValue( |
Idx: LongWord; |
Value: Pointer |
):LongInt; |
Idx |
|
index to set value for. |
Value |
|
value to set. |
Non-zero if the value could be set, zero if out of resources. Note that setting value to nil will always succeed.
Set the task specific value associated with the given Thread-Local Storage index.
Attention
The result of this call must be checked and a viable error handling path taken.
|
Free Thread-Local Storage index |
|
|
VarArgs version of TLSAllocA |
|
|
Call Thread-Local Storage index destructors for the given task (V51.46) |
|
|
get the task specific value associated with a given Thread-Local Storage index (V51.46) |
type TTLSData = record foo: LongWord; bar: PChar; // ... end; PTLSData = ^TTtlsdata; var TLSIndex: LongWord; // Set and cleaned up elsewhere TLSData: Ptlsdata; begin Data := PTLSData(TLSGetValue(TLSIndex)); if not Assigned(data) then begin data := PTLSData(AllocVec(SizeOf(Ttlsdata), MEMF_CLEAR)); if not Assigned(data) or (TLSSetValue(TLSIndex, data) <> 0) then begin if Assigned(data) then begin FreeVec(data); data := NULL; end; end; end; if Assigned(data) then begin // Use the thread specific data. ... end; //... // Thread specific data is no longer needed, free it. data := PTLSData(TLSGetValue(tlsindex)); if Assigned(data) then begin FreeVec(Data); TLSSetValue(tlsindex, nil); // Always succeeds end; end;