C++ (Cpp) pthread_mutex_unlock Examples

C++ (Cpp) pthread_mutex_unlock - 30 examples found. These are the top rated real world C++ (Cpp) examples of pthread_mutex_unlock extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
//async thread start here
void * async_thread_start(void *d)
{
    stone_async_thread *a = d;
    opool_iter *iter, *head;
    stone_async_t *a_t;
    void *temp;
    pthread_cleanup_push(async_thread_destroy, a);
    while(1) {
        pthread_mutex_lock(&a->lock);
        iter = opool_requestAll(a->que);
        if(iter == NULL) {
            pthread_mutex_unlock(&a->lock);
            sleep(60);
            continue;
        }
        //exchange use and back
        temp = a->use;
        a->use = a->back;
        a->back  = temp;
        pthread_mutex_unlock(&a->lock);
        head = iter;//store head to release
        //now deal with que
        while(iter) {
            a_t = iter->data;
            a_t->fn(a_t->fd, a_t->data);
            iter = iter->next;
        }
        //after all, reset pool and return all to que
        ngx_reset_pool(a->back);
        opool_releaseAll(a->que, head);
    }
    pthread_cleanup_pop(0);
}
Example #2
0
/*
 * Write the message into log file according to different level.
 */
void
debug_print(FILE *out, int level, const char *fmt, ...)
{
    va_list ap;

    if (level <= s_debuglevel) {
        if (out == NULL) {
            if (s_logfile != NULL) {
                (void) pthread_mutex_lock(&s_debug_ctl.mutex);
                (void) fprintf(s_logfile,
                               "%"PRIu64": ", current_ms() / 1000);
                va_start(ap, fmt);
                (void) vfprintf(s_logfile, fmt, ap);
                va_end(ap);
                (void) fflush(s_logfile);
                (void) pthread_mutex_unlock(
                    &s_debug_ctl.mutex);
            }
        } else {
            (void) pthread_mutex_lock(&s_debug_ctl.mutex);
            (void) fprintf(out,
                           "%"PRIu64": ", current_ms() / 1000);
            va_start(ap, fmt);
            (void) vfprintf(out, fmt, ap);
            va_end(ap);
            (void) fflush(out);
            (void) pthread_mutex_unlock(&s_debug_ctl.mutex);
        }
    }
}
Example #3
0
static void * work (void * voidptr) {
    Worker * worker = voidptr;
    int wid = worker - workers;
    LGL * lgl = worker->lgl;
    assert (0 <= wid && wid < nworkers);
    msg (wid, 1, "running");
    assert (workers <= worker && worker < workers + nworkers);
    worker->res = lglsat (lgl);
    msg (wid, 1, "result %d", worker->res);
    if (pthread_mutex_lock (&donemutex))
        warn ("failed to lock 'done' mutex in worker");
    done = 1;
    if (pthread_mutex_unlock (&donemutex))
        warn ("failed to unlock 'done' mutex in worker");
    msg (wid, 2, "%d decisions, %d conflicts, %.0f props, %.1f MB",
         lglgetdecs (lgl), lglgetconfs (lgl), lglgetprops (lgl), lglmb (lgl));
    if (verbose >= 2) {
        if (pthread_mutex_lock (&fixedmutex))
            warn ("failed to lock 'fixed' in work");
        msg (wid, 2, "consumed %d units %.0f%%, produced %d units %.0f%%",
             worker->consumed, percent (worker->consumed, nfixed),
             worker->produced, percent (worker->produced, nfixed));
        if (pthread_mutex_unlock (&fixedmutex))
            warn ("failed to unlock 'fixed' in work");
    }
    return worker->res ? worker : 0;
}
void *llegada_reno(void *param) {

    while (1) {
#ifndef NOSLEEP
        sleep(1 * random() % 5);
#endif
        pthread_mutex_lock(&santa_duerme);
        pthread_mutex_lock(&sala_espera_m);
        if (sala_espera < MAX_RENOS) {
            sala_espera++;
            printf("Llega reno... Total: %d\n", sala_espera);
            if (sala_espera == MAX_RENOS) {
                //Esta la sala llena con todos los renos?
                pthread_mutex_unlock(&sala_espera_m);
                printf("todos renos, repartimos!\n");
                pthread_cond_signal(&santa_libre);
                pthread_cond_wait(&sala_espera_cond, &santa_duerme);
            } else {
                //no? Desbloqueamos variables
                pthread_mutex_unlock(&sala_espera_m);
                pthread_cond_wait(&sala_espera_cond, &santa_duerme);
            }
        } else {
            pthread_mutex_unlock(&sala_espera_m);
        }
        pthread_mutex_unlock(&santa_duerme);
    }
}
Example #5
0
/*!
  Signal the event.
  The behaviour of this message is influenced by the broadcast flag, if this
  is a broadcast event then the event will be signaled to all the waiting
  threads otherwise only one thread will be signaled.
  \param id The calling thread id.
 */
int Event::signal (u_long id)
{
    if (!initialized)
        return -1;

#ifdef HAVE_PTHREAD
    if (broadcast)
    {
        pthread_mutex_lock (&mutex);
        pthread_cond_broadcast (&event);
        pthread_mutex_unlock (&mutex);
    }
    else
    {
        pthread_mutex_lock (&mutex);
        pthread_cond_signal (&event);
        pthread_mutex_unlock (&mutex);
    }
#else
    SetEvent (event);

    /* Reset the event for later reusability.  */
    ResetEvent (event);

#endif
    return 0;
}
Example #6
0
//************************************************************************//
//* free memory allocated from the av heap.
//************************************************************************//
void av_heap_free(void* vaddr)
{
    int            block_idx;
    unsigned char* paddr;
    int            offset;

    if(heap_ctx == NULL)
    {
        loge("av heap not initialized yet.");
        return;
    }

    pthread_mutex_lock(&heap_ctx->mutex);

    block_idx = av_heap_find_block_by_vaddr(heap_ctx, vaddr);
    if(block_idx < 0)
    {
        loge("can not find a block of specific virtual address %x.", vaddr);
        pthread_mutex_unlock(&heap_ctx->mutex);
        return;
    }

    paddr  = (unsigned char*)heap_ctx->block_info[block_idx].paddr;
    offset = (int)(paddr - (heap_ctx->env_info.phymem_start & 0x3fffffff));

    munmap(heap_ctx->block_info[block_idx].vaddr, heap_ctx->block_info[block_idx].size);

    allocator_free(heap_ctx->allocator, offset);

    memset(&heap_ctx->block_info[block_idx], 0, sizeof(block_info_t));

    pthread_mutex_unlock(&heap_ctx->mutex);

    return;
}