make getThreadId() work on Linux

This commit is contained in:
araq
2017-01-31 13:49:32 +01:00
parent 97d91bb6b7
commit eaa0eda72d

View File

@@ -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".}