int _zbar_thread_start (zbar_thread_t *thr, zbar_thread_proc_t *proc, void *arg, zbar_mutex_t *lock) { HANDLE hthr; int rc; if(thr->started || thr->running) return(-1/*FIXME*/); thr->started = 1; _zbar_event_init(&thr->notify); _zbar_event_init(&thr->activity); hthr = CreateThread(NULL, 0, proc, arg, 0, NULL); rc = (!hthr || _zbar_event_wait(&thr->activity, NULL, NULL) < 0 || !thr->running); CloseHandle(hthr); if(rc) { thr->started = 0; _zbar_event_destroy(&thr->notify); _zbar_event_destroy(&thr->activity); return(-1/*FIXME*/); } return(0); }
int _zbar_thread_stop (zbar_thread_t *thr, zbar_mutex_t *lock) { if(thr->started) { thr->started = 0; _zbar_event_trigger(&thr->notify); while(thr->running) /* FIXME time out and abandon? */ _zbar_event_wait(&thr->activity, lock, NULL); _zbar_event_destroy(&thr->notify); _zbar_event_destroy(&thr->activity); } return(0); }
void zbar_processor_destroy (zbar_processor_t *proc) { proc_waiter_t *w, *next; zbar_processor_init(proc, NULL, 0); if(proc->scanner) { zbar_image_scanner_destroy(proc->scanner); proc->scanner = NULL; } _zbar_mutex_destroy(&proc->mutex); _zbar_processor_cleanup(proc); assert(!proc->wait_head); assert(!proc->wait_tail); assert(!proc->wait_next); for(w = proc->free_waiter; w; w = next) { next = w->next; _zbar_event_destroy(&w->notify); free(w); } err_cleanup(&proc->err); free(proc); }