예제 #1
0
static __inline int proc_wait_unthreaded (zbar_processor_t *proc,
                                        proc_waiter_t *waiter,
                                        zbar_timer_t *timeout)
{
	int blocking = 0;// proc->streaming && zbar_video_get_fd(proc->video) < 0;
    _zbar_mutex_unlock(&proc->mutex);

    int rc = 1;
    while(rc > 0 && (waiter->events & EVENTS_PENDING)) {
        /* FIXME lax w/the locking (though shouldn't matter...) */
        //if(blocking) {
        //    zbar_image_t *img = zbar_video_next_image(proc->video);
        //    if(!img) {
        //        rc = -1;
        //        break;
        //    }

            /* FIXME reacquire API lock! (refactor w/video thread?) */
        //    _zbar_mutex_lock(&proc->mutex);
        //    _zbar_process_image(proc, img);
        //    zbar_image_destroy(img);
        //    _zbar_mutex_unlock(&proc->mutex);
        //}
        int reltime = _zbar_timer_check(timeout);
        if(blocking && (reltime < 0 || reltime > MAX_INPUT_BLOCK))
            reltime = MAX_INPUT_BLOCK;
        rc = _zbar_processor_input_wait(proc, NULL, reltime);
    }
    _zbar_mutex_lock(&proc->mutex);
    return(rc);
}
예제 #2
0
/* lock must be held */
int _zbar_event_wait (zbar_event_t *event,
                      zbar_mutex_t *lock,
                      zbar_timer_t *timeout)
{
    if(lock)
        _zbar_mutex_unlock(lock);
    int rc = WaitForSingleObject(*event, _zbar_timer_check(timeout));
    if(lock)
        _zbar_mutex_lock(lock);

    if(!rc)
        return(1); /* got event */
    if(rc == WAIT_TIMEOUT)
        return(0); /* timed out */
    return(-1); /* error (FIXME save info) */
}
예제 #3
0
int _zbar_event_wait (zbar_event_t *event,
                      zbar_mutex_t *lock,
                      zbar_timer_t *timeout)
{
    int rc = !event->state;
    if(rc) {
        if(!timeout)
            /* FIXME was that error or hang? */
            return(-1);

        int _sleep = _zbar_timer_check(timeout);
        if(_sleep)
            proc_sleep(_sleep);
    }

    rc = !event->state;

    /* consume/reset event */
    event->state = 0;

    return(rc);
}