added system.getThreadId for various OSes (untested)
This commit is contained in:
parent
082f6f15e7
commit
b173499543
1 changed files with 31 additions and 1 deletions
|
|
@ -53,7 +53,7 @@ when defined(windows):
|
||||||
type
|
type
|
||||||
SysThread* = Handle
|
SysThread* = Handle
|
||||||
WinThreadProc = proc (x: pointer): int32 {.stdcall.}
|
WinThreadProc = proc (x: pointer): int32 {.stdcall.}
|
||||||
{.deprecated: [TSysThread: SysThread, TWinThreadProc: WinThreadProc].}
|
{.deprecated: [TSysThread: SysThread].}
|
||||||
|
|
||||||
proc createThread(lpThreadAttributes: pointer, dwStackSize: int32,
|
proc createThread(lpThreadAttributes: pointer, dwStackSize: int32,
|
||||||
lpStartAddress: WinThreadProc,
|
lpStartAddress: WinThreadProc,
|
||||||
|
|
@ -77,6 +77,9 @@ when defined(windows):
|
||||||
proc terminateThread(hThread: SysThread, dwExitCode: int32): int32 {.
|
proc terminateThread(hThread: SysThread, dwExitCode: int32): int32 {.
|
||||||
stdcall, dynlib: "kernel32", importc: "TerminateThread".}
|
stdcall, dynlib: "kernel32", importc: "TerminateThread".}
|
||||||
|
|
||||||
|
proc getCurrentThreadId(): int32 {.
|
||||||
|
stdcall, dynlib: "kernel32", importc: "GetCurrentThreadId".}
|
||||||
|
|
||||||
type
|
type
|
||||||
ThreadVarSlot = distinct int32
|
ThreadVarSlot = distinct int32
|
||||||
|
|
||||||
|
|
@ -108,6 +111,10 @@ when defined(windows):
|
||||||
proc setThreadAffinityMask(hThread: SysThread, dwThreadAffinityMask: uint) {.
|
proc setThreadAffinityMask(hThread: SysThread, dwThreadAffinityMask: uint) {.
|
||||||
importc: "SetThreadAffinityMask", stdcall, header: "<windows.h>".}
|
importc: "SetThreadAffinityMask", stdcall, header: "<windows.h>".}
|
||||||
|
|
||||||
|
proc getThreadId*(): int =
|
||||||
|
## get the ID of the currently running thread.
|
||||||
|
result = int(getCurrentThreadId())
|
||||||
|
|
||||||
else:
|
else:
|
||||||
when not defined(macosx):
|
when not defined(macosx):
|
||||||
{.passL: "-pthread".}
|
{.passL: "-pthread".}
|
||||||
|
|
@ -187,6 +194,29 @@ else:
|
||||||
proc setAffinity(thread: SysThread; setsize: csize; s: var CpuSet) {.
|
proc setAffinity(thread: SysThread; setsize: csize; s: var CpuSet) {.
|
||||||
importc: "pthread_setaffinity_np", header: pthreadh.}
|
importc: "pthread_setaffinity_np", header: pthreadh.}
|
||||||
|
|
||||||
|
when defined(linux):
|
||||||
|
type Pid {.importc: "pid_t", header: "<sys/types.h>".} = distinct int
|
||||||
|
proc gettid(): Pid {.importc, header: "<sys/types.h>".}
|
||||||
|
|
||||||
|
proc getThreadId*(): int =
|
||||||
|
## get the ID of the currently running thread.
|
||||||
|
result = int(gettid())
|
||||||
|
elif defined(macosx) or defined(bsd):
|
||||||
|
proc pthread_main_np(): cint {.importc, header: "pthread.h".}
|
||||||
|
|
||||||
|
proc getThreadId*(): int =
|
||||||
|
## get the ID of the currently running thread.
|
||||||
|
result = int(pthread_main_np())
|
||||||
|
elif defined(solaris):
|
||||||
|
# just a guess really:
|
||||||
|
type thread_t {.importc: "thread_t", header: "<thread.h>".} = distinct int
|
||||||
|
proc thr_self(): thread_t {.importc, header: "<thread.h>".}
|
||||||
|
|
||||||
|
proc getThreadId*(): int =
|
||||||
|
## get the ID of the currently running thread.
|
||||||
|
result = int(thr_self())
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
emulatedThreadVars = compileOption("tlsEmulation")
|
emulatedThreadVars = compileOption("tlsEmulation")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue