summaryrefslogtreecommitdiffstats
path: root/avahi-common
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-12-12 19:37:24 +0100
committerLennart Poettering <lennart@poettering.net>2008-12-12 19:37:24 +0100
commitdf0f904f29312efd82cdbf55adb37b10cee47a6e (patch)
tree89080dc296ebad450d92449422db0aef464030d0 /avahi-common
parent292f62a27cf22211ad12aeac190c4f4b15c6a07e (diff)
actually set thread_running. Closes #251
Diffstat (limited to 'avahi-common')
-rw-r--r--avahi-common/thread-watch.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/avahi-common/thread-watch.c b/avahi-common/thread-watch.c
index 1a5d9d2..4f23608 100644
--- a/avahi-common/thread-watch.c
+++ b/avahi-common/thread-watch.c
@@ -2,17 +2,17 @@
/***
This file is part of avahi.
-
+
avahi 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.
-
+
avahi 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 avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -53,7 +53,7 @@ static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *
/* Before entering poll() we unlock the mutex, so that
* avahi_simple_poll_quit() can succeed from another thread. */
-
+
pthread_mutex_unlock(mutex);
r = poll(ufds, nfds, timeout);
pthread_mutex_lock(mutex);
@@ -68,11 +68,11 @@ static void* thread(void *userdata){
/* Make sure that signals are delivered to the main thread */
sigfillset(&mask);
pthread_sigmask(SIG_BLOCK, &mask, NULL);
-
+
pthread_mutex_lock(&p->mutex);
p->retval = avahi_simple_poll_loop(p->simple_poll);
pthread_mutex_unlock(&p->mutex);
-
+
return NULL;
}
@@ -81,14 +81,14 @@ AvahiThreadedPoll *avahi_threaded_poll_new(void) {
if (!(p = avahi_new(AvahiThreadedPoll, 1)))
goto fail; /* OOM */
-
+
if (!(p->simple_poll = avahi_simple_poll_new()))
goto fail;
-
+
pthread_mutex_init(&p->mutex, NULL);
avahi_simple_poll_set_func(p->simple_poll, poll_func, &p->mutex);
-
+
p->thread_running = 0;
return p;
@@ -136,6 +136,8 @@ int avahi_threaded_poll_start(AvahiThreadedPoll *p) {
if (pthread_create(&p->thread_id, NULL, thread, p) < 0)
return -1;
+ p->thread_running = 1;
+
return 0;
}
@@ -151,7 +153,7 @@ int avahi_threaded_poll_stop(AvahiThreadedPoll *p) {
pthread_mutex_lock(&p->mutex);
avahi_simple_poll_quit(p->simple_poll);
pthread_mutex_unlock(&p->mutex);
-
+
pthread_join(p->thread_id, NULL);
p->thread_running = 0;
@@ -172,7 +174,7 @@ void avahi_threaded_poll_lock(AvahiThreadedPoll *p) {
/* Make sure that this function is not called from the helper thread */
assert(!p->thread_running || !pthread_equal(pthread_self(), p->thread_id));
-
+
pthread_mutex_lock(&p->mutex);
}
@@ -181,6 +183,6 @@ void avahi_threaded_poll_unlock(AvahiThreadedPoll *p) {
/* Make sure that this function is not called from the helper thread */
assert(!p->thread_running || !pthread_equal(pthread_self(), p->thread_id));
-
+
pthread_mutex_unlock(&p->mutex);
}