From 181e9c6d5d11cb1e5d36a2777eeb233ad8ed00e5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 9 Oct 2008 18:15:23 +0200 Subject: big pile of updates to match more what happened with libcanberra --- src/thread-posix.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/thread-posix.c') 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 + . +***/ + #ifdef HAVE_CONFIG_H #include #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); -- cgit