1 #ifndef _LIBRINGBUFFER_SHM_H
2 #define _LIBRINGBUFFER_SHM_H
7 * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Dual LGPL v2.1/GPL v2 license.
15 #define SHM_MAGIC 0x54335433
20 * Defining a max shm offset, for debugging purposes.
22 #if (CAA_BITS_PER_LONG == 32)
23 /* Define the maximum shared memory size to 128MB on 32-bit machines */
24 #define MAX_SHM_SIZE 134217728
26 /* Define the maximum shared memory size to 8GB on 64-bit machines */
27 #define MAX_SHM_SIZE 8589934592
30 #define DECLARE_SHMP(type, name) type *****name
36 uint8_t bits_per_long
;
37 size_t shm_size
, shm_allocated
;
39 DECLARE_SHMP(struct channel
, chan
);
42 #define shmp(shm_offset) \
43 ((__typeof__(****(shm_offset))) (((char *) &(shm_offset)) + (ptrdiff_t) (shm_offset)))
45 #define _shmp_abs(a) ((a < 0) ? -(a) : (a))
48 void _set_shmp(ptrdiff_t *shm_offset
, void *ptr
)
50 *shm_offset
= (((char *) ptr
) - ((char *) shm_offset
));
51 assert(_shmp_abs(*shm_offset
) < MAX_SHM_SIZE
);
54 #define set_shmp(shm_offset, ptr) \
55 _set_shmp((ptrdiff_t *) ****(shm_offset), ptr)
57 /* Shared memory is already zeroed by shmget */
58 /* *NOT* multithread-safe (should be protected by mutex) */
60 void *zalloc_shm(struct shm_header
*shm_header
, size_t len
)
64 if (shm_header
->shm_size
- shm_header
->shm_allocated
< len
)
66 ret
= (char *) shm_header
+ shm_header
->shm_allocated
;
67 shm_header
->shm_allocated
+= len
;
71 #endif /* _LIBRINGBUFFER_SHM_H */
This page took 0.03189 seconds and 5 git commands to generate.