unix,windows: make uv_thread_create() return errno

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é <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2015-02-14 22:19:19 +01:00
parent 3ddfb4a9cc
commit ff0316813d
3 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}