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); }
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); }
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); }
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); }
static ErlDrvData innostore_drv_start(ErlDrvPort port, char* buffer) { PortState* state = (PortState*)driver_alloc(sizeof(PortState)); int worker_rc; memset(state, '\0', sizeof(PortState)); // Save handle to the port state->port = port; // Save the owner PID state->port_owner = driver_connected(port); // Initialize in the READY state state->port_state = STATE_READY; // Make sure port is running in binary mode set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY); // Allocate a mutex and condition variable for the worker state->worker_lock = erl_drv_mutex_create("innostore_worker_lock"); state->worker_cv = erl_drv_cond_create("innostore_worker_cv"); // Spin up the worker worker_rc = erl_drv_thread_create("innostore_worker", &(state->worker), &innostore_worker, state, 0); if (state->worker_lock != NULL && state->worker_cv != NULL && worker_rc == 0) { return (ErlDrvData)state; } else { log("Innostore: Could not create port [lock=%p, cv=%p]\n", state->worker_lock, state->worker_cv); if (state->worker_cv != NULL) erl_drv_cond_destroy(state->worker_cv); if (state->worker_lock != NULL) erl_drv_mutex_destroy(state->worker_lock); driver_free(state); errno = worker_rc; return (ErlDrvData) ERL_DRV_ERROR_ERRNO; } }
void enif_cond_destroy(ErlNifCond *cnd) { erl_drv_cond_destroy(cnd); }
int erts_cond_destroy(erl_cond_t cnd) { erl_drv_cond_destroy((ErlDrvCond *) cnd); return 0; }