Logo
shared_memory.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdio.h>
4 #include <pthread.h>
5 #include <sys/shm.h>
6 #include <sys/ipc.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <sys/mman.h>
10 #include <fcntl.h>
11 #include <cstdlib>
12 #include <stdint.h>
13 #include <unistd.h>
14 
15 #define DEFAULT_KEY 85549
16 
17 struct shm_buf{
18  uint64_t chunk_size;
19  char* buf;
20  uint32_t chunk_index;
21 // uint32_t chunk_offset;
22 // bool commit;
23 };
24 
25 struct semaphore {
26  pthread_mutex_t lock;
27  pthread_cond_t nonzero;
28  unsigned head;
29  unsigned tail;
30  unsigned queue_size;
31  unsigned count;
32 };
33 
34 struct semaphore * semaphore_create(const char *semaphore_name, unsigned qs);
35 struct semaphore * semaphore_open(const char *semaphore_name);
36 void semaphore_close(struct semaphore *semap);
37 
void semaphore_close(struct semaphore *semap)
Definition: shared_memory-modify.hh:84
struct semaphore * semaphore_open(const char *semaphore_name)
Definition: shared_memory.cc:37
struct semaphore * semaphore_create(const char *semaphore_name, unsigned qs)
Definition: shared_memory.cc:4
Definition: shared_memory-modify.hh:22
unsigned queue_size
Definition: shared_memory-modify.hh:27
pthread_cond_t nonzero
Definition: shared_memory-modify.hh:24
pthread_mutex_t lock
Definition: shared_memory-modify.hh:23
unsigned tail
Definition: shared_memory-modify.hh:26
unsigned count
Definition: shared_memory-modify.hh:28
unsigned head
Definition: shared_memory-modify.hh:25
Definition: shared_memory-modify.hh:14
char * buf
Definition: shared_memory-modify.hh:16
uint32_t chunk_index
Definition: shared_memory-modify.hh:17
uint64_t chunk_size
Definition: shared_memory-modify.hh:15