Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
int  rtp_timer_start    (RTP_TIMER* newJob, 
                         void (*fn)(int,void*), 
                         void* data, 
                         long msecInterval,
                         unsigned long repeat)
{
	newJob->scheduledTimeMsec = msecInterval;
	newJob->timerFunction = fn;
	newJob->timerData = data;
	newJob->repeat = repeat;

	if (rtp_sig_mutex_claim(rtpTimerLock) >= 0)
	{		
		DLLIST_INSERT_BEFORE(&rtpTimerNewList, newJob);
		
		newJob->listId = RTP_TIMER_LIST_NEW;
		
		if (!rtpTimerThreadAwake)
		{
			rtpTimerThreadAwake = 1;
			rtp_sig_semaphore_signal(rtpTimerSignal);
		}

		rtp_sig_mutex_release(rtpTimerLock);
		
		return (0);
	}
	
	return (-1);
}
Ejemplo n.º 2
0
/*---------------------------------------------------------------------------*/
int rtp_queue_put (RTPMessageQueue *queue, void *message)
{
	if (rtp_sig_mutex_claim(queue->lock) < 0)
	{
		return (-1);
	}
	
	/* make sure the queue is not full */
	if ((queue->last + 1) % queue->queueSize == queue->first)
	{
		rtp_sig_mutex_release(queue->lock);	
		return (-1);
	}
		
	tc_memcpy(&queue->messages[queue->last * queue->msgSize], (char *) message, queue->msgSize);

	queue->last = (queue->last + 1) % queue->queueSize;
		
	rtp_sig_semaphore_signal(queue->sem);
	rtp_sig_mutex_release(queue->lock);
	
	return (0);
}
Ejemplo n.º 3
0
/*---------------------------------------------------------------------------*/
int rtp_helper_thread_queue_job (
		RTP_HELPER_THREAD_CTX* ctx,
		RTP_HELPER_THREAD_JOB* job
	)
{
	rtp_sig_mutex_claim(ctx->mutex);	
	
	if (ctx->lastJob)
	{
		ctx->lastJob->next = job;		
	}	
	else
	{
		ctx->firstJob = job;
	}
	job->next = 0;
	ctx->lastJob = job;
	rtp_sig_semaphore_signal(ctx->signal);	
	
	rtp_sig_mutex_release(ctx->mutex);

	return (0);
}
Ejemplo n.º 4
0
/*---------------------------------------------------------------------------*/
int  rtp_timer_stop    (RTP_TIMER* timer)
{
	int result = -1;
	
	rtp_sig_mutex_claim(rtpTimerLock);
	
	switch (timer->listId)
	{
		case RTP_TIMER_LIST_NONE:
			break;

		case RTP_TIMER_LIST_ACTIVE:
			if (rtpTimerNextToProcess == timer)
			{
				rtpTimerNextToProcess = timer->next;
			}
			/* intentional fall-through */
			
		case RTP_TIMER_LIST_NEW:
			DLLIST_REMOVE(timer);
			DLLIST_INIT(timer);
			timer->listId = RTP_TIMER_LIST_NONE;
			result = 0;

			if (!rtpTimerThreadAwake)
			{
				rtpTimerThreadAwake = 1;
				rtp_sig_semaphore_signal(rtpTimerSignal);		
			}
			break;
	}
	
	rtp_sig_mutex_release(rtpTimerLock);
		
	return (result);
}