std/private/threadtypes

Source   Edit  

Types

GcThread {.pure, inheritable.} = object
  when emulatedThreadVars:
      tls*: ThreadLocalStorage

  else:
      nil

  when hasSharedHeap:
      next*, prev*: PGcThread
      stackBottom*, stackTop*: pointer
      stackSize*: int

  else:
      nil

  
Source   Edit  
Handle = int
Source   Edit  
PGcThread = ptr GcThread
Source   Edit  
Thread[TArg] = object
  core*: PGcThread
  sys*: SysThread
  when TArg is void:
      dataFn*: proc () {.nimcall, ...gcsafe.}

  else:
      dataFn*: proc (m: TArg) {.nimcall, ...gcsafe.}
      data*: TArg

  when hasAllocStack:
      rawStack*: pointer

  
Source   Edit  
ThreadLocalStorage = array[0 .. (nimTlsSize div 8), float]
Source   Edit  
WinThreadProc = proc (x: pointer): int32 {.stdcall.}
Source   Edit  

Consts

emulatedThreadVars = false
Source   Edit  
hasAllocStack = false
Source   Edit  
hasSharedHeap = false
Source   Edit  

Procs

proc `=copy`[TArg](x: var Thread[TArg]; y: Thread[TArg]) {.error.}
Source   Edit  
proc createThread(lpThreadAttributes: pointer; dwStackSize: int32;
                  lpStartAddress: WinThreadProc; lpParameter: pointer;
                  dwCreationFlags: int32; lpThreadId: var int32): SysThread {.
    stdcall, dynlib: "kernel32", importc: "CreateThread", ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc setThreadAffinityMask(hThread: SysThread; dwThreadAffinityMask: uint) {.
    importc: "SetThreadAffinityMask", stdcall, header: "<windows.h>",
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc terminateThread(hThread: SysThread; dwExitCode: int32): int32 {.stdcall,
    dynlib: "kernel32", importc: "TerminateThread", ...raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc waitForMultipleObjects(nCount: int32; lpHandles: ptr SysThread;
                            bWaitAll: int32; dwMilliseconds: int32): int32 {.
    stdcall, dynlib: "kernel32", importc: "WaitForMultipleObjects", ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc waitForSingleObject(hHandle: SysThread; dwMilliseconds: int32): int32 {.
    stdcall, dynlib: "kernel32", importc: "WaitForSingleObject", ...raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc winResumeThread(hThread: SysThread): int32 {.stdcall, dynlib: "kernel32",
    importc: "ResumeThread", ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc winSuspendThread(hThread: SysThread): int32 {.stdcall, dynlib: "kernel32",
    importc: "SuspendThread", ...raises: [], tags: [], forbids: [].}
Source   Edit