summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 37a71824d7..e4dbebe1c4 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -454,6 +454,7 @@ thread_add_unuse (struct thread_master *m, struct thread *thread)
assert (m != NULL && thread != NULL);
assert (thread->next == NULL);
assert (thread->prev == NULL);
+ thread->ref = NULL;
thread->type = THREAD_UNUSED;
thread->hist->total_active--;
@@ -775,7 +776,7 @@ fd_clear_read_write (struct thread *thread)
}
/* Add new read thread. */
-struct thread *
+void
funcname_thread_add_read_write (int dir, struct thread_master *m,
int (*func) (struct thread *), void *arg, int fd, struct thread **t_ptr,
debugargdef)
@@ -787,7 +788,7 @@ funcname_thread_add_read_write (int dir, struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return NULL;
+ return;
}
#if defined (HAVE_POLL_CALL)
@@ -831,14 +832,15 @@ funcname_thread_add_read_write (int dir, struct thread_master *m,
}
if (t_ptr)
- *t_ptr = thread;
+ {
+ *t_ptr = thread;
+ thread->ref = t_ptr;
+ }
}
pthread_mutex_unlock (&m->mtx);
-
- return thread;
}
-static struct thread *
+static void
funcname_thread_add_timer_timeval (struct thread_master *m,
int (*func) (struct thread *), int type, void *arg,
struct timeval *time_relative, struct thread **t_ptr, debugargdef)
@@ -856,7 +858,7 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return NULL;
+ return;
}
queue = ((type == THREAD_TIMER) ? m->timer : m->background);
@@ -871,16 +873,17 @@ funcname_thread_add_timer_timeval (struct thread_master *m,
pthread_mutex_unlock (&thread->mtx);
if (t_ptr)
- *t_ptr = thread;
+ {
+ *t_ptr = thread;
+ thread->ref = t_ptr;
+ }
}
pthread_mutex_unlock (&m->mtx);
-
- return thread;
}
/* Add timer event thread. */
-struct thread *
+void
funcname_thread_add_timer (struct thread_master *m,
int (*func) (struct thread *), void *arg, long timer,
struct thread **t_ptr, debugargdef)
@@ -897,7 +900,7 @@ funcname_thread_add_timer (struct thread_master *m,
}
/* Add timer event thread with "millisecond" resolution */
-struct thread *
+void
funcname_thread_add_timer_msec (struct thread_master *m,
int (*func) (struct thread *), void *arg, long timer,
struct thread **t_ptr, debugargdef)
@@ -909,22 +912,22 @@ funcname_thread_add_timer_msec (struct thread_master *m,
trel.tv_sec = timer / 1000;
trel.tv_usec = 1000*(timer % 1000);
- return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel,
- t_ptr, debugargpass);
+ funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel,
+ t_ptr, debugargpass);
}
/* Add timer event thread with "millisecond" resolution */
-struct thread *
+void
funcname_thread_add_timer_tv (struct thread_master *m,
int (*func) (struct thread *), void *arg, struct timeval *tv,
struct thread **t_ptr, debugargdef)
{
- return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv,
- t_ptr, debugargpass);
+ funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv, t_ptr,
+ debugargpass);
}
/* Add a background thread, with an optional millisec delay */
-struct thread *
+void
funcname_thread_add_background (struct thread_master *m,
int (*func) (struct thread *), void *arg, long delay,
struct thread **t_ptr, debugargdef)
@@ -944,12 +947,12 @@ funcname_thread_add_background (struct thread_master *m,
trel.tv_usec = 0;
}
- return funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg,
- &trel, t_ptr, debugargpass);
+ funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, &trel,
+ t_ptr, debugargpass);
}
/* Add simple event thread. */
-struct thread *
+void
funcname_thread_add_event (struct thread_master *m,
int (*func) (struct thread *), void *arg, int val,
struct thread **t_ptr, debugargdef)
@@ -963,7 +966,7 @@ funcname_thread_add_event (struct thread_master *m,
if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule
{
pthread_mutex_unlock (&m->mtx);
- return NULL;
+ return;
}
thread = thread_get (m, THREAD_EVENT, func, arg, debugargpass);
@@ -975,11 +978,12 @@ funcname_thread_add_event (struct thread_master *m,
pthread_mutex_unlock (&thread->mtx);
if (t_ptr)
- *t_ptr = thread;
+ {
+ *t_ptr = thread;
+ thread->ref = t_ptr;
+ }
}
pthread_mutex_unlock (&m->mtx);
-
- return thread;
}
static void
@@ -1077,6 +1081,9 @@ thread_cancel (struct thread *thread)
assert(!"Thread should be either in queue or list or array!");
}
+ if (thread->ref)
+ *thread->ref = NULL;
+
thread_add_unuse (thread->master, thread);
done:
@@ -1106,6 +1113,8 @@ thread_cancel_event (struct thread_master *m, void *arg)
{
ret++;
thread_list_delete (&m->event, t);
+ if (t->ref)
+ *t->ref = NULL;
thread_add_unuse (m, t);
}
}
@@ -1125,6 +1134,8 @@ thread_cancel_event (struct thread_master *m, void *arg)
{
ret++;
thread_list_delete (&m->ready, t);
+ if (t->ref)
+ *t->ref = NULL;
thread_add_unuse (m, t);
}
}
@@ -1306,6 +1317,8 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
if ((thread = thread_trim_head (&m->ready)) != NULL)
{
fetch = thread_run (m, thread, fetch);
+ if (fetch->ref)
+ *fetch->ref = NULL;
pthread_mutex_unlock (&m->mtx);
return fetch;
}
@@ -1375,6 +1388,8 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
if ((thread = thread_trim_head (&m->ready)) != NULL)
{
fetch = thread_run (m, thread, fetch);
+ if (fetch->ref)
+ *fetch->ref = NULL;
pthread_mutex_unlock (&m->mtx);
return fetch;
}
@@ -1386,6 +1401,8 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
if ((thread = thread_trim_head (&m->ready)) != NULL)
{
fetch = thread_run (m, thread, fetch);
+ if (fetch->ref)
+ *fetch->ref = NULL;
pthread_mutex_unlock (&m->mtx);
return fetch;
}
@@ -1493,7 +1510,7 @@ thread_call (struct thread *thread)
}
/* Execute thread */
-struct thread *
+void
funcname_thread_execute (struct thread_master *m,
int (*func)(struct thread *),
void *arg,
@@ -1525,6 +1542,4 @@ funcname_thread_execute (struct thread_master *m,
dummy.schedfrom_line = fromln;
thread_call (&dummy);
-
- return NULL;
}