summaryrefslogtreecommitdiffstats
path: root/src/thread-posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread-posix.c')
-rw-r--r--src/thread-posix.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/thread-posix.c b/src/thread-posix.c
index d76e8d5..33efe41 100644
--- a/src/thread-posix.c
+++ b/src/thread-posix.c
@@ -1,3 +1,23 @@
+/***
+ This file is part of libsydney.
+
+ Copyright 2007-2008 Lennart Poettering
+
+ libsydney is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 2.1 of the
+ License, or (at your option) any later version.
+
+ libsydney is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with libsydney. If not, see
+ <http://www.gnu.org/licenses/>.
+***/
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -17,6 +37,7 @@ struct sa_thread {
void *userdata;
int running;
sa_mutex *mutex;
+ sa_bool_t joined;
};
struct sa_tls {
@@ -78,6 +99,7 @@ sa_thread* sa_thread_new(sa_thread_func_t thread_func, void *userdata) {
t->thread_func = thread_func;
t->userdata = userdata;
t->running = 1;
+ t->joined = FALSE;
if (!(t->mutex = sa_mutex_new(FALSE, FALSE))) {
sa_free(t);
@@ -127,6 +149,10 @@ int sa_thread_join(sa_thread *t) {
/* Only allowed when this is not a foreign thread */
sa_assert(t->thread_func);
+ if (t->joined)
+ return -1;
+
+ t->joined = TRUE;
return pthread_join(t->id, NULL);
}
@@ -151,6 +177,7 @@ sa_thread* sa_thread_self(void) {
t->thread_func = NULL;
t->userdata = NULL;
t->running = 2;
+ t->joined = TRUE;
t->mutex = sa_mutex_new(FALSE, FALSE);
sa_tls_set(tid_tls, t);