This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* lock_t - type for the spinlock bit array | |
* C11 spec says to use an atomic for atomic lock value | |
*/ | |
typedef atomic_uint lock_t; | |
/** | |
* lockholder - bit array marking the thread holding the spinlock | |
* | |
* This will be 0 if no thread holds lock, otherwise ONE of the defined lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* event types to log | |
*/ | |
typedef enum evtid { | |
EVT_ENQ = 1, | |
EVT_DEQ = 2, | |
EVT_DEQ_IDLE = 3, | |
EVT_END = 4, | |
} evtid_t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* q_consumer: pthread to call q_deq | |
* @arg: pthread arguments passed from pthread_create (not used) | |
* | |
* This pthread loops until the END_EL value is received. It trys to dequeue a | |
* value. If one is available the function logs it, otherwise it increases and | |
* idle counter. After a value is dequeued it will also log the idle counter. | |
* | |
* When the consumer thread starts before the producer it busy-waits | |
* until the first value is written by the producer. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* q_deq: dequeue the oldest ringbuffer element | |
* @sqp: the simple queue context structure | |
* @valp: return the value in the current deq element | |
* | |
* Logic: | |
* - If no valid elements, return -1 | |
* - get value from bufs element | |
* - mark queue element as invalid (for debugging) and decrement counter | |
* - if last element then wrap to first, otherwise move to next element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Fixed size of the array used for queuing */ | |
#define QDEPTH 4096 | |
/** | |
* struct sq - simple queue | |
* @bufs: fix array of buffers | |
* @enq: pointer to the bufs element to fill for the newest value, | |
* the element will either be invalid or, if valid, the | |
* oldest filled. | |
* @deq: pointer to the bufs element to drain next, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* q_enq: enqueue a new value into the oldest ringbuffer element | |
* @sqp: the simple queue context structure | |
* @val: value to enter into current bufs element | |
* | |
* Logic: | |
* - update element value and wrap or increment enq pointer | |
* - if all bufs are being used then move the deq pointer to the | |
* current oldest (one more than the newest!), | |
* if bufs still available then increment buf count |