예제 #1
0
static void 
destruct_esqlite_connection(ErlNifEnv *env, void *arg)
{
    esqlite_connection *db = (esqlite_connection *) arg;
    esqlite_command *cmd = command_create();
  
    /* Send the stop command 
     */
    cmd->type = cmd_stop;
    queue_push(db->commands, cmd);
    queue_send(db->commands, cmd);
     
    /* Wait for the thread to finish 
     */
    enif_thread_join(db->tid, NULL);
    enif_thread_opts_destroy(db->opts);
     
    /* The thread has finished... now remove the command queue, and close
     * the datbase (if it was still open).
     */
    queue_destroy(db->commands);

    if(db->db)
	   sqlite3_close(db->db);
}
예제 #2
0
파일: elua.c 프로젝트: indie21/elua
void woker_destory(worker_t *w)
{
    msg_t *msg = msg_create();
    msg->type = msg_stop;
    queue_push(w->q, msg);

    enif_thread_join(w->tid, NULL);
    enif_thread_opts_destroy(w->opts);

    queue_destroy(w->q);
}
예제 #3
0
void
resource_dtor(ErlNifEnv *env, void *obj)
{
    ctx_t  *ctx = static_cast<ctx_t*>(obj);
    task_t *task = init_empty_task(SHUTDOWN);
    void   *result = NULL;

    async_queue_push(ctx->queue, static_cast<void*>(task));
    enif_thread_join(ctx->tid, &result);
    async_queue_destroy(ctx->queue);
    enif_thread_opts_destroy(ctx->topts);
}
예제 #4
0
static void
unload(ErlNifEnv* env, void* priv)
{
    state_t* state = (state_t*) priv;
    void* resp;
    
    queue_push(state->queue, NULL);
    enif_thread_join(state->qthread, &resp);
    queue_destroy(state->queue);

    enif_thread_opts_destroy(state->opts);
    enif_free(state);
}
예제 #5
0
파일: vm.c 프로젝트: alepharchives/emonk
void
vm_destroy(ErlNifEnv* env, void* obj)
{
    vm_ptr vm = (vm_ptr) obj;
    job_ptr job = job_create();
    void* resp;
    
    assert(job != NULL && "Failed to create job.");
    job->type = job_close;
    queue_push(vm->jobs, job);
    queue_send(vm->jobs, job);

    enif_thread_join(vm->tid, &resp);
    
    queue_destroy(vm->jobs);
    enif_thread_opts_destroy(vm->opts);
}
예제 #6
0
파일: elua.c 프로젝트: indie21/elua
int worker_init(worker_t *worker,int id)
{
    struct queue_t *q;
    ErlNifThreadOpts* opts;

    q = queue_create();
    if(q == NULL ) {
        goto queue_error;
    }

    worker->q = q;
    worker->id =id;
    opts = enif_thread_opts_create("lua_thread_opts");

    if(opts == NULL) {
        goto opts_error;
    }

    worker->opts = opts;
    if(enif_thread_create("lua_thread",
                          &worker->tid,
                          worker_run,
                          worker,
                          worker->opts) != 0) {
        goto create_error;
    }

    return 0;

 create_error:
    enif_thread_opts_destroy(opts);
 opts_error:
    queue_destroy(q);
 queue_error:
    return -1;
}