static void taskcomm ( COMM *sio, int type, unsigned millisec ) { switch( type ) { case TASK_INIT : if ( sio->_qCOMM == NULL ) tComm_init(sio) ; return ; case TASK_FINISH : tqueue_free(sio->_qCOMM) ; return ; } if ( _curr_task == NULL || sio->_qCOMM == NULL ) { /* not in TASK */ delay(millisec) ; return ; } if ( type == TASK_WDELAY || type == TASK_RDELAY ) { qCOMM_add(sio,type==TASK_WDELAY?TASK_TX:TASK_RX) ; } task_delay((unsigned long)millisec*128/125) ; /* 1/1024 unit */ }
void timed_testfunc(int nthreads, long nitems) { tqueue_t *q; long i, res, expected; struct tqueue_options opts; memset(&opts, 0, sizeof(opts)); opts.nthreads = nthreads; opts.worker = &ww; q = tqueue_new(&opts); EXPECT(tqueue_get(q, 0) == NULL, "expected NULL result on tqueue_get"); for(i=0; i<nitems; i++) { EXPECT(tqueue_put(q, (void*)(i+1)) == 0, "tqueue_put failure"); } expected = 0; for(i=res=expected=0; i<nitems; i++) { expected += i+2; res += (long)tqueue_get(q, 1); } EXPECT(res == expected, "sum: expected %ld, was %ld", expected, res); tqueue_free(q); }