mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-30 18:41:45 +00:00
Add handle function to Thread type
Exposes SysThread type and introduces the function "handle" to return Thread.sys.
This commit is contained in:
@@ -51,7 +51,7 @@ const
|
|||||||
|
|
||||||
when defined(windows):
|
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, TWinThreadProc: WinThreadProc].}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ else:
|
|||||||
type Time = int
|
type Time = int
|
||||||
|
|
||||||
type
|
type
|
||||||
SysThread {.importc: "pthread_t", header: "<sys/types.h>",
|
SysThread* {.importc: "pthread_t", header: "<sys/types.h>",
|
||||||
final, pure.} = object
|
final, pure.} = object
|
||||||
Pthread_attr {.importc: "pthread_attr_t",
|
Pthread_attr {.importc: "pthread_attr_t",
|
||||||
header: "<sys/types.h>", final, pure.} = object
|
header: "<sys/types.h>", final, pure.} = object
|
||||||
@@ -379,6 +379,10 @@ proc running*[TArg](t: Thread[TArg]): bool {.inline.} =
|
|||||||
## returns true if `t` is running.
|
## returns true if `t` is running.
|
||||||
result = t.dataFn != nil
|
result = t.dataFn != nil
|
||||||
|
|
||||||
|
proc handle*[TArg](t: Thread[TArg]): SysThread {.inline.} =
|
||||||
|
## returns the thread handle of `t`.
|
||||||
|
result = t.sys
|
||||||
|
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
proc joinThread*[TArg](t: Thread[TArg]) {.inline.} =
|
proc joinThread*[TArg](t: Thread[TArg]) {.inline.} =
|
||||||
## waits for the thread `t` to finish.
|
## waits for the thread `t` to finish.
|
||||||
|
|||||||
Reference in New Issue
Block a user