Mercurial > fife-parpg
comparison ext/openal-soft/OpenAL32/alThunk.c @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /** | |
2 * OpenAL cross platform audio library | |
3 * Copyright (C) 1999-2007 by authors. | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the | |
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 * Boston, MA 02111-1307, USA. | |
18 * Or go to http://www.gnu.org/copyleft/lgpl.html | |
19 */ | |
20 | |
21 #include "config.h" | |
22 | |
23 #include <stdlib.h> | |
24 | |
25 #include "alMain.h" | |
26 #include "alThunk.h" | |
27 | |
28 typedef struct { | |
29 ALvoid *ptr; | |
30 ALboolean InUse; | |
31 } ThunkEntry; | |
32 | |
33 static ThunkEntry *g_ThunkArray; | |
34 static ALuint g_ThunkArraySize; | |
35 | |
36 static CRITICAL_SECTION g_ThunkLock; | |
37 | |
38 void alThunkInit(void) | |
39 { | |
40 InitializeCriticalSection(&g_ThunkLock); | |
41 g_ThunkArraySize = 1; | |
42 g_ThunkArray = calloc(1, g_ThunkArraySize * sizeof(ThunkEntry)); | |
43 } | |
44 | |
45 void alThunkExit(void) | |
46 { | |
47 free(g_ThunkArray); | |
48 g_ThunkArray = NULL; | |
49 g_ThunkArraySize = 0; | |
50 DeleteCriticalSection(&g_ThunkLock); | |
51 } | |
52 | |
53 ALuint alThunkAddEntry(ALvoid *ptr) | |
54 { | |
55 ALuint index; | |
56 | |
57 EnterCriticalSection(&g_ThunkLock); | |
58 | |
59 for(index = 0;index < g_ThunkArraySize;index++) | |
60 { | |
61 if(g_ThunkArray[index].InUse == AL_FALSE) | |
62 break; | |
63 } | |
64 | |
65 if(index == g_ThunkArraySize) | |
66 { | |
67 ThunkEntry *NewList; | |
68 | |
69 NewList = realloc(g_ThunkArray, g_ThunkArraySize*2 * sizeof(ThunkEntry)); | |
70 if(!NewList) | |
71 { | |
72 LeaveCriticalSection(&g_ThunkLock); | |
73 return 0; | |
74 } | |
75 memset(&NewList[g_ThunkArraySize], 0, g_ThunkArraySize*sizeof(ThunkEntry)); | |
76 g_ThunkArraySize *= 2; | |
77 g_ThunkArray = NewList; | |
78 } | |
79 | |
80 g_ThunkArray[index].ptr = ptr; | |
81 g_ThunkArray[index].InUse = AL_TRUE; | |
82 | |
83 LeaveCriticalSection(&g_ThunkLock); | |
84 | |
85 return index+1; | |
86 } | |
87 | |
88 void alThunkRemoveEntry(ALuint index) | |
89 { | |
90 EnterCriticalSection(&g_ThunkLock); | |
91 | |
92 if(index > 0 && index <= g_ThunkArraySize) | |
93 g_ThunkArray[index-1].InUse = AL_FALSE; | |
94 | |
95 LeaveCriticalSection(&g_ThunkLock); | |
96 } | |
97 | |
98 ALvoid *alThunkLookupEntry(ALuint index) | |
99 { | |
100 ALvoid *ptr = NULL; | |
101 | |
102 EnterCriticalSection(&g_ThunkLock); | |
103 | |
104 if(index > 0 && index <= g_ThunkArraySize) | |
105 ptr = g_ThunkArray[index-1].ptr; | |
106 | |
107 LeaveCriticalSection(&g_ThunkLock); | |
108 | |
109 return ptr; | |
110 } |