-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.h
More file actions
38 lines (28 loc) · 1.06 KB
/
buffer.h
File metadata and controls
38 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef JO418361_BUFFER_H
#define JO418361_BUFFER_H
#include <stddef.h>
typedef struct Buffer Buffer;
typedef Buffer* buffer_t;
// returns thing from buffer or waits till there is one,
// if no things are left but kill_buffer was called returns NULL
void* buffer_take(buffer_t buffer);
// all things put into buffer should be freed by
// one who takes from buffer
void buffer_put(buffer_t buffer, void* thing);
// retvals:
// 0 - success
// -1 - buffer malloc error
// -2 - arr malloc error
// -3 - mutex || semaphore init error
int create_buffer(buffer_t* buffer, size_t size);
// cleanup - assumes that no things are left in the buffer,
// if things are still in the buffer might cause memory leak
void destroy_buffer(buffer_t* buffer);
// any thing user tries to buffer_put after calling this function
// is freed immediately,
// buffer_take returns values till there are things in the buffer
// when no things are left returns NULL
void kill_buffer(buffer_t buffer);
size_t buffer_size(buffer_t buffer);
void buffer_print(buffer_t buffer);
#endif //JO418361_BUFFER_H