diff --git a/common/shm.c b/common/shm.c index f4543b2d..22d79840 100644 --- a/common/shm.c +++ b/common/shm.c @@ -5,6 +5,7 @@ * - common (interface-independent) code * - POSIX implementation * - System V implementation + * - Windows implementation * * The implementation used is determined by whether USE_POSIX_SHM was * set in the ./configure step. @@ -12,7 +13,8 @@ /* Copyright (C) 2001-2003 Paul Davis - + Copyright (C) 2005-2012 Grame + This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or @@ -1167,7 +1169,7 @@ jack_access_registry (jack_shm_info_t *ri) } } - if ((ri->attached_at = shmat (registry_id, 0, 0)) < 0) { + if ((ri->ptr.attached_at = shmat (registry_id, 0, 0)) < 0) { jack_error ("Cannot attach shm registry segment (%s)", strerror (errno)); return EINVAL; @@ -1175,7 +1177,7 @@ jack_access_registry (jack_shm_info_t *ri) /* set up global pointers */ ri->index = JACK_SHM_REGISTRY_INDEX; - jack_shm_header = ri->attached_at; + jack_shm_header = ri->ptr.attached_at; jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1); return 0; } @@ -1199,7 +1201,7 @@ jack_create_registry (jack_shm_info_t *ri) return errno; } - if ((ri->attached_at = shmat (registry_id, 0, 0)) < 0) { + if ((ri->ptr.attached_at = shmat (registry_id, 0, 0)) < 0) { jack_error ("Cannot attach shm registry segment (%s)", strerror (errno)); return EINVAL; @@ -1207,7 +1209,7 @@ jack_create_registry (jack_shm_info_t *ri) /* set up global pointers */ ri->index = JACK_SHM_REGISTRY_INDEX; - jack_shm_header = ri->attached_at; + jack_shm_header = ri->ptr.attached_at; jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1); /* initialize registry contents */ @@ -1226,8 +1228,8 @@ void jack_release_shm (jack_shm_info_t* si) { /* registry may or may not be locked */ - if (si->attached_at != MAP_FAILED) { - shmdt (si->attached_at); + if (si->ptr.attached_at != MAP_FAILED) { + shmdt (si->ptr.attached_at); } } @@ -1261,7 +1263,7 @@ jack_shmalloc (const char* name_not_used, jack_shmsize_t size, registry->id = shmid; registry->allocator = getpid(); si->index = registry->index; - si->attached_at = MAP_FAILED; /* not attached */ + si->ptr.attached_at = MAP_FAILED; /* not attached */ rc = 0; } else { @@ -1277,7 +1279,19 @@ jack_shmalloc (const char* name_not_used, jack_shmsize_t size, int jack_attach_shm (jack_shm_info_t* si) { - if ((si->attached_at = shmat (jack_shm_registry[si->index].id, 0, 0)) < 0) { + if ((si->ptr.attached_at = shmat (jack_shm_registry[si->index].id, 0, 0)) < 0) { + jack_error ("Cannot attach shm segment (%s)", + strerror (errno)); + jack_release_shm_info (si->index); + return -1; + } + return 0; +} + +int +jack_attach_shm_read (jack_shm_info_t* si) +{ + if ((si->ptr.attached_at = shmat (jack_shm_registry[si->index].id, 0, SHM_RDONLY)) < 0) { jack_error ("Cannot attach shm segment (%s)", strerror (errno)); jack_release_shm_info (si->index); diff --git a/common/shm.h b/common/shm.h index 2ee4e87e..43f420de 100644 --- a/common/shm.h +++ b/common/shm.h @@ -1,3 +1,36 @@ +/* This module provides a set of abstract shared memory interfaces + * with support using both System V and POSIX shared memory + * implementations. The code is divided into three sections: + * + * - common (interface-independent) code + * - POSIX implementation + * - System V implementation + * - Windows implementation + * + * The implementation used is determined by whether USE_POSIX_SHM was + * set in the ./configure step. + */ + +/* + Copyright (C) 2001-2003 Paul Davis + Copyright (C) 2005-2012 Grame + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + */ + #ifndef __jack_shm_h__ #define __jack_shm_h__ @@ -38,7 +71,7 @@ extern "C" typedef char shm_name_t[SHM_NAME_MAX]; typedef shm_name_t jack_shm_id_t; -#elif WIN32 // TO CHECK +#elif WIN32 #define NAME_MAX 255 #ifndef SHM_NAME_MAX #define SHM_NAME_MAX NAME_MAX