-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryConnection.h
More file actions
58 lines (47 loc) · 1.57 KB
/
MemoryConnection.h
File metadata and controls
58 lines (47 loc) · 1.57 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
typedef void* _mem_socket;
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/shm.h>
#include <semaphore.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define DEFAULT_CONNECTION_BUFFER_SIZE 256
#define DEFAULT_CONNECTION_SHM "ndb_socket"
#define DEFAULT_SERVER_SEMAPHORE_NAME "ndb_ssocket_sem" /* used to block server */
#define DEFAULT_CLIENT_SEMAPHORE_NAME "ndb_csocket_sem" /* used to block all clients */
#define state1 socket-1 /* first part of state spinlock*/
#define state2 socket-2 /* second part */
#define update1 socket-3 /* state update property */
#ifndef MEMSOCKET_H
#define MEMSOCKET_H
enum _ConnectionState
{
MCON_UNVAIL,
MCON_EMPTY,
MCON_TRANSFER,
MCON_WAITING,
MCON_RESPONSED
};
enum _UpdateState
{
UPDATE,
UPDATE_NONE
};
struct _MemCon
{
_mem_socket socket;
int shm_id;
sem_t*socket_lock;
};
extern inline void memcon_awaitAndSetState(enum _ConnectionState state_wait, enum _ConnectionState state_new, struct _MemCon* con);
extern inline void memcon_awaitState(enum _ConnectionState state_wait, struct _MemCon* con);
extern inline void memcon_updateState(enum _ConnectionState state_new, struct _MemCon* con);
extern inline char memcon_setUpdate(enum _UpdateState state_new, struct _MemCon* con);
extern inline char memcon_getState(struct _MemCon* con);
#endif