예제 #1
0
void bdberl_tpool_stop(TPool* tpool)
{
    LOCK(tpool);

    // Set the shutdown flag and broadcast a notification
    tpool->shutdown = 1;
    erl_drv_cond_broadcast(tpool->work_cv);

    // Clean out the queue of pending jobs -- invoke their cleanup function

    // Wait for until active_threads hits zero
    while (tpool->active_threads > 0)
    {
        erl_drv_cond_wait(tpool->work_cv, tpool->lock);
    }
    
    // Join up with all the workers
    int i = 0;
    for (i = 0; i < tpool->thread_count; i++)
    {
        erl_drv_thread_join(tpool->threads[i], 0);
    }

    // Cleanup 
    erl_drv_cond_destroy(tpool->work_cv);
    erl_drv_cond_destroy(tpool->cancel_cv);
    driver_free(tpool->threads);
    UNLOCK(tpool);
    erl_drv_mutex_destroy(tpool->lock);
    driver_free(tpool);
}
예제 #2
0
static void innostore_drv_stop(ErlDrvData handle)
{
    PortState* state = (PortState*)handle;

    // Grab the worker lock, in case we have an job running
    erl_drv_mutex_lock(state->worker_lock);

    // Signal the shutdown and wait until the current operation has completed
    state->shutdown_flag = 1;
    erl_drv_cond_signal(state->worker_cv);

    while (state->op)
    {
        erl_drv_cond_wait(state->worker_cv, state->worker_lock);
    }

    // If the port state is not marked as READY, close the cursor and abort the txn
    if (state->port_state != STATE_READY)
    {
        ib_cursor_close(state->cursor);
        ib_trx_rollback(state->txn);
    }

    // No pending jobs and we have the lock again -- join our worker thread
    erl_drv_cond_signal(state->worker_cv);
    erl_drv_mutex_unlock(state->worker_lock);
    erl_drv_thread_join(state->worker, 0);

    // Cleanup
    erl_drv_cond_destroy(state->worker_cv);
    erl_drv_mutex_destroy(state->worker_lock);
    driver_free(handle);
}
예제 #3
0
파일: wxe_impl.cpp 프로젝트: AlainODea/otp
void stop_native_gui(wxe_data *sd)
{
  erl_drv_thread_join(wxe_thread, NULL);
  erl_drv_mutex_destroy(wxe_status_m);
  erl_drv_cond_destroy(wxe_status_c);
  erl_drv_mutex_destroy(wxe_batch_locker_m);
  erl_drv_cond_destroy(wxe_batch_locker_c);
}
예제 #4
0
파일: echo_drv.c 프로젝트: HansN/otp
static void echo_drv_stop(EchoDrvData *data_p)
{
    struct my_thread* thr = data_p->threads;

    while (thr) {
        struct my_thread* next = thr->next;
        void* exit_value;
        int ret = erl_drv_thread_join(thr->tid, &exit_value);
        assert(ret == 0 && exit_value == NULL);
        driver_free(thr);
        thr = next;
    }
    driver_free(data_p);
}
예제 #5
0
void stop_native_gui(wxe_data *sd)
{
    if(wxe_status == WXE_INITIATED) {
        meta_command(WXE_SHUTDOWN, sd);
    }
#ifdef __DARWIN__
    erl_drv_stolen_main_thread_join(wxe_thread, NULL);
#else
    erl_drv_thread_join(wxe_thread, NULL);
#endif
    erl_drv_mutex_destroy(wxe_status_m);
    erl_drv_cond_destroy(wxe_status_c);
    erl_drv_mutex_destroy(wxe_batch_locker_m);
    erl_drv_cond_destroy(wxe_batch_locker_c);
}
예제 #6
0
파일: fp_drv.c 프로젝트: gitter-badger/otp
static ErlDrvSSizeT control(ErlDrvData drv_data,
                            unsigned int command,
                            char *buf, ErlDrvSizeT len,
                            char **rbuf, ErlDrvSizeT rlen)
{
    char *res_str;
    PRINTF(("control(%p, %d, ...) called\r\n", drv_data, command));

    switch (command) {
    case ERTS_FP_THREAD_TEST: {
        ErlDrvTid tid;
        ErlDrvSysInfo info;
        driver_system_info(&info, sizeof(ErlDrvSysInfo));
        if (!info.thread_support)
            res_str = "skip: no thread support";
        else if (0 != erl_drv_thread_create("test", &tid, do_test, NULL, NULL))
            res_str = "failed to create thread";
        else if (0 != erl_drv_thread_join(tid, &res_str))
            res_str = "failed to join thread";
        break;
    }
    case ERTS_FP_CONTROL_TEST:
        res_str = do_test(NULL);
        break;
    default:
        res_str = "unknown command";
        break;
    }

done: {
        int res_len = strlen(res_str);
        if (res_len > rlen) {
            char *abuf = driver_alloc(sizeof(char)*res_len);
            if (!abuf)
                return 0;
            *rbuf = abuf;
        }

        memcpy((void *) *rbuf, (void *) res_str, res_len);

        return res_len;
    }
}
예제 #7
0
파일: dthread.c 프로젝트: relabsoss/uart
int dthread_stop(dthread_t* target, dthread_t* source, 
		 void** exit_value)
{
    dmessage_t* mp;
    int r;

    if (!(mp = dmessage_create(DTHREAD_STOP, NULL, 0)))
	return -1;
    dthread_send(target, source, mp);

    DEBUGF("dthread_stop: wait to join");
    r = erl_drv_thread_join(target->tid, exit_value);
    DEBUGF("dthread_stop: thread_join: return=%d, exit_value=%p", r, *exit_value);

    dthread_signal_finish(target, 1);
    dthread_finish(target);
    DFREE(target);
    return 0;
}
예제 #8
0
파일: erl_nif.c 프로젝트: a5an0/otp
int enif_thread_join(ErlNifTid tid, void **respp) { return erl_drv_thread_join(tid,respp); }
예제 #9
0
int
erts_thread_join(erl_thread_t tid, void **respp)
{
    return erl_drv_thread_join((ErlDrvTid) tid, respp);
}