35 #define QUEUE_MAGIC 75657551
55 pthread_mutexattr_t attr;
57 if (pthread_mutexattr_init(&attr)) {
61 pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
63 if (pthread_mutex_init(&q->
mutex, &attr)) {
67 if (pthread_cond_init(&q->
cond, NULL)) {
72 q->
q_len = queue_length;
77 pthread_mutex_destroy(&q->
mutex);
78 pthread_cond_destroy(&q->
cond);
93 pthread_mutex_destroy(&queuep->
mutex);
94 pthread_cond_destroy(&queuep->
cond);
102 const void *itemp, uint32_t timeout_ms)
106 struct timespec abstime;
111 abstime.tv_nsec += (timeout_ms % 1000) * 1000000;
112 abstime.tv_sec += timeout_ms / 1000;
114 if (abstime.tv_nsec > 1000000000) {
115 abstime.tv_nsec -= 1000000000;
120 pthread_mutex_lock(&queuep->
mutex);
124 if (pthread_cond_timedwait(&queuep->
cond,
125 &queuep->
mutex, &abstime)) {
126 pthread_mutex_unlock(&queuep->
mutex);
130 pthread_cond_wait(&queuep->
cond, &queuep->
mutex);
134 pthread_cond_broadcast(&queuep->
cond);
136 pthread_mutex_unlock(&queuep->
mutex);
142 const void *itemp, uint32_t timeout_ms)
164 const void *itemp,
bool *wokenp)
168 if (ret && (wokenp)) {
176 void *itemp, uint32_t timeout_ms)
178 struct timespec abstime;
183 abstime.tv_nsec += (timeout_ms % 1000) * 1000000;
184 abstime.tv_sec += timeout_ms / 1000;
186 if (abstime.tv_nsec > 1000000000) {
187 abstime.tv_nsec -= 1000000000;
192 pthread_mutex_lock(&queuep->
mutex);
196 if (pthread_cond_timedwait(&queuep->
cond,
197 &queuep->
mutex, &abstime)) {
198 pthread_mutex_unlock(&queuep->
mutex);
202 pthread_cond_wait(&queuep->
cond, &queuep->
mutex);
206 pthread_cond_broadcast(&queuep->
cond);
208 pthread_mutex_unlock(&queuep->
mutex);
214 void *itemp, uint32_t timeout_ms)
uint32_t PIOS_Thread_Systime(void)
static bool PIOS_Queue_Send_Impl(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
int clock_gettime(clockid_t clk_id, struct timespec *t)
uint16_t circ_queue_read_data(circ_queue_t q, void *buf, uint16_t num)
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
bool PIOS_Queue_Send_FromISR(struct pios_queue *queuep, const void *itemp, bool *wokenp)
static bool PIOS_Queue_Receive_Impl(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
uint16_t circ_queue_write_data(circ_queue_t q, const void *buf, uint16_t num)
void * PIOS_malloc(size_t size)
bool PIOS_Queue_Send(struct pios_queue *queuep, const void *itemp, uint32_t timeout_ms)
bool PIOS_Queue_Receive(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
void PIOS_Queue_Delete(struct pios_queue *queuep)
circ_queue_t circ_queue_new(uint16_t elem_size, uint16_t num_elem)
#define PIOS_QUEUE_TIMEOUT_MAX
size_t PIOS_Queue_GetItemSize(struct pios_queue *queuep)
bool PIOS_Thread_Period_Elapsed(const uint32_t prev_systime, const uint32_t increment_ms)
Determine if a period has elapsed since a datum.
Public header for 1 reader, 1 writer circular queue.
void PIOS_free(void *buf)
#define PIOS_Assert(test)
bool PIOS_Thread_FakeClock_IsActive(void)