chap4
This commit is contained in:
27
bac2/os/chap4/RingBuffer.h
Normal file
27
bac2/os/chap4/RingBuffer.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define rb_init(size, type)\
|
||||
{(size),\
|
||||
0, 0, false, false,\
|
||||
type,\
|
||||
malloc(sizeof(int)*(size)),\
|
||||
PTHREAD_MUTEX_INITIALIZER};
|
||||
|
||||
#define rb_free(rb) free(rb.data)
|
||||
|
||||
typedef struct rb{
|
||||
size_t size;
|
||||
size_t w_pos, r_pos;
|
||||
bool filled;
|
||||
bool error;
|
||||
enum {DROP, WAIT} type;
|
||||
int* data;
|
||||
pthread_mutex_t m;
|
||||
} rb_t;
|
||||
|
||||
void rb_push(rb_t*, int);
|
||||
int rb_pop(rb_t*);
|
Reference in New Issue
Block a user