*------------------------------------------------------------------
* svm_queue.c - unidirectional shared-memory queues
*
- * Copyright (c) 2009 Cisco and/or its affiliates.
+ * Copyright (c) 2009-2019 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
/* Fake a wait for event. We could use epoll but that would mean
* using yet another fd. Should do for now */
u32 cursize = q->cursize;
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
while (q->cursize == cursize)
CLIB_PAUSE ();
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
}
}
u32 cursize = q->cursize;
int rv;
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
while (q->cursize == cursize && unix_time_now () < max_time)
CLIB_PAUSE ();
rv = unix_time_now () < max_time ? 0 : ETIMEDOUT;
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
return rv;
}
}
}
}
else
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
if (PREDICT_FALSE (q->cursize == q->maxsize))
{
if (nowait)
{
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return (-2);
}
while (q->cursize == q->maxsize)
if (need_broadcast)
svm_queue_send_signal (q, 1);
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return 0;
}
}
}
else
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
if (PREDICT_FALSE (q->cursize + 1 == q->maxsize))
{
if (nowait)
{
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return (-2);
}
while (q->cursize + 1 == q->maxsize)
if (need_broadcast)
svm_queue_send_signal (q, 1);
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return 0;
}
}
}
else
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
if (PREDICT_FALSE (q->cursize == 0))
{
if (cond == SVM_Q_NOWAIT)
{
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return (-2);
}
else if (cond == SVM_Q_TIMEDWAIT)
if (rc == ETIMEDOUT)
{
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return ETIMEDOUT;
}
}
if (need_broadcast)
svm_queue_send_signal (q, 0);
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return 0;
}
int need_broadcast;
i8 *headp;
- pthread_mutex_lock (&q->mutex);
+ svm_queue_lock (q);
if (q->cursize == 0)
{
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
return -1;
}
if (PREDICT_FALSE (q->head == q->maxsize))
q->head = 0;
- pthread_mutex_unlock (&q->mutex);
+ svm_queue_unlock (q);
if (need_broadcast)
svm_queue_send_signal (q, 0);