Browse Source

Update Syst V shared memory implementation.

tags/1.9.9.5
Stephane Letz 12 years ago
parent
commit
994423f8b5
2 changed files with 57 additions and 10 deletions
  1. +23
    -9
      common/shm.c
  2. +34
    -1
      common/shm.h

+ 23
- 9
common/shm.c View File

@@ -5,6 +5,7 @@
* - common (interface-independent) code * - common (interface-independent) code
* - POSIX implementation * - POSIX implementation
* - System V implementation * - System V implementation
* - Windows implementation
* *
* The implementation used is determined by whether USE_POSIX_SHM was * The implementation used is determined by whether USE_POSIX_SHM was
* set in the ./configure step. * set in the ./configure step.
@@ -12,7 +13,8 @@


/* /*
Copyright (C) 2001-2003 Paul Davis Copyright (C) 2001-2003 Paul Davis

Copyright (C) 2005-2012 Grame
This program is free software; you can redistribute it and/or modify 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 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 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)", jack_error ("Cannot attach shm registry segment (%s)",
strerror (errno)); strerror (errno));
return EINVAL; return EINVAL;
@@ -1175,7 +1177,7 @@ jack_access_registry (jack_shm_info_t *ri)


/* set up global pointers */ /* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX; 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); jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
return 0; return 0;
} }
@@ -1199,7 +1201,7 @@ jack_create_registry (jack_shm_info_t *ri)
return errno; 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)", jack_error ("Cannot attach shm registry segment (%s)",
strerror (errno)); strerror (errno));
return EINVAL; return EINVAL;
@@ -1207,7 +1209,7 @@ jack_create_registry (jack_shm_info_t *ri)


/* set up global pointers */ /* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX; 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); jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);


/* initialize registry contents */ /* initialize registry contents */
@@ -1226,8 +1228,8 @@ void
jack_release_shm (jack_shm_info_t* si) jack_release_shm (jack_shm_info_t* si)
{ {
/* registry may or may not be locked */ /* 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->id = shmid;
registry->allocator = getpid(); registry->allocator = getpid();
si->index = registry->index; si->index = registry->index;
si->attached_at = MAP_FAILED; /* not attached */
si->ptr.attached_at = MAP_FAILED; /* not attached */
rc = 0; rc = 0;


} else { } else {
@@ -1277,7 +1279,19 @@ jack_shmalloc (const char* name_not_used, jack_shmsize_t size,
int int
jack_attach_shm (jack_shm_info_t* si) 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)", jack_error ("Cannot attach shm segment (%s)",
strerror (errno)); strerror (errno));
jack_release_shm_info (si->index); jack_release_shm_info (si->index);


+ 34
- 1
common/shm.h View File

@@ -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__ #ifndef __jack_shm_h__
#define __jack_shm_h__ #define __jack_shm_h__


@@ -38,7 +71,7 @@ extern "C"
typedef char shm_name_t[SHM_NAME_MAX]; typedef char shm_name_t[SHM_NAME_MAX];
typedef shm_name_t jack_shm_id_t; typedef shm_name_t jack_shm_id_t;


#elif WIN32 // TO CHECK
#elif WIN32
#define NAME_MAX 255 #define NAME_MAX 255
#ifndef SHM_NAME_MAX #ifndef SHM_NAME_MAX
#define SHM_NAME_MAX NAME_MAX #define SHM_NAME_MAX NAME_MAX


Loading…
Cancel
Save