39 #ifndef _CTHREAD_QUEUE_H_
40 #define _CTHREAD_QUEUE_H_
47 #include "cthread_int.h"
49 #include "cthread_pool.h"
75 struct cthread_queue {
78 char name[CTHREAD_NAME_SIZE];
89 static inline struct cthread_queue *
90 _cthread_queue_create(
const char *name)
93 struct cthread_queue *new_queue;
95 new_queue = calloc(1,
sizeof(
struct cthread_queue));
100 stub = _qnode_alloc();
107 strlcpy(new_queue->name, (name) ? name :
"Unknown",
sizeof(new_queue->name));
111 new_queue->head = stub;
112 new_queue->tail = stub;
125 static __attribute__((always_inline))
inline int
126 _cthread_queue_empty(
struct cthread_queue *q)
128 return q->tail == q->head;
140 _cthread_queue_destroy(
struct cthread_queue *q)
145 if (!_cthread_queue_empty(q))
148 _qnode_free(q->head);
165 static __attribute__((always_inline))
inline struct qnode *
166 _cthread_queue_insert_mp(
struct cthread_queue *q,
void *data)
169 struct qnode *n = _qnode_alloc();
180 prev = (
struct qnode *)__sync_lock_test_and_set((uint64_t *)&(q)->head, (uint64_t)prev);
200 static __attribute__((always_inline))
inline struct qnode *
201 _cthread_queue_insert_sp(
struct cthread_queue *q,
void *data)
205 struct qnode *n = _qnode_alloc();
216 prev->next = q->head = n;
229 static __attribute__((always_inline))
inline void *
230 _cthread_queue_poll(
struct cthread_queue *q)
233 struct qnode *tail = q->tail;
234 struct qnode *next = (
struct qnode *)tail->next;
243 if (
likely(next != NULL)) {
245 tail->data = next->data;
264 static __attribute__((always_inline))
inline void *
265 _cthread_queue_remove(
struct cthread_queue *q)
275 data = _cthread_queue_poll(q);
280 }
while (
unlikely(!_cthread_queue_empty(q)));
294 static __attribute__((always_inline))
inline void *
295 _cthread_queue_remove_given(
struct cthread_queue *q,
void *given)
298 struct cthread_queue *saved;
300 saved = _cthread_queue_create(NULL);
310 data = _cthread_queue_poll(q);
312 if (
likely(data != NULL)) {
315 _cthread_queue_insert_sp(saved, data);
319 }
while (
unlikely(!_cthread_queue_empty(q)));
321 while (!_cthread_queue_empty(saved)) {
322 given = _cthread_queue_remove(saved);
323 _cthread_queue_insert_mp(q, given);
325 _cthread_queue_destroy(saved);
#define cne_compiler_barrier()
#define __cne_cache_aligned
#define CNE_DECLARE_PER_THREAD(type, name)