From ff0316813d38253780337178386053cf6c3357f0 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 14 Feb 2015 22:19:19 +0100 Subject: [PATCH] unix,windows: make uv_thread_create() return errno MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, UNIX returned -1 on failure. Windows sometimes returned a UV_E* error code and sometimes a bogus status code, courtesy of errno values not mapping to UV_E* error codes on that platform. PR-URL: https://github.com/libuv/libuv/pull/204 Reviewed-By: Saúl Ibarra Corretgé --- docs/src/threading.rst | 3 +++ src/unix/thread.c | 2 +- src/win/thread.c | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/src/threading.rst b/docs/src/threading.rst index aab13f84..494202b5 100644 --- a/docs/src/threading.rst +++ b/docs/src/threading.rst @@ -56,6 +56,9 @@ Threads ^^^^^^^ .. c:function:: int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg) + + .. versionchanged:: 1.5.0 returns a UV_E* error code on failure + .. c:function:: uv_thread_t uv_thread_self(void) .. c:function:: int uv_thread_join(uv_thread_t *tid) .. c:function:: int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) diff --git a/src/unix/thread.c b/src/unix/thread.c index 7e85bcc5..ea8563fe 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -68,7 +68,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { if (err) free(ctx); - return err ? -1 : 0; + return -err; } diff --git a/src/win/thread.c b/src/win/thread.c index 9b74b5f9..9d273a56 100644 --- a/src/win/thread.c +++ b/src/win/thread.c @@ -175,7 +175,18 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { ResumeThread(thread); } - return err; + switch (err) { + case 0: + return 0; + case EACCES: + return UV_EACCES; + case EAGAIN: + return UV_EAGAIN; + case EINVAL: + return UV_EINVAL; + } + + return UV_EIO; }