lasp/test/test_workers.c

80 lines
1.5 KiB
C
Raw Normal View History

2018-01-29 15:14:50 +00:00
// test_bf.c
//
// Author: J.A. de Jong -ASCEE
//
// Description:
//
//////////////////////////////////////////////////////////////////////
#include "lasp_config.h"
#include "lasp_tracer.h"
#include "lasp_assert.h"
#include <unistd.h>
#ifdef LASP_PARALLEL
#include "lasp_worker.h"
#include "lasp_mq.h"
2018-01-29 15:14:50 +00:00
static void* walloc(void*);
static int worker(void*,void*);
static void wfree(void*);
#endif // LASP_PARALLEL
2018-01-29 15:14:50 +00:00
int main() {
fsTRACE(15);
iVARTRACE(15,getTracerLevel());
#ifdef LASP_PARALLEL
us njobs = 4;
2018-01-29 15:14:50 +00:00
JobQueue* jq = JobQueue_alloc(njobs);
dbgassert(jq,NULLPTRDEREF);
2018-01-29 15:14:50 +00:00
Workers* w = Workers_create(njobs,
jq,
walloc,
worker,
wfree,
(void*) 101);
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);
#endif // LASP_PARALLEL
2018-01-29 15:14:50 +00:00
return 0;
}
#ifdef LASP_PARALLEL
2018-01-29 15:14:50 +00:00
static void* walloc(void* data) {
TRACE(15,"WALLOC");
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");
}
#endif // LASP_PARALLEL
2018-01-29 15:14:50 +00:00
//////////////////////////////////////////////////////////////////////