55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
#ifndef INCLUDED_C_LOCKQUEUE_H
|
|||
|
|
#define INCLUDED_C_LOCKQUEUE_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_TYPES_H
|
||
|
|
#include <c_Types.h>
|
||
|
|
#endif /*INCLUDED_C_TYPES_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_MUTEX_H
|
||
|
|
#include <c_Mutex.h>
|
||
|
|
#endif /*INCLUDED_C_MUTEX_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_COND_H
|
||
|
|
#include <c_Cond.h>
|
||
|
|
#endif /*INCLUDED_C_COND_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_ALLOCATOR_H
|
||
|
|
#include <c_Allocator.h>
|
||
|
|
#endif /*INCLUDED_C_ALLOCATOR_H*/
|
||
|
|
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
void** data;
|
||
|
|
c_size_t capacity;
|
||
|
|
c_size_t write_idx;
|
||
|
|
c_size_t read_idx;
|
||
|
|
c_size_t size;
|
||
|
|
c_bool_t is_shutdown;
|
||
|
|
|
||
|
|
c_Mutex_t lock;
|
||
|
|
c_Cond_t not_full;
|
||
|
|
c_Cond_t not_empty;
|
||
|
|
c_Allocator_t allocator;
|
||
|
|
}c_LockQueue_t;
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
c_err_t c_LockQueue_Init(c_LockQueue_t* queue, c_size_t capacity, c_Allocator_t* allocator);
|
||
|
|
void c_LockQueue_Destroy(c_LockQueue_t* queue);
|
||
|
|
void c_LockQueue_Shutdown(c_LockQueue_t* queue);
|
||
|
|
|
||
|
|
c_err_t c_LockQueue_Push(c_LockQueue_t* queue, void* data);
|
||
|
|
c_err_t c_LockQueue_Pop(c_LockQueue_t* queue, void** data);
|
||
|
|
c_bool_t c_LockQueue_TimedPop(c_LockQueue_t* queue, void** item, c_uint_t timeout_ms);
|
||
|
|
c_bool_t c_LockQueue_TimedPush(c_LockQueue_t* queue, void* item, c_uint_t timeout_ms);
|
||
|
|
c_size_t c_LockQueue_Size(c_LockQueue_t* queue);
|
||
|
|
|
||
|
|
c_bool_t c_LockQueue_IsEmpty(c_LockQueue_t* queue);
|
||
|
|
c_bool_t c_LockQueue_IsFull(c_LockQueue_t* queue);
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_LOCKQUEUE_H*/
|