-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexr_shmq.h
76 lines (60 loc) · 1.64 KB
/
flexr_shmq.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <thread>
#include <cstdint>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
class FlexrElemMeta
{
public:
uint32_t occupiedSize;
void init()
{
occupiedSize = 0;
}
};
class FlexrShmQueue
{
public:
pthread_mutex_t lock;
uint32_t rear;
uint32_t front;
uint32_t numElem;
char data[1];
};
/*
* | FlexrShmQueue |
* | FlexrShmQueue | FlexrElemMeta + Elem Data | FlexrElemMeta + Elem Data | FlexrElemMeta + Elem Data | ... |
*/
class FlexrShmQueueMeta
{
public:
uint32_t maxElem;
uint32_t elemSize;
uint32_t totalDataSize;
uint32_t queueSize;
char* name;
int shmemFd;
FlexrShmQueue* queue;
FlexrElemMeta *elemMeta;
bool curElemAccess;
FlexrShmQueueMeta();
~FlexrShmQueueMeta();
bool initQueue(char const* name, uint32_t maxElem, uint32_t elemSize);
bool initQueue(char const* name, uint32_t maxElem, uint32_t elemSize, bool removeFile);
void cleanInit();
void closeQueue();
bool isFull();
bool isEmpty();
void printInfo();
// blocking & nonblocking semantics
bool enqueueElem(void* element, int len, bool blocking=false);
bool dequeueElem(void* element, int &occupiedSize, int len, bool blocking=false);
bool dequeueElem(void* element, uint32_t &occupiedSize, uint32_t bufSize, bool blocking=false);
bool enqueueElemPart(void* element, int offset, int len, bool blocking, bool done);
bool dequeueElemPart(void* element, int &occupiedSize, int offset, int len, bool blocking, bool done);
};