Пример #1
0
int start_native_gui(wxe_data *sd)
{
  int res;
  wxe_status_m = erl_drv_mutex_create((char *) "wxe_status_m");
  wxe_status_c = erl_drv_cond_create((char *)"wxe_status_c");

  wxe_batch_locker_m = erl_drv_mutex_create((char *)"wxe_batch_locker_m");
  wxe_batch_locker_c = erl_drv_cond_create((char *)"wxe_batch_locker_c");
  init_caller = driver_connected(sd->port); 

  if((res = erl_drv_thread_create((char *)"wxwidgets",
				  &wxe_thread,wxe_main_loop,(void *) sd->pdl,NULL)) == 0) {
    erl_drv_mutex_lock(wxe_status_m);
    for(;wxe_status == WXE_NOT_INITIATED;) {
      erl_drv_cond_wait(wxe_status_c, wxe_status_m);
    }
    erl_drv_mutex_unlock(wxe_status_m);
    return wxe_status;
  } else {
    wxString msg;
    msg.Printf(wxT("Erlang failed to create wxe-thread %d\r\n"), res);
    send_msg("error", &msg);
    return -1;
  }
}
Пример #2
0
int start_native_gui(wxe_data *sd)
{
  int res;
  wxe_status_m = erl_drv_mutex_create((char *) "wxe_status_m");
  wxe_status_c = erl_drv_cond_create((char *)"wxe_status_c");

  wxe_batch_locker_m = erl_drv_mutex_create((char *)"wxe_batch_locker_m");
  wxe_batch_locker_c = erl_drv_cond_create((char *)"wxe_batch_locker_c");
  init_caller = driver_connected(sd->port_handle);

#ifdef __DARWIN__
  res = erl_drv_steal_main_thread((char *)"wxwidgets",
				  &wxe_thread,wxe_main_loop,(void *) sd->pdl,NULL);
#else
  ErlDrvThreadOpts *opts = erl_drv_thread_opts_create((char *)"wx thread");
  opts->suggested_stack_size = 8192;
  res = erl_drv_thread_create((char *)"wxwidgets",
			      &wxe_thread,wxe_main_loop,(void *) sd->pdl,opts);
  erl_drv_thread_opts_destroy(opts);
#endif
  if(res == 0) {
    erl_drv_mutex_lock(wxe_status_m);
    for(;wxe_status == WXE_NOT_INITIATED;) {
      erl_drv_cond_wait(wxe_status_c, wxe_status_m);
    }
    erl_drv_mutex_unlock(wxe_status_m);
    return wxe_status;
  } else {
    wxString msg;
    msg.Printf(wxT("Erlang failed to create wxe-thread %d\r\n"), res);
    send_msg("error", &msg);
    return -1;
  }
}
Пример #3
0
TPool* bdberl_tpool_start(unsigned int thread_count)
{
    TPool* tpool = driver_alloc(sizeof(TPool));
    memset(tpool, '\0', sizeof(TPool));

    // Initialize lock, cv, etc.
    tpool->lock         = erl_drv_mutex_create("bdberl_tpool_lock");
    tpool->work_cv      = erl_drv_cond_create("bdberl_tpool_work_cv");
    tpool->cancel_cv    = erl_drv_cond_create("bdberl_tpool_cancel_cv");
    tpool->threads      = driver_alloc(sizeof(ErlDrvTid) * thread_count);
    tpool->thread_count = thread_count;

    // Startup all the threads
    int i;
    for (i = 0; i < thread_count; i++)
    {
        // TODO: Figure out good way to deal with errors in this situation (should be rare, but still...)
        erl_drv_thread_create("bdberl_tpool_thread", &(tpool->threads[i]), &bdberl_tpool_main, (void*)tpool, 0);
    }

    return tpool;
}
Пример #4
0
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;
    }
}
Пример #5
0
ErlNifCond* enif_cond_create(char *name) { return erl_drv_cond_create(name); }
Пример #6
0
erl_cond_t
erts_cond_create(void)
{
    return (erl_cond_t) erl_drv_cond_create(NULL);
}