Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the errno as the error number that a pthread function returns #454

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/sb_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#ifdef HAVE_PTHREAD_H
# include <pthread.h>
# include <errno.h>
#endif

#ifndef HAVE_PTHREAD_CANCEL
Expand Down Expand Up @@ -122,8 +123,12 @@ static void* thread_start_routine_proxy(void *arg) {
int sb_thread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
int rv;
#ifdef HAVE_PTHREAD_CANCEL
return pthread_create(thread, attr, start_routine, arg);
rv = pthread_create(thread, attr, start_routine, arg);
if (rv)
errno = rv;
return rv;
#else
struct sb_thread_proxy *proxy = malloc(sizeof(struct sb_thread_proxy));
if (!proxy)
Expand All @@ -132,27 +137,36 @@ int sb_thread_create(pthread_t *thread, const pthread_attr_t *attr,
}
proxy->start_routine = start_routine;
proxy->arg = arg;
int rv = pthread_create(thread, attr, thread_start_routine_proxy, proxy);
rv = pthread_create(thread, attr, thread_start_routine_proxy, proxy);
if (rv)
{
free(proxy);
errno = rv;
}
return rv;
#endif
}

int sb_thread_join(pthread_t thread, void **retval)
{
return pthread_join(thread, retval);
int rv;
rv = pthread_join(thread, retval);
if (rv)
errno = rv;
return rv;
}

int sb_thread_cancel(pthread_t thread)
{
int rv;
#ifdef HAVE_PTHREAD_CANCEL
return pthread_cancel(thread);
rv = pthread_cancel(thread);
#else
return pthread_kill(thread, thread_cancel_signal);
rv = pthread_kill(thread, thread_cancel_signal);
#endif
if (rv)
errno = rv;
return rv;
}

int sb_thread_create_workers(void *(*worker_routine)(void*))
Expand Down