[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c
Kenneth C. Arnold
kcarnold at xiph.org
Tue Jun 19 09:30:19 PDT 2001
kcarnold 01/06/19 09:30:19
Modified: ogg123 buffer.c
Log:
Patch from Christian "naddy" Weisgerber <naddy at mips.inka.de> to add
mmap for shared memory. I didn't realize I had never committed this
until I started building the rc1 packages locally. This has been
pretty extensively tested (at least by me and Christian) so I'm
committing it without much discussion.
Revision Changes Path
1.6 +23 -4 vorbis-tools/ogg123/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- buffer.c 2001/05/12 21:24:19 1.5
+++ buffer.c 2001/06/19 16:30:18 1.6
@@ -6,16 +6,16 @@
*/
#include <sys/types.h>
+#if HAVE_SMMAP
+#include <sys/mman.h>
+#else
#include <sys/ipc.h>
#include <sys/shm.h>
+#endif
#include <sys/time.h>
#include <unistd.h> /* for fork and pipe*/
#include <fcntl.h>
-#ifndef DARWIN
-#include <malloc.h>
-#endif
-
#include "ogg123.h"
#include "buffer.h"
@@ -72,6 +72,22 @@
int childpid;
buf_t *buf;
+#if HAVE_SMMAP
+ int fd;
+
+ if ((fd = open("/dev/zero", O_RDWR)) < 0)
+ {
+ perror ("cannot open /dev/zero");
+ exit (1);
+ }
+ if ((buf = (buf_t *) mmap (0, sizeof(buf_t) + sizeof (chunk_t) * (size - 1),
+ PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED)
+ {
+ perror("mmap");
+ exit(1);
+ }
+ close(fd);
+#else
/* Get the shared memory segment. */
int shmid = shmget (IPC_PRIVATE,
sizeof(buf_t) + sizeof (chunk_t) * (size - 1),
@@ -94,6 +110,7 @@
/* Remove segment after last process detaches it or terminates. */
shmctl(shmid, IPC_RMID, 0);
+#endif /* HAVE_SMMAP */
buffer_init (buf, size);
@@ -173,6 +190,8 @@
tv.tv_usec = 0;
select (0, NULL, NULL, NULL, &tv);
}
+#ifndef HAVE_SMMAP
/* Deallocate the shared memory segment. */
shmdt(buf);
+#endif /* HAVE_SMMAP */
}
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list