-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59658a8 changed uv_thread_self() to return uv_thread_t, but uv_thread_t is a thread's HANDLE while uv_thread_self() returns the current thread's id. This means that uv_thread_equal() is also broken, as we are potentially comparing HANDLES to ids. Changed uv_thread_self() to return the current thread's creation handle. Fixed small doc issue.
- Loading branch information
1 parent
0f25560
commit 6591d00
Showing
4 changed files
with
108 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,68 @@ void uv_once(uv_once_t* guard, void (*callback)(void)) { | |
uv__once_inner(guard, callback); | ||
} | ||
|
||
static UV_THREAD_LOCAL uv_thread_t uv__current_thread = NULL; | ||
|
||
struct thread_ctx { | ||
void (*entry)(void* arg); | ||
void* arg; | ||
uv_thread_t self; | ||
}; | ||
|
||
|
||
static UINT __stdcall uv__thread_start(void* arg) | ||
{ | ||
struct thread_ctx *ctx_p; | ||
struct thread_ctx ctx; | ||
|
||
ctx_p = arg; | ||
ctx = *ctx_p; | ||
free(ctx_p); | ||
|
||
uv__current_thread = ctx.self; | ||
ctx.entry(ctx.arg); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { | ||
struct thread_ctx* ctx; | ||
int err; | ||
HANDLE thread; | ||
|
||
ctx = malloc(sizeof(*ctx)); | ||
if (ctx == NULL) | ||
return UV_ENOMEM; | ||
|
||
ctx->entry = entry; | ||
ctx->arg = arg; | ||
|
||
/* Create the thread in suspended state so we have a chance to pass | ||
* its own creation handle to it */ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
trevnorris
Member
|
||
thread = (HANDLE) _beginthreadex(NULL, | ||
0, | ||
uv__thread_start, | ||
ctx, | ||
CREATE_SUSPENDED, | ||
NULL); | ||
if (thread == NULL) { | ||
err = errno; | ||
free(ctx); | ||
} else { | ||
err = 0; | ||
*tid = thread; | ||
ctx->self = thread; | ||
ResumeThread(thread); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
|
||
uv_thread_t uv_thread_self(void) { | ||
return uv__current_thread; | ||
} | ||
|
||
int uv_thread_join(uv_thread_t *tid) { | ||
if (WaitForSingleObject(*tid, INFINITE)) | ||
|
nit: whitespace at end of comment