add comment
This commit is contained in:
parent
fb7646fac7
commit
7ffcbafaa2
@ -3,26 +3,32 @@
|
|||||||
|
|
||||||
#include<stddef.h>
|
#include<stddef.h>
|
||||||
|
|
||||||
|
//queue type declare
|
||||||
|
|
||||||
#define queue_struct(queue_type,queue_size) struct{\
|
#define queue_struct(queue_type,queue_size) struct{\
|
||||||
queue_type data [(queue_size)+1];\
|
queue_type data [(queue_size)+1];\
|
||||||
size_t begin;\
|
size_t begin;\
|
||||||
size_t end;\
|
size_t end;\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//queue's attribute
|
||||||
|
|
||||||
#define queue_size(queue) ((sizeof((queue)->data)/sizeof((queue)->data[0])) - 1)
|
#define queue_size(queue) ((sizeof((queue)->data)/sizeof((queue)->data[0])) - 1)
|
||||||
#define queue_isempty(queue) ((queue)->begin == (queue)->end)
|
#define queue_isempty(queue) ((queue)->begin == (queue)->end)
|
||||||
#define queue_isfull(queue) ((queue)->begin == (((queue)->end + 1) % queue_size(queue)))
|
#define queue_isfull(queue) ((queue)->begin == (((queue)->end + 1) % queue_size(queue)))
|
||||||
|
|
||||||
|
//queue's methods
|
||||||
|
|
||||||
#define queue_init(queue) do{\
|
#define queue_init(queue) do{\
|
||||||
(queue)->begin = 0;\
|
(queue)->begin = 0;\
|
||||||
(queue)->end = 0;\
|
(queue)->end = 0;\
|
||||||
}while(0)
|
}while(0)
|
||||||
//unchecked
|
//this do not check that queue is full.
|
||||||
#define enqueue(queue,element) do{ \
|
#define enqueue(queue,element) do{ \
|
||||||
(queue)->data[(queue)->end] = (element);\
|
(queue)->data[(queue)->end] = (element);\
|
||||||
(queue)->end = ((queue)->end + 1) % (queue_size(queue) + 1);\
|
(queue)->end = ((queue)->end + 1) % (queue_size(queue) + 1);\
|
||||||
}while(0)
|
}while(0)
|
||||||
//unchecked
|
//this do not check that queue is empty.
|
||||||
#define dequeue(queue) \
|
#define dequeue(queue) \
|
||||||
(((queue)->begin = ((queue)->begin + 1) % (queue_size(queue) + 1)) ,\
|
(((queue)->begin = ((queue)->begin + 1) % (queue_size(queue) + 1)) ,\
|
||||||
(queue)->data[((queue)->begin + queue_size(queue)) % (queue_size(queue) + 1)])
|
(queue)->data[((queue)->begin + queue_size(queue)) % (queue_size(queue) + 1)])
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#ifndef __always_inline
|
#ifndef __always_inline
|
||||||
#define __always_inline
|
#define __always_inline
|
||||||
#endif
|
#endif
|
||||||
|
///subtract b from a to get difference
|
||||||
__always_inline struct timespec timespec_sub(struct timespec a,struct timespec b){
|
__always_inline struct timespec timespec_sub(struct timespec a,struct timespec b){
|
||||||
struct timespec ret;
|
struct timespec ret;
|
||||||
ret.tv_sec = a.tv_sec - b.tv_sec;
|
ret.tv_sec = a.tv_sec - b.tv_sec;
|
||||||
|
Loading…
Reference in New Issue
Block a user