shm_arena.h
1 /* shm_arena.h is generated from the file shm_arena.h.in using configure */
2 
3 /*
4  shm-arena shared memory arena
5  Copyright (C) 2006-2008 Lance Arsenault (LGPL v3)
6 
7 
8  This file is part of shm-arena.
9 
10  shm-arena is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14 
15  shm-arena is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this program. If not, see
22  <http://www.gnu.org/licenses/>.
23 */
24 
41 #ifndef __SHM_ARENA_H__
42 #define __SHM_ARENA_H__
43 
44 /*************************************************************
45  system header files needed
46 *************************************************************/
47 #include <sys/stat.h> /* for SHM_RW_MODE */
48 #include <fcntl.h> /* for some macros */
49 #include <stdio.h> /* defines NULL */
50 #include <sys/types.h> /* for size_t */
51 
52 /**********************************************************
53  shm CPP MACROS
54 **********************************************************/
55 
64 #define SHM_DEFAULT_SPEW_LEVEL "WARN"
65 
70 #define SHM_HOMEPAGE "http://shm-arena.sourceforge.net/"
71 
77 #define SHM_PREFIX "/home/lanceman/installed/encap/shm_arena"
78 
86 #define SHM_DEFAULT_ARENA_DIR "/tmp/shm_arena"
87 
97 #define SHM_DEFAULT_ARENA_FILE "arena"
98 
99 
105 #define SHM_RW_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
106 
107 
108 /* The configure script makes sure that the last 8 bits (of 32)
109  * in the open(2) flags are unused by any standard system flags
110  * like O_CREAT and all the others in fcntl.h. */
111 
123 #define SHM_WITH_SHM_OPEN (01 << 24)
124 
130 #define SHM_ARENA_HAVE_FLOCK (01 << 25)
131 
138 #define SHM_USE_GIVEN_PATH (01 << 26)
139 
144 #define SHM_ARENA_DEFAULT (01 << 27)
145 
150 #define SHM_WITHOUT_RWLOCK (01 << 28)
151 
152 
153 
158 #define SHM_TIMESTAMP (01 << 29)
159 
165 #define SHM_UNKNOWN_SIZE ((size_t) -1)
166 
167 
168 /***********************************************************************/
169 #ifdef __cplusplus
170 extern "C"
171 {
172 #endif
173 
174 /************************************************************************
175  shm data structures
176 ************************************************************************/
177 
185  typedef struct shm_arena *shm_arena_t;
186 
196  typedef struct smq *smq_t;
197 
198 /************************************************************************
199  shm library functions
200 ************************************************************************/
201 
202  /* The shm_*() functions are doxygen documented in other .c source
203  * files. */
204 
205  extern
206  void *shm_get(shm_arena_t arena, size_t size,
207  const char *name, int flags);
208 
209  extern
210  ssize_t shm_size(shm_arena_t arena, const void *ptr);
211 
212  extern
213  ssize_t shm_size_name(shm_arena_t arena, const char *name);
214 
215  extern
216  int shm_remove(shm_arena_t arena, const void *ptr);
217 
218  extern
219  int shm_remove_name(shm_arena_t arena, const char *name);
220 
221  extern
222  char *shm_name(shm_arena_t arena, const void *ptr,
223  char *name, size_t name_size);
224 
225 
226 
227 
228  extern
229  int shm_wrlock(shm_arena_t arena, const void *ptr);
230 
231  extern
232  int shm_rdlock(shm_arena_t arena, const void *ptr);
233 
234  extern
235  int shm_unlock(shm_arena_t arena, const void *ptr);
236 
237 
238  extern
239  int shm_rwlock_reset(shm_arena_t arena, const void *ptr);
240 
241 
242 
243 
244  /* arena management functions */
245 
246  extern
247  shm_arena_t shm_arena_create(const char *path, int flags,
248  mode_t mode, size_t min_size);
249 
250 
251  extern
252  int shm_arena_delete(shm_arena_t arena);
253 
254  extern
255  int shm_arena_destroy(const char *path, int flags);
256 
257  extern
258  int shm_arena_rwlock_reset(shm_arena_t arena);
259 
260 
261 
262 
263 
264  extern
265  int shm_arena_wrlock(shm_arena_t arena);
266 
267  extern
268  int shm_arena_rdlock(shm_arena_t arena);
269 
270  extern
271  int shm_arena_unlock(shm_arena_t arena);
272 
273 
274 
275  extern
276  int shm_arena_set_default(const shm_arena_t arena);
277 
278 
279 
280 
281  extern
282  int shm_arena_print(shm_arena_t arena);
283 
284  extern
285  int shm_arena_print_dot(shm_arena_t arena);
286 
287  extern
288  int shm_arena_print_list(shm_arena_t arena);
289 
290 
291 
292 
293  /*******************************************************************
294  * simpler interfaces which use the default arena which can be set
295  * automatically or by using shm_arena_set_default()
296  *******************************************************************/
297 
298 
328  static inline
329  void *sm_get(size_t size, const char *name)
330  {
331  return shm_get(NULL, size, name, O_CREAT);
332  }
333 
353  static inline
354  void *sm_create(size_t size, const char *name)
355  {
356  return shm_get(NULL, size, name, O_CREAT|O_EXCL);
357  }
358 
378  static inline
379  void *sm_connect(size_t size, const char *name)
380  {
381  return shm_get(NULL, size, name, 0);
382  }
383 
395  static inline
396  size_t sm_size(const void *ptr)
397  {
398  return shm_size(NULL, ptr);
399  }
400 
413  static inline
414  size_t sm_size_name(const char *name)
415  {
416  return shm_size_name(NULL, name);
417  }
418 
419 
432  static inline
433  int sm_remove(const void *ptr)
434  {
435  return shm_remove(NULL, ptr);
436  }
437 
450  static inline
451  int sm_remove_name(const char *name)
452  {
453  return shm_remove_name(NULL, name);
454  }
455 
477  static inline
478  char *sm_name(const void *ptr, char *name, size_t name_size)
479  {
480  return shm_name(NULL, ptr, name, name_size);
481  }
482 
500  static inline
501  int sm_wrlock(const void *ptr)
502  {
503  return shm_wrlock(NULL, ptr);
504  }
505 
523  static inline
524  int sm_rdlock(const void *ptr)
525  {
526  return shm_rdlock(NULL, ptr);
527  }
528 
547  static inline
548  int sm_unlock(const void *ptr)
549  {
550  return shm_unlock(NULL, ptr);
551  }
552 
553 
554 
566  static inline
567  int sm_arena_wrlock(void)
568  {
569  return shm_arena_wrlock(NULL);
570  }
571 
583  static inline
584  int sm_arena_rdlock(void)
585  {
586  return shm_arena_rdlock(NULL);
587  }
588 
602  static inline
603  int sm_arena_unlock(void)
604  {
605  return shm_arena_unlock(NULL);
606  }
607 
608 
609  /****************************************************************
610  * smq functions *
611  ****************************************************************/
612  extern
613  smq_t smq_get(shm_arena_t arena, size_t element_size,
614  int q_length, const char *name, int flags);
615  extern
616  size_t smq_element_size(smq_t q);
617  extern
618  int smq_remove(smq_t q);
619  extern
620  int smq_delete(smq_t q);
621  extern
622  int smq_rdlock(smq_t q, int num);
623  extern
624  int smq_unblock_rdlock(smq_t q);
625  extern
626  int smq_wrlock(smq_t q, int num);
627  extern
628  int smq_unlock(smq_t q);
629  extern
630  void *smq_write(smq_t q);
631  extern
632  void *smq_poll(smq_t q);
633  extern
634  void *smq_read(smq_t q);
635  extern
636  long double *smq_timestamp(smq_t q, const void *ptr);
637 
638 
639 /***********************************************************************/
640 #ifdef __cplusplus
641 }
642 #endif
643 /***********************************************************************/
644 
645 #endif /* #ifndef __SHM_ARENA_H__ */
646 
static size_t sm_size(const void *ptr)
get the size of a shared memory segment from a pointer
Definition: shm_arena.h:396
int shm_rwlock_reset(shm_arena_t arena, const void *ptr)
reset a segment read-write lock
Definition: lock.c:315
long double * smq_timestamp(smq_t q, const void *ptr)
read or write the time stamp
Definition: smq.c:1136
smq_t smq_get(shm_arena_t arena, size_t element_size, int q_length, const char *name, int flags)
get a Shared Multi-Queue object
Definition: smq.c:358
ssize_t shm_size(shm_arena_t arena, const void *ptr)
get the size of a shared memory segment
Definition: size_name.c:63
void * smq_poll(smq_t q)
poll the last entry from the Shared Multi-Queue
Definition: smq.c:1229
int shm_arena_set_default(const shm_arena_t arena)
set the local default arena object
Definition: set_default.c:56
shm_arena_t shm_arena_create(const char *path, int flags, mode_t mode, size_t min_size)
create a shared memory arena object
Definition: arena.c:387
int shm_arena_rdlock(shm_arena_t arena)
acquire an arena read lock
Definition: lock.c:114
void * shm_get(shm_arena_t arena, size_t size, const char *name, int flags)
get a shared memory segment
Definition: get.c:437
int shm_remove(shm_arena_t arena, const void *ptr)
remove a shared memory segment
Definition: remove.c:312
static int sm_arena_unlock(void)
release an arena read or write lock
Definition: shm_arena.h:603
int shm_unlock(shm_arena_t arena, const void *ptr)
release a shared memory segment read-write lock
Definition: lock.c:268
int shm_arena_wrlock(shm_arena_t arena)
acquire an arena write lock
Definition: lock.c:80
size_t smq_element_size(smq_t q)
get the element size of Shared Multi-Queue object
Definition: smq.c:792
int smq_rdlock(smq_t q, int num)
acquire Shared Multi-Queue read-lock
Definition: smq.c:881
static void * sm_connect(size_t size, const char *name)
connect to a shared memory segment
Definition: shm_arena.h:379
static char * sm_name(const void *ptr, char *name, size_t name_size)
get the name of a shared memory segment
Definition: shm_arena.h:478
static int sm_arena_rdlock(void)
acquire an arena read lock
Definition: shm_arena.h:584
static int sm_unlock(const void *ptr)
release a shared memory segment read-write lock
Definition: shm_arena.h:548
int smq_unblock_rdlock(smq_t q)
unblock a smq_rdlock() call if needed
Definition: smq.c:1027
int smq_remove(smq_t q)
remove a Shared Multi-Queue from the arena
Definition: smq.c:717
void * smq_write(smq_t q)
write an entry into the Shared Multi-Queue
Definition: smq.c:1165
int shm_arena_print_list(shm_arena_t arena)
Definition: print.c:61
struct shm_arena * shm_arena_t
local process arena object
Definition: shm_arena.h:185
int shm_arena_rwlock_reset(shm_arena_t arena)
reset an arena read-write lock
Definition: lock.c:358
static int sm_remove(const void *ptr)
remove a shared memory segment using a pointer
Definition: shm_arena.h:433
int shm_arena_destroy(const char *path, int flags)
destroy a shared memory arena file
Definition: arena.c:1126
int smq_delete(smq_t q)
delete the local Shared Multi-Queue object
Definition: smq.c:810
int shm_remove_name(shm_arena_t arena, const char *name)
remove a shared memory segment by name
Definition: remove.c:401
static size_t sm_size_name(const char *name)
get the size of a shared memory segment from the name
Definition: shm_arena.h:414
struct smq * smq_t
shared multi-queue object
Definition: shm_arena.h:196
char * shm_name(shm_arena_t arena, const void *ptr, char *name, size_t name_size)
get the name of a shared memory segment for a pointer
Definition: size_name.c:227
int shm_wrlock(shm_arena_t arena, const void *ptr)
acquire an segment write lock
Definition: lock.c:177
static void * sm_get(size_t size, const char *name)
get a shared memory segment
Definition: shm_arena.h:329
static int sm_remove_name(const char *name)
remove a shared memory segment using the name
Definition: shm_arena.h:451
static int sm_wrlock(const void *ptr)
acquire a shared memory segment write lock
Definition: shm_arena.h:501
int shm_arena_unlock(shm_arena_t arena)
release an arena read or write lock
Definition: lock.c:145
int smq_unlock(smq_t q)
release Shared Multi-Queue read or write lock
Definition: smq.c:1102
static int sm_rdlock(const void *ptr)
acquire a shared memory segment read lock
Definition: shm_arena.h:524
static void * sm_create(size_t size, const char *name)
create a shared memory segment
Definition: shm_arena.h:354
int smq_wrlock(smq_t q, int num)
acquire Shared Multi-Queue write-lock
Definition: smq.c:1073
void * smq_read(smq_t q)
read the next entry from the Shared Multi-Queue
Definition: smq.c:1262
static int sm_arena_wrlock(void)
acquire an arena write lock
Definition: shm_arena.h:567
ssize_t shm_size_name(shm_arena_t arena, const char *name)
get the size of a shared memory segment
Definition: size_name.c:145
int shm_arena_delete(shm_arena_t arena)
delete a local shared memory arena object
Definition: arena.c:1016
int shm_arena_print_dot(shm_arena_t arena)
print debug information about a shared memory arena object in this case a dot file that can be made i...
Definition: print.c:535
int shm_arena_print(shm_arena_t arena)
print the cotents of a shared memory arena file to stdout
Definition: print.c:190
int shm_rdlock(shm_arena_t arena, const void *ptr)
acquire an segment read lock
Definition: lock.c:225

Shared Memory Arena version RC-0.0.25