/ src / libnml / buffer / shmem.hh
shmem.hh
 1  /********************************************************************
 2  * Description: shmem.hh
 3  *   C++ file for the Communication Management System (CMS).
 4  *   Includes member Functions for class SHMEM.
 5  *   Notes: The class SHMEM should be used by procedures accessing a
 6  *   shared memory buffer on the same processor.
 7  *
 8  *   Derived from a work by Fred Proctor & Will Shackleford
 9  *
10  * Author:
11  * License: GPL Version 2
12  * System: Linux
13  *    
14  * Copyright (c) 2004 All rights reserved.
15  *
16  * Last change: 
17  ********************************************************************/
18  
19  #ifndef SHMEM_HH
20  #define SHMEM_HH
21  
22  #ifdef __cplusplus
23  extern "C" {
24  #endif
25  
26  #include <stdio.h>		/* NULL */
27  #include <stddef.h>		/* size_t */
28  #include <sys/types.h>		/* key_t */
29  
30  #ifdef __cplusplus
31  }
32  #endif
33  #include "cms.hh"		/* class CMS */
34  #include "shm.hh"		/* class RCS_SHAREDMEM */
35  #include "memsem.hh"		/* struct mem_access_object */
36  
37  class SHMEM:public CMS {
38    public:
39      SHMEM(const char *name, long size, int neutral, key_t key, int m = 0);
40      SHMEM(const char *bufline, const char *procline, int set_to_server = 0,
41  	int set_to_master = 0);
42      virtual ~ SHMEM();
43  
44      CMS_STATUS main_access(void *_local, int *serial_number);
45  
46    private:
47  
48      /* data buffer stuff */
49      int fast_mode;
50      int open();			/* get shared mem and sem */
51      int close();		/* detach from shared mem and sem */
52      key_t key;			/* key for shared mem and sem */
53      key_t bsem_key;		// key for blocking semaphore
54      int second_read;		// true only if the first read returned no
55      // new data
56      RCS_SHAREDMEM *shm;		/* shared memory */
57      RCS_SEMAPHORE *sem;		/* semaphore */
58      int master;			/* Is this process responsible for */
59      /* clearing memory & semaphores? */
60      double sem_delay;		/* Time to wait between polling the
61  				   semaphore. */
62      struct mem_access_object mao;	/* passed to mem_get_access() */
63      enum SHMEM_MUTEX_TYPE {
64  	NO_MUTEX,
65  	MAO_MUTEX,
66  	MAO_MUTEX_W_OS_SEM,
67  	OS_SEM_MUTEX,
68  	NO_INTERRUPTS_MUTEX,
69  	NO_SWITCHING_MUTEX
70      };
71  
72      int use_os_sem;
73      int use_os_sem_only;
74  
75      SHMEM_MUTEX_TYPE mutex_type;
76      void *shm_addr_offset;
77  
78      RCS_SEMAPHORE *bsem;	// blocking semaphore
79      int autokey_table_size;
80  
81  };
82  
83  #endif /* !SHMEM_HH */