Add reverb parameters
[openal-soft.git] / OpenAL32 / alThunk.c
blobd050d6b4c123efecbfa60ca3e518de3468ba4cdb
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.
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.
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
21 #include <stdlib.h>
23 #include "alMain.h"
24 #include "alThunk.h"
26 typedef struct {
27 ALvoid *ptr;
28 ALboolean InUse;
29 } ThunkEntry;
31 static ThunkEntry *g_ThunkArray;
32 static ALuint g_ThunkArraySize;
34 static CRITICAL_SECTION g_ThunkLock;
36 void alThunkInit(void)
38 InitializeCriticalSection(&g_ThunkLock);
39 g_ThunkArraySize = 1;
40 g_ThunkArray = calloc(1, g_ThunkArraySize * sizeof(ThunkEntry));
43 void alThunkExit(void)
45 free(g_ThunkArray);
46 g_ThunkArray = NULL;
47 g_ThunkArraySize = 0;
48 DeleteCriticalSection(&g_ThunkLock);
51 ALuint alThunkAddEntry(ALvoid *ptr)
53 ALuint index;
55 EnterCriticalSection(&g_ThunkLock);
57 for(index = 0;index < g_ThunkArraySize;index++)
59 if(g_ThunkArray[index].InUse == AL_FALSE)
60 break;
63 if(index == g_ThunkArraySize)
65 ThunkEntry *NewList;
67 NewList = realloc(g_ThunkArray, g_ThunkArraySize*2 * sizeof(ThunkEntry));
68 if(!NewList)
70 LeaveCriticalSection(&g_ThunkLock);
71 return 0;
73 memset(&NewList[g_ThunkArraySize], 0, g_ThunkArraySize*sizeof(ThunkEntry));
74 g_ThunkArraySize *= 2;
75 g_ThunkArray = NewList;
78 g_ThunkArray[index].ptr = ptr;
79 g_ThunkArray[index].InUse = AL_TRUE;
81 LeaveCriticalSection(&g_ThunkLock);
83 return index+1;
86 void alThunkRemoveEntry(ALuint index)
88 EnterCriticalSection(&g_ThunkLock);
90 if(index > 0 && index <= g_ThunkArraySize)
91 g_ThunkArray[index-1].InUse = AL_FALSE;
93 LeaveCriticalSection(&g_ThunkLock);
96 ALvoid *alThunkLookupEntry(ALuint index)
98 ALvoid *ptr = NULL;
100 EnterCriticalSection(&g_ThunkLock);
102 if(index > 0 && index <= g_ThunkArraySize)
103 ptr = g_ThunkArray[index-1].ptr;
105 LeaveCriticalSection(&g_ThunkLock);
107 return ptr;