Skip to content

Latest commit

 

History

History
72 lines (59 loc) · 1.83 KB

SDL_audiomem.c

File metadata and controls

72 lines (59 loc) · 1.83 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Mar 6, 2002
Mar 6, 2002
3
Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
22
23
24
25
26
27
28
29
30
31
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id$";
#endif
/* Functions to allocate audio buffer memory, shareable across threads
(necessary because SDL audio emulates threads with fork()
*/
Apr 26, 2001
Apr 26, 2001
32
#include <stdlib.h>
Apr 26, 2001
Apr 26, 2001
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifdef FORK_HACK
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stddef.h>
#endif
#include "SDL_audiomem.h"
/* Allocate memory that will be shared between threads (freed on exit) */
void *SDL_AllocAudioMem(int size)
{
void *chunk;
#ifdef FORK_HACK
int semid;
/* Create and get the address of a shared memory segment */
semid = shmget(IPC_PRIVATE, size, (IPC_CREAT|0600));
if ( semid < 0 ) {
return(NULL);
}
chunk = shmat(semid, NULL, 0);
/* Set the segment for deletion when it is detatched */
shmctl(semid, IPC_RMID, NULL); /* Delets semid if shmat() fails */
#else
chunk = malloc(size);
#endif
return((void *)chunk);
}
void SDL_FreeAudioMem(void *chunk)
{
#ifdef FORK_HACK
shmdt(chunk);
#else
free(chunk);
#endif
}