コード例 #1
0
static void* pausing_thread (void* data)
{
    gu_info ("pausing_thread start, pause_order = %d", pause_order);
    gcs_sm_t* sm = (gcs_sm_t*)data;

    gu_cond_t cond;
    gu_cond_init (&cond, NULL);

    gcs_sm_schedule (sm);
    gu_info ("pausing_thread scheduled, pause_order = %d", pause_order);
    fail_if (pause_order != 0, "pause_order = %d, expected 0");
    pause_order = 1;
    gcs_sm_enter (sm, &cond, true);
    gu_info ("pausing_thread entered, pause_order = %d", pause_order);
    fail_if (pause_order != 2, "pause_order = %d, expected 2");
    pause_order = 3;
    usleep(TEST_USLEEP);
    gcs_sm_leave (sm);

    mark_point();
    gu_cond_destroy(&cond);

    gu_info ("pausing_thread exit, pause_order = %d", pause_order);
    return NULL;
}
コード例 #2
0
 ~Cond ()
 {
     int ret;
     while (EBUSY == (ret = gu_cond_destroy(&cond)))
         { usleep (100); }
     if (gu_unlikely(ret != 0))
     {
         log_fatal << "gu_cond_destroy() failed: " << ret
                   << " (" << strerror(ret) << ". Aborting.";
         ::abort();
     }
 }
コード例 #3
0
static void* simple_thread(void* arg)
{
    gcs_sm_t* sm = (gcs_sm_t*) arg;

    gu_cond_t cond;
    gu_cond_init (&cond, NULL);

    if (0 == (simple_ret = gcs_sm_enter (sm, &cond, false))) {
        usleep(1000);
        gcs_sm_leave (sm);
    }

    gu_cond_destroy (&cond);

    return NULL;
}
コード例 #4
0
ファイル: gu_to.c プロジェクト: latinovic/galera
long gu_to_destroy (gu_to_t** to)
{
    gu_to_t *t = *to;
    long      ret;
    ssize_t    i;

    gu_mutex_lock (&t->lock);
    if (t->used) {
        gu_mutex_unlock (&t->lock);
        return -EBUSY;
    }
    
    for (i = 0; i < t->qlen; i++) {
        to_waiter_t *w = t->queue + i;
#ifdef TO_USE_SIGNAL
        if (gu_cond_destroy (&w->cond)) {
            // @todo: what if someone is waiting?
            gu_warn ("Failed to destroy condition %d. Should not happen", i);
        }
#else
        if (pthread_mutex_destroy (&w->mtx)) {
            // @todo: what if someone is waiting?
            gu_warn ("Failed to destroy mutex %d. Should not happen", i);
        }
#endif
    }    
    t->qlen = 0;
    
    gu_mutex_unlock (&t->lock);
    /* What else can be done here? */
    ret = gu_mutex_destroy (&t->lock);
    if (ret) return -ret; // application can retry

    gu_free (t->queue);
    gu_free (t);
    *to = NULL;
    return 0;
}
コード例 #5
0
long
gcs_sm_close (gcs_sm_t* sm)
{
    gu_info ("Closing send monitor...");

    if (gu_unlikely(gu_mutex_lock (&sm->lock))) abort();

    sm->ret = -EBADFD;

    if (sm->pause) _gcs_sm_continue_common (sm);

    gu_cond_t cond;
    gu_cond_init (&cond, NULL);

    // in case the queue is full
    while (sm->users >= (long)sm->wait_q_len) {
        gu_mutex_unlock (&sm->lock);
        usleep(1000);
        gu_mutex_lock (&sm->lock);
    }

    while (sm->users > 0) { // wait for cleared queue
        sm->users++;
        GCS_SM_INCREMENT(sm->wait_q_tail);
        _gcs_sm_enqueue_common (sm, &cond);
        sm->users--;
        GCS_SM_INCREMENT(sm->wait_q_head);
    }

    gu_cond_destroy (&cond);

    gu_mutex_unlock (&sm->lock);

    gu_info ("Closed send monitor.");

    return 0;
}