Unused variable.
[jack2.git] / common / shm.h
blob4a7d15c69c30294e71c9577f0e0fc4caf027f4e3
1 #ifndef __jack_shm_h__
2 #define __jack_shm_h__
4 #include <limits.h>
5 #include <sys/types.h>
6 #include "types.h"
7 #include "JackCompilerDeps.h"
9 #define TRUE 1
10 #define FALSE 0
12 #ifdef __cplusplus
13 extern "C"
15 #endif
17 #define MAX_SERVERS 8 /* maximum concurrent servers */
18 #define MAX_SHM_ID 256 /* generally about 16 per server */
19 #define JACK_SERVER_NAME_SIZE 256 /* maximum length of server name */
20 #define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
21 #define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
22 #define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
25 /* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory
26 * segment name (instead of NAME_MAX or PATH_MAX as defined by the
27 * standard).
29 #ifdef USE_POSIX_SHM
31 #ifndef NAME_MAX
32 #define NAME_MAX 255
33 #endif
35 #ifndef SHM_NAME_MAX
36 #define SHM_NAME_MAX NAME_MAX
37 #endif
38 typedef char shm_name_t[SHM_NAME_MAX];
39 typedef shm_name_t jack_shm_id_t;
41 #elif WIN32 // TO CHECK
42 #define NAME_MAX 255
43 #ifndef SHM_NAME_MAX
44 #define SHM_NAME_MAX NAME_MAX
45 #endif
46 typedef char shm_name_t[SHM_NAME_MAX];
47 typedef shm_name_t jack_shm_id_t;
49 #else
50 /* System V SHM */
51 typedef int jack_shm_id_t;
52 #endif /* SHM type */
54 /* shared memory type */
55 typedef enum {
56 shm_POSIX = 1, /* POSIX shared memory */
57 shm_SYSV = 2, /* System V shared memory */
58 shm_WIN32 = 3 /* Windows 32 shared memory */
59 } jack_shmtype_t;
61 typedef int16_t jack_shm_registry_index_t;
63 /**
64 * A structure holding information about shared memory allocated by
65 * JACK. this persists across invocations of JACK, and can be used by
66 * multiple JACK servers. It contains no pointers and is valid across
67 * address spaces.
69 * The registry consists of two parts: a header including an array of
70 * server names, followed by an array of segment registry entries.
72 typedef struct _jack_shm_server {
73 #ifdef WIN32
74 int pid; /* process ID */
75 #else
76 pid_t pid; /* process ID */
77 #endif
79 char name[JACK_SERVER_NAME_SIZE];
81 jack_shm_server_t;
83 typedef struct _jack_shm_header {
84 uint32_t magic; /* magic number */
85 uint16_t protocol; /* JACK protocol version */
86 jack_shmtype_t type; /* shm type */
87 jack_shmsize_t size; /* total registry segment size */
88 jack_shmsize_t hdr_len; /* size of header */
89 jack_shmsize_t entry_len; /* size of registry entry */
90 jack_shm_server_t server[MAX_SERVERS]; /* current server array */
92 jack_shm_header_t;
94 typedef struct _jack_shm_registry {
95 jack_shm_registry_index_t index; /* offset into the registry */
97 #ifdef WIN32
98 int allocator; /* PID that created shm segment */
99 #else
100 pid_t allocator; /* PID that created shm segment */
101 #endif
103 jack_shmsize_t size; /* for POSIX unattach */
104 jack_shm_id_t id; /* API specific, see above */
106 jack_shm_registry_t;
108 #define JACK_SHM_REGISTRY_SIZE (sizeof (jack_shm_header_t) \
109 + sizeof (jack_shm_registry_t) * MAX_SHM_ID)
112 * a structure holding information about shared memory
113 * allocated by JACK. this version is valid only
114 * for a given address space. It contains a pointer
115 * indicating where the shared memory has been
116 * attached to the address space.
119 typedef struct _jack_shm_info {
120 jack_shm_registry_index_t index; /* offset into the registry */
121 uint32_t size;
122 union {
123 void *attached_at; /* address where attached */
124 char ptr_size[8];
125 } ptr; /* a "pointer" that has the same 8 bytes size when compling in 32 or 64 bits */
127 POST_PACKED_STRUCTURE jack_shm_info_t;
129 /* utility functions used only within JACK */
131 void jack_shm_copy_from_registry (jack_shm_info_t*,
132 jack_shm_registry_index_t);
133 void jack_shm_copy_to_registry (jack_shm_info_t*,
134 jack_shm_registry_index_t*);
135 void jack_release_shm_info (jack_shm_registry_index_t);
136 char* jack_shm_addr (jack_shm_info_t* si);
138 // here begin the API
139 int jack_register_server (const char *server_name, int new_registry);
140 void jack_unregister_server (const char *server_name);
142 int jack_initialize_shm (const char *server_name);
143 int jack_initialize_shm_server (void);
144 int jack_initialize_shm_client (void);
145 int jack_cleanup_shm (void);
147 int jack_shmalloc (const char *shm_name, jack_shmsize_t size,
148 jack_shm_info_t* result);
149 void jack_release_shm (jack_shm_info_t*);
150 void jack_destroy_shm (jack_shm_info_t*);
151 int jack_attach_shm (jack_shm_info_t*);
152 int jack_attach_shm_read (jack_shm_info_t*);
153 int jack_resize_shm (jack_shm_info_t*, jack_shmsize_t size);
155 #ifdef __cplusplus
157 #endif
159 #endif /* __jack_shm_h__ */