diff options
author | Saúl Ibarra Corretgé <saghul@gmail.com> | 2014-11-21 15:43:12 +0100 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2014-11-26 12:08:36 -0800 |
commit | 9d9ed61c5a97562b93a2326f33922783ed509d47 (patch) | |
tree | 702c9dcc3a54bcc7bad26b9b756ddada54795c02 /deps/uv/src/win/thread.c | |
parent | 2d17193f20930bfe594d7008fe5c08f813f03c7b (diff) | |
download | android-node-v8-9d9ed61c5a97562b93a2326f33922783ed509d47.tar.gz android-node-v8-9d9ed61c5a97562b93a2326f33922783ed509d47.tar.bz2 android-node-v8-9d9ed61c5a97562b93a2326f33922783ed509d47.zip |
deps: update libuv to 1.0.0
PR-URL: https://github.com/joyent/node/pull/8762
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'deps/uv/src/win/thread.c')
-rw-r--r-- | deps/uv/src/win/thread.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/deps/uv/src/win/thread.c b/deps/uv/src/win/thread.c index ccc5579fa7..7143743926 100644 --- a/deps/uv/src/win/thread.c +++ b/deps/uv/src/win/thread.c @@ -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 */ + 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)) @@ -129,6 +191,11 @@ int uv_thread_join(uv_thread_t *tid) { } +int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) { + return *t1 == *t2; +} + + int uv_mutex_init(uv_mutex_t* mutex) { InitializeCriticalSection(mutex); return 0; |