mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-16 22:38:38 +00:00
Implement switch_queue_pop_timeout() and refactor sofia_profile_worker_thread_run() to use it so it doesn't wake up too often
This commit is contained in:
1 parent
42a4a3dedf
commit
de417e99f0
6 files changed
+148
-46
No files matched your search
@@ -1 +1 @@
|
||||
Mon Dec 28 14:55:57 EST 2009
|
||||
Thu 18 Nov 2010 20:56:38 EST
|
||||
@@ -78,6 +78,22 @@ APU_DECLARE(apr_status_t) apr_queue_push(apr_queue_t *queue, void *data);
|
||||
*/
|
||||
APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data);
|
||||
|
||||
/**
|
||||
* pop/get an object from the queue, blocking if the queue is already empty
|
||||
*
|
||||
* @param queue the queue
|
||||
* @param data the data
|
||||
* @param timeout The amount of time in microseconds to wait. This is
|
||||
* a maximum, not a minimum. If the condition is signaled, we
|
||||
* will wake up before this time, otherwise the error APR_TIMEUP
|
||||
* is returned.
|
||||
* @returns APR_TIMEUP the request timed out
|
||||
* @returns APR_EINTR the blocking was interrupted (try again)
|
||||
* @returns APR_EOF if the queue has been terminated
|
||||
* @returns APR_SUCCESS on a successfull pop
|
||||
*/
|
||||
APU_DECLARE(apr_status_t) apr_queue_pop_timeout(apr_queue_t *queue, void **data, apr_interval_time_t timeout);
|
||||
|
||||
/**
|
||||
* push/add a object to the queue, returning immediatly if the queue is full
|
||||
*
|
||||
|
||||
@@ -313,6 +313,71 @@ APU_DECLARE(apr_status_t) apr_queue_pop(apr_queue_t *queue, void **data)
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the next item from the queue. If there are no
|
||||
* items available, it will block until one becomes available, or
|
||||
* until timeout is elapsed. Once retrieved, the item is placed into
|
||||
* the address specified by'data'.
|
||||
*/
|
||||
APU_DECLARE(apr_status_t) apr_queue_pop_timeout(apr_queue_t *queue, void **data, apr_interval_time_t timeout)
|
||||
{
|
||||
apr_status_t rv;
|
||||
|
||||
if (queue->terminated) {
|
||||
return APR_EOF; /* no more elements ever again */
|
||||
}
|
||||
|
||||
rv = apr_thread_mutex_lock(queue->one_big_mutex);
|
||||
if (rv != APR_SUCCESS) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Keep waiting until we wake up and find that the queue is not empty. */
|
||||
if (apr_queue_empty(queue)) {
|
||||
if (!queue->terminated) {
|
||||
queue->empty_waiters++;
|
||||
rv = apr_thread_cond_timedwait(queue->not_empty, queue->one_big_mutex, timeout);
|
||||
queue->empty_waiters--;
|
||||
/* In the event of a timemout, APR_TIMEUP will be returned */
|
||||
if (rv != APR_SUCCESS) {
|
||||
apr_thread_mutex_unlock(queue->one_big_mutex);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
/* If we wake up and it's still empty, then we were interrupted */
|
||||
if (apr_queue_empty(queue)) {
|
||||
Q_DBG("queue empty (intr)", queue);
|
||||
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
|
||||
if (rv != APR_SUCCESS) {
|
||||
return rv;
|
||||
}
|
||||
if (queue->terminated) {
|
||||
return APR_EOF; /* no more elements ever again */
|
||||
}
|
||||
else {
|
||||
return APR_EINTR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*data = queue->data[queue->out];
|
||||
queue->nelts--;
|
||||
|
||||
queue->out = (queue->out + 1) % queue->bounds;
|
||||
if (queue->full_waiters) {
|
||||
Q_DBG("signal !full", queue);
|
||||
rv = apr_thread_cond_signal(queue->not_full);
|
||||
if (rv != APR_SUCCESS) {
|
||||
apr_thread_mutex_unlock(queue->one_big_mutex);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
rv = apr_thread_mutex_unlock(queue->one_big_mutex);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the next item from the queue. If there are no
|
||||
* items available, return APR_EAGAIN. Once retrieved,
|
||||
|
||||
Reference in new issue
Block a user