mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
make getThreadId() work on Linux
This commit is contained in:
@@ -195,12 +195,15 @@ else:
|
||||
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 syscall(arg: int): int {.varargs, importc: "syscall", header: "<sys/syscall.h>".}
|
||||
var SYS_gettid {.importc, header: "<sys/syscall.h>".}: int
|
||||
|
||||
#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())
|
||||
result = int(syscall(SYS_gettid))
|
||||
elif defined(macosx) or defined(bsd):
|
||||
proc pthread_main_np(): cint {.importc, header: "pthread.h".}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user