mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-18 23:15:46 -04:00
dep/cubeb: Update to dc511c6
This commit is contained in:
@ -16,8 +16,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
void ** buf;
|
||||
size_t num;
|
||||
size_t writePos;
|
||||
@ -25,10 +24,11 @@ typedef struct
|
||||
pthread_mutex_t mutex;
|
||||
} array_queue;
|
||||
|
||||
array_queue * array_queue_create(size_t num)
|
||||
array_queue *
|
||||
array_queue_create(size_t num)
|
||||
{
|
||||
assert(num != 0);
|
||||
array_queue * new_queue = (array_queue*)calloc(1, sizeof(array_queue));
|
||||
array_queue * new_queue = (array_queue *)calloc(1, sizeof(array_queue));
|
||||
new_queue->buf = (void **)calloc(1, sizeof(void *) * num);
|
||||
new_queue->readPos = 0;
|
||||
new_queue->writePos = 0;
|
||||
@ -39,7 +39,8 @@ array_queue * array_queue_create(size_t num)
|
||||
return new_queue;
|
||||
}
|
||||
|
||||
void array_queue_destroy(array_queue * aq)
|
||||
void
|
||||
array_queue_destroy(array_queue * aq)
|
||||
{
|
||||
assert(aq);
|
||||
|
||||
@ -48,14 +49,14 @@ void array_queue_destroy(array_queue * aq)
|
||||
free(aq);
|
||||
}
|
||||
|
||||
int array_queue_push(array_queue * aq, void * item)
|
||||
int
|
||||
array_queue_push(array_queue * aq, void * item)
|
||||
{
|
||||
assert(item);
|
||||
|
||||
pthread_mutex_lock(&aq->mutex);
|
||||
int ret = -1;
|
||||
if(aq->buf[aq->writePos % aq->num] == NULL)
|
||||
{
|
||||
if (aq->buf[aq->writePos % aq->num] == NULL) {
|
||||
aq->buf[aq->writePos % aq->num] = item;
|
||||
aq->writePos = (aq->writePos + 1) % aq->num;
|
||||
ret = 0;
|
||||
@ -65,12 +66,12 @@ int array_queue_push(array_queue * aq, void * item)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void* array_queue_pop(array_queue * aq)
|
||||
void *
|
||||
array_queue_pop(array_queue * aq)
|
||||
{
|
||||
pthread_mutex_lock(&aq->mutex);
|
||||
void * value = aq->buf[aq->readPos % aq->num];
|
||||
if(value)
|
||||
{
|
||||
if (value) {
|
||||
aq->buf[aq->readPos % aq->num] = NULL;
|
||||
aq->readPos = (aq->readPos + 1) % aq->num;
|
||||
}
|
||||
@ -78,7 +79,8 @@ void* array_queue_pop(array_queue * aq)
|
||||
return value;
|
||||
}
|
||||
|
||||
size_t array_queue_get_size(array_queue * aq)
|
||||
size_t
|
||||
array_queue_get_size(array_queue * aq)
|
||||
{
|
||||
pthread_mutex_lock(&aq->mutex);
|
||||
ssize_t r = aq->writePos - aq->readPos;
|
||||
@ -94,4 +96,4 @@ size_t array_queue_get_size(array_queue * aq)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //CUBE_ARRAY_QUEUE_H
|
||||
#endif // CUBE_ARRAY_QUEUE_H
|
||||
|
Reference in New Issue
Block a user