Exemplo n.º 1
0
static Timer *new_timer( const char *name )
{
	Timer *timer;

	SET_SEGV_LOCATION();
	if( list_isfull( timerlist ) )
	{
		nlog( LOG_WARNING, "new_timer: timer hash is full" );
		return NULL;
	}
	dlog( DEBUG2, "new_timer: %s", name );
	timer = ns_calloc( sizeof( Timer ) );
	strlcpy( timer->name, name, MAX_MOD_NAME );
	return timer;
}
Exemplo n.º 2
0
void enqueue(queue_t *q, void* data)
{
    lnode_t *n = lnode_create(data);
    
    pthread_mutex_lock(&q->lock);
    
    if (list_isfull(q->list)) {
        pthread_cond_wait(&q->notfull, &q->lock);
    }
    
    if (list_isempty(q->list)) {
        list_append(q->list, n);
        pthread_cond_broadcast(&q->notempty);
    }
    
    pthread_mutex_unlock(&q->lock);
}
Exemplo n.º 3
0
void* dequeue(queue_t *q)
{
    lnode_t *n;
    pthread_mutex_lock(&q->lock);
    
    if (list_isempty(q->list)) {
        pthread_cond_wait(&q->notempty, &q->lock);
    }
    
    if (list_isfull(q->list)) {
        n = list_del_first(q->list);
        pthread_cond_broadcast(&q->notfull);
    }
    else {
        n = list_del_first(q->list);
    }
    
    pthread_mutex_unlock(&q->lock);
    
    return lnode_get(n);
}