src/lib/ctx.c
changeset 21 47f15166e25a
parent 20 f0d1011e8874
child 33 0ed40e11b0e8
equal deleted inserted replaced
20:f0d1011e8874 21:47f15166e25a
     4 #include <stdlib.h>
     4 #include <stdlib.h>
     5 #include <signal.h>
     5 #include <signal.h>
     6 #include <assert.h>
     6 #include <assert.h>
     7 #include <stdio.h> // for perror
     7 #include <stdio.h> // for perror
     8 
     8 
       
     9 /**
       
    10  * Wrapper around pthread_mutex_unlock for use with pthread_cleanup_push
       
    11  */
     9 static void pt_mutex_unlock (void *arg)
    12 static void pt_mutex_unlock (void *arg)
    10 {
    13 {
    11     pthread_mutex_t *mutex = arg;
    14     pthread_mutex_t *mutex = arg;
    12 
    15 
    13     assert(!pthread_mutex_unlock(mutex));
    16     assert(!pthread_mutex_unlock(mutex));
   224 int pt_ctx_work (struct pt_ctx *ctx, pt_work_func func, void *arg)
   227 int pt_ctx_work (struct pt_ctx *ctx, pt_work_func func, void *arg)
   225 {
   228 {
   226     struct pt_work *work;
   229     struct pt_work *work;
   227 
   230 
   228     // check state
   231     // check state
       
   232     // XXX: this is kind of retarded, because pt_ctx_shutdown/work should only be called from the same thread...
   229     if (!ctx->running)
   233     if (!ctx->running)
   230         RETURN_ERROR(PT_ERR_CTX_SHUTDOWN);
   234         RETURN_ERROR(PT_ERR_CTX_SHUTDOWN);
   231 
   235 
   232     // construct
   236     // alloc
   233     if ((work = calloc(1, sizeof(*work))) == NULL)
   237     if ((work = calloc(1, sizeof(*work))) == NULL)
   234         RETURN_ERROR(PT_ERR_MEM);
   238         RETURN_ERROR(PT_ERR_MEM);
   235 
   239 
   236     // init
   240     // init
   237     work->func = func;
   241     work->func = func;