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
33 static ThunkEntry
*g_ThunkArray
;
34 static ALuint g_ThunkArraySize
;
36 static CRITICAL_SECTION g_ThunkLock
;
38 void alThunkInit(void)
40 InitializeCriticalSection(&g_ThunkLock
);
42 g_ThunkArray
= calloc(1, g_ThunkArraySize
* sizeof(ThunkEntry
));
45 void alThunkExit(void)
50 DeleteCriticalSection(&g_ThunkLock
);
53 ALuint
alThunkAddEntry(ALvoid
*ptr
)
57 EnterCriticalSection(&g_ThunkLock
);
59 for(index
= 0;index
< g_ThunkArraySize
;index
++)
61 if(g_ThunkArray
[index
].InUse
== AL_FALSE
)
65 if(index
== g_ThunkArraySize
)
69 NewList
= realloc(g_ThunkArray
, g_ThunkArraySize
*2 * sizeof(ThunkEntry
));
72 LeaveCriticalSection(&g_ThunkLock
);
73 AL_PRINT("Realloc failed to increase to %u enties!\n", g_ThunkArraySize
*2);
76 memset(&NewList
[g_ThunkArraySize
], 0, g_ThunkArraySize
*sizeof(ThunkEntry
));
77 g_ThunkArraySize
*= 2;
78 g_ThunkArray
= NewList
;
81 g_ThunkArray
[index
].ptr
= ptr
;
82 g_ThunkArray
[index
].InUse
= AL_TRUE
;
84 LeaveCriticalSection(&g_ThunkLock
);
89 void alThunkRemoveEntry(ALuint index
)
91 EnterCriticalSection(&g_ThunkLock
);
93 if(index
> 0 && index
<= g_ThunkArraySize
)
94 g_ThunkArray
[index
-1].InUse
= AL_FALSE
;
96 LeaveCriticalSection(&g_ThunkLock
);
99 ALvoid
*alThunkLookupEntry(ALuint index
)
103 EnterCriticalSection(&g_ThunkLock
);
105 if(index
> 0 && index
<= g_ThunkArraySize
)
106 ptr
= g_ThunkArray
[index
-1].ptr
;
108 LeaveCriticalSection(&g_ThunkLock
);