/* 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);
}
/* terminate all the threads and all pending requests */
-void jobs_terminate()
+void jobs_terminate(int wait)
{
struct job *job;
pthread_t me, other;
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);
#include <afb/afb-req-itf.h>
#include "../afb-thread.h"
+#include "../jobs.h"
struct foo {
int value;
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;
ts.tv_sec = 1;
ts.tv_nsec = 0;
nanosleep(&ts, NULL);
- afb_thread_terminate();
+ jobs_terminate();
}
#!/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