static void threadSafeFree(void *vpt)
/* Wrap mutex lock around free. */
{
pthreadMutexLock(&memMutex);
parentMem->free(vpt);
pthreadMutexUnlock(&memMutex);
}
Ejemplo n.º 2
0
void synQueuePut(struct synQueue *sq, void *message)
/* Add message to end of queue. */
{
pthreadMutexLock(&sq->mutex);
dlAddValTail(sq->queue, message);
pthreadCondSignal(&sq->cond);
pthreadMutexUnlock(&sq->mutex);
}
static void *threadSafeRealloc(void *vpt, size_t size)
/* Wrap mutex lock around realloc. */
{
void *result;
pthreadMutexLock(&memMutex);
result = parentMem->realloc(vpt, size);
pthreadMutexUnlock(&memMutex);
return result;
}
static void *threadSafeAlloc(size_t size)
/* Wrap mutex lock around allocation. */
{
void *result;
pthreadMutexLock(&memMutex);
result = parentMem->alloc(size);
pthreadMutexUnlock(&memMutex);
return result;
}
Ejemplo n.º 5
0
int synQueueSize(struct synQueue *sq)
/* Return number of messages currently on queue. */
{
int size;
pthreadMutexLock(&sq->mutex);
size = dlCount(sq->queue);
pthreadMutexUnlock(&sq->mutex);
return size;
}
Ejemplo n.º 6
0
void *synQueueGet(struct synQueue *sq)
/* Get message off start of queue.  Wait until there is
 * a message if queue is empty. */
{
void *message;
struct dlNode *node;
pthreadMutexLock(&sq->mutex);
while (dlEmpty(sq->queue))
    pthreadCondWait(&sq->cond, &sq->mutex);
node = dlPopHead(sq->queue);
pthreadMutexUnlock(&sq->mutex);
message = node->val;
freeMem(node);
return message;
}
Ejemplo n.º 7
0
void *synQueueGrab(struct synQueue *sq)
/* Get message off start of queue.  Return NULL immediately 
 * if queue is empty. */
{
void *message = NULL;
struct dlNode *node;
pthreadMutexLock(&sq->mutex);
node = dlPopHead(sq->queue);
pthreadMutexUnlock(&sq->mutex);
if (node != NULL)
    {
    message = node->val;
    freeMem(node);
    }
return message;
}