aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jobs.c6
-rw-r--r--src/jobs.h2
-rw-r--r--src/tests/test-thread.c7
-rwxr-xr-xsrc/tests/test-thread.sh4
4 files changed, 11 insertions, 8 deletions
diff --git a/src/jobs.c b/src/jobs.c
index 1be6ec7b..2910f0a3 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -146,7 +146,9 @@ static struct job *job_create(
/* allocates the job */
job = free_jobs;
- if (!job) {
+ if (job)
+ free_jobs = job->next;
+ else {
pthread_mutex_unlock(&mutex);
job = malloc(sizeof *job);
pthread_mutex_lock(&mutex);
@@ -369,7 +371,7 @@ int jobs_init(int allowed_count, int start_count, int waiter_count)
}
/* terminate all the threads and all pending requests */
-void jobs_terminate()
+void jobs_terminate(int wait)
{
struct job *job;
pthread_t me, other;
diff --git a/src/jobs.h b/src/jobs.h
index b6f277c5..95565b86 100644
--- a/src/jobs.h
+++ b/src/jobs.h
@@ -42,6 +42,6 @@ extern int jobs_add_event_loop(void *key, int timeout, void (*evloop)(int, void*
extern int jobs_init(int allowed_count, int start_count, int waiter_count);
extern int jobs_add_me();
-extern void jobs_terminate();
+extern void jobs_terminate(int wait);
diff --git a/src/tests/test-thread.c b/src/tests/test-thread.c
index cc676bd0..2f0e1853 100644
--- a/src/tests/test-thread.c
+++ b/src/tests/test-thread.c
@@ -7,6 +7,7 @@
#include <afb/afb-req-itf.h>
#include "../afb-thread.h"
+#include "../jobs.h"
struct foo {
int value;
@@ -77,12 +78,12 @@ int main()
struct timespec ts;
req.itf = &itf;
- afb_thread_init(4, 1);
+ jobs_init(4, 0, 20000);
for (i = 0 ; i < 10000 ; i++) {
req.closure = foo = malloc(sizeof *foo);
foo->value = i;
foo->refcount = 1;
- afb_thread_call(req, process, 5, (&ts) + (i % 4));
+ afb_thread_req_call(req, process, 5, (&ts) + (i % 7));
unref(foo);
ts.tv_sec = 0;
ts.tv_nsec = 1000000;
@@ -91,7 +92,7 @@ int main()
ts.tv_sec = 1;
ts.tv_nsec = 0;
nanosleep(&ts, NULL);
- afb_thread_terminate();
+ jobs_terminate();
}
diff --git a/src/tests/test-thread.sh b/src/tests/test-thread.sh
index 6d1b3a53..d5186d19 100755
--- a/src/tests/test-thread.sh
+++ b/src/tests/test-thread.sh
@@ -1,4 +1,4 @@
#!/bin/sh
-cc test-thread.c ../afb-thread.c ../verbose.c ../afb-sig-handler.c -o test-thread -lrt -lpthread -I../../include
-./test-thread
+cc test-thread.c ../afb-thread.c ../verbose.c ../sig-monitor.c ../jobs.c -o test-thread -lrt -lpthread -I../../include -g -O2
+gdb ./test-thread