2018-01-29 15:14:50 +00:00
|
|
|
// test_bf.c
|
|
|
|
//
|
|
|
|
// Author: J.A. de Jong -ASCEE
|
|
|
|
//
|
|
|
|
// Description:
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "worker.h"
|
|
|
|
#include "mq.h"
|
2018-02-06 11:01:27 +00:00
|
|
|
#include "ascee_tracer.h"
|
2018-02-09 10:56:49 +00:00
|
|
|
#include "ascee_assert.h"
|
2018-02-06 11:01:27 +00:00
|
|
|
#include <unistd.h>
|
2018-01-29 15:14:50 +00:00
|
|
|
static void* walloc(void*);
|
|
|
|
static int worker(void*,void*);
|
|
|
|
static void wfree(void*);
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
fsTRACE(15);
|
|
|
|
|
|
|
|
iVARTRACE(15,getTracerLevel());
|
|
|
|
|
2018-02-06 11:01:27 +00:00
|
|
|
us njobs = 4;
|
2018-01-29 15:14:50 +00:00
|
|
|
JobQueue* jq = JobQueue_alloc(njobs);
|
2018-02-09 10:56:49 +00:00
|
|
|
dbgassert(jq,NULLPTRDEREF);
|
2018-01-29 15:14:50 +00:00
|
|
|
|
|
|
|
Workers* w = Workers_create(njobs,
|
|
|
|
jq,
|
|
|
|
walloc,
|
|
|
|
worker,
|
|
|
|
wfree,
|
|
|
|
(void*) 101);
|
2018-02-09 10:56:49 +00:00
|
|
|
dbgassert(jq,NULLPTRDEREF);
|
2018-01-29 15:14:50 +00:00
|
|
|
|
|
|
|
for(us i=0; i< njobs; i++) {
|
|
|
|
iVARTRACE(15,i);
|
|
|
|
JobQueue_push(jq,(void*) i+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
JobQueue_wait_alldone(jq);
|
|
|
|
Workers_free(w);
|
|
|
|
JobQueue_free(jq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static void* walloc(void* data) {
|
|
|
|
TRACE(15,"WALLOC");
|
2018-02-06 11:01:27 +00:00
|
|
|
uVARTRACE(15,(us) data);
|
|
|
|
return (void*) 1;
|
2018-01-29 15:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int worker(void* w_data,void* tj) {
|
|
|
|
|
|
|
|
TRACE(15,"worker");
|
|
|
|
|
|
|
|
sleep(4);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
static void wfree(void* w_data) {
|
|
|
|
TRACE(15,"wfree");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|