From 7ffcbafaa273929d7d2d27ea22071faaa07d9dd8 Mon Sep 17 00:00:00 2001 From: ubuntu201711081 <201711081@jbnu.ac.kr> Date: Mon, 14 Dec 2020 10:57:12 +0000 Subject: [PATCH] add comment --- simple_circular_buffer.h | 10 ++++++++-- timerhelper.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/simple_circular_buffer.h b/simple_circular_buffer.h index 5d3f505..5056dfb 100644 --- a/simple_circular_buffer.h +++ b/simple_circular_buffer.h @@ -3,26 +3,32 @@ #include +//queue type declare + #define queue_struct(queue_type,queue_size) struct{\ queue_type data [(queue_size)+1];\ size_t begin;\ size_t end;\ } +//queue's attribute + #define queue_size(queue) ((sizeof((queue)->data)/sizeof((queue)->data[0])) - 1) #define queue_isempty(queue) ((queue)->begin == (queue)->end) #define queue_isfull(queue) ((queue)->begin == (((queue)->end + 1) % queue_size(queue))) +//queue's methods + #define queue_init(queue) do{\ (queue)->begin = 0;\ (queue)->end = 0;\ }while(0) -//unchecked +//this do not check that queue is full. #define enqueue(queue,element) do{ \ (queue)->data[(queue)->end] = (element);\ (queue)->end = ((queue)->end + 1) % (queue_size(queue) + 1);\ }while(0) -//unchecked +//this do not check that queue is empty. #define dequeue(queue) \ (((queue)->begin = ((queue)->begin + 1) % (queue_size(queue) + 1)) ,\ (queue)->data[((queue)->begin + queue_size(queue)) % (queue_size(queue) + 1)]) diff --git a/timerhelper.h b/timerhelper.h index fc4ae26..d68a09a 100644 --- a/timerhelper.h +++ b/timerhelper.h @@ -5,7 +5,7 @@ #ifndef __always_inline #define __always_inline #endif - +///subtract b from a to get difference __always_inline struct timespec timespec_sub(struct timespec a,struct timespec b){ struct timespec ret; ret.tv_sec = a.tv_sec - b.tv_sec;