Пример #1
0
int
sbevent_wait(sbevent_t *evt, int sec, int nsec)
{
    DWORD rv;

    rv = cond_timed_wait(evt->evt, sec, nsec);
    return rv;
}
Пример #2
0
void *
sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec)
{
    char *outptr;
    size_t len;

    /* Lock the condition variable while we manipulate nmsg. */
    pthread_mutex_lock(&q->mtx);
    if (q->nbytes == 0) {
        /* Unlock the condition variable and wait for a signal. */
        if (cond_timed_wait(&q->cond, &q->mtx, sec, nsec) != 0) {
            /* Timed out or something... */
            pthread_mutex_unlock(&q->mtx);
            return NULL;
        }
        /* Condition variable is now locked again. */
    }
    /* Get the message size. */
    if (q->out + sizeof(q->msglen) > q->depth) {
        /* Handle annoying wraparound case. */
        size_t len1 = q->depth - q->out;
        memcpy(&q->msglen, q->data + q->out, len1);
        memcpy(((char *)&q->msglen) + len1, q->data,
               sizeof(q->msglen) - len1);
        q->out = sizeof(q->msglen) - len1;
    }
    else {
        memcpy(&q->msglen, q->data + q->out, sizeof(q->msglen));
        q->out += sizeof(q->msglen);
    }
    q->nbytes -= sizeof(q->msglen);
    /* Get the message body. */
    outptr = q->msg;
    len = q->msglen;
    if (q->out + q->msglen > q->depth) {
        /* Handle wraparound. */
        size_t len1 = q->depth - q->out;
        memcpy(outptr, q->data + q->out, len1);
        outptr += len1;
        len -= len1;
        q->nbytes -= len1;
        q->out = 0;
    }
    memcpy(outptr, q->data + q->out, len);
    q->nbytes -= len;
    q->out += len;

    /* Signal the condition variable. */
    pthread_cond_signal(&q->cond);
    /* Unlock the condition variable, we are done. */
    pthread_mutex_unlock(&q->mtx);
    if (out_len)
        *out_len = q->msglen;
    return q->msg;
}
Пример #3
0
void *
sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec)
{
    char *outptr;
    size_t len;

    /* Wait for data to be available. */
    if (q->nbytes == 0) {
        if (cond_timed_wait(q->evt, sec, nsec) == WAIT_FAILED)
            /* Timed out or something... */
            return NULL;
    }
    /* Lock to manipulate the queue (FIXME) */
    EnterCriticalSection(&q->mtx);
    /* Get the message size. */
    if (q->out + sizeof(q->msglen) > q->depth) {
        /* Handle annoying wraparound case. */
        size_t len1 = q->depth - q->out;
        memcpy(&q->msglen, q->data + q->out, len1);
        memcpy(((char *)&q->msglen) + len1, q->data,
               sizeof(q->msglen) - len1);
        q->out = sizeof(q->msglen) - len1;
    }
    else {
        memcpy(&q->msglen, q->data + q->out, sizeof(q->msglen));
        q->out += sizeof(q->msglen);
    }
    q->nbytes -= sizeof(q->msglen);
    /* Get the message body. */
    outptr = q->msg;
    len = q->msglen;
    if (q->out + q->msglen > q->depth) {
        /* Handle wraparound. */
        size_t len1 = q->depth - q->out;
        memcpy(outptr, q->data + q->out, len1);
        outptr += len1;
        len -= len1;
        q->nbytes -= len1;
        q->out = 0;
    }
    memcpy(outptr, q->data + q->out, len);
    q->nbytes -= len;
    q->out += len;

    /* Signal the condition variable. */
    SetEvent(q->evt);
    /* Unlock. */
    LeaveCriticalSection(&q->mtx);
    if (out_len)
        *out_len = q->msglen;
    return q->msg;
}
Пример #4
0
long  CSynchronized::wait(pthread_cond_t *cond,pthread_mutex_t *monitor,long timeout)
{
    struct timespec ts;
    struct timeval  tv;

    long result= VOS_OK ;

    gettimeofday(&tv, 0);
    ts.tv_sec  = tv.tv_sec  + (long)timeout/1000;
    ts.tv_nsec = (tv.tv_usec + (timeout %1000)*1000) * 1000;

    long err;
    if( timeout )
    {
        err = cond_timed_wait(cond,monitor,&ts);
    }
    else
    {
        err = cond_timed_wait(cond,monitor,VOS_NULL);
    }
    if( err  > VOS_OK )
    {
        switch(err)
        {
            case ETIMEDOUT:
                 result = VOS_ERR_QUE_TIMEOUT;
            break;

            default:
                 result = VOS_ERR_SYS;
            break;
        }
    }

    return result;
}
Пример #5
0
int
sbevent_wait(sbevent_t *evt, int sec, int nsec)
{
    int rv = 0;

    /* Lock the mutex before we check its signalled state. */
    pthread_mutex_lock(&evt->mtx);
    /* If it's not signalled, then wait until it is. */
    if (!evt->signalled)
        rv = cond_timed_wait(&evt->cond, &evt->mtx, sec, nsec);
    /* Set its state to unsignalled if we were successful. */
    if (rv == 0)
        evt->signalled = FALSE;
    /* And unlock its mutex. */
    pthread_mutex_unlock(&evt->mtx);

    return rv;
}