Beispiel #1
0
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);
}
Beispiel #2
0
static __inline proc_waiter_t *proc_waiter_queue (zbar_processor_t *proc)
{
    proc_waiter_t *waiter = proc->free_waiter;
    if(waiter) {
        proc->free_waiter = waiter->next;
        waiter->events = 0;
    }
    else {
        waiter = calloc(1, sizeof(proc_waiter_t));
        _zbar_event_init(&waiter->notify);
    }

    waiter->next = NULL;
    waiter->requester = _zbar_thread_self();

    if(proc->wait_head)
        proc->wait_tail->next = waiter;
    else
        proc->wait_head = waiter;
    proc->wait_tail = waiter;
    return(waiter);
}