rlm@0: /** rlm@0: * OpenAL cross platform audio library rlm@0: * Copyright (C) 1999-2007 by authors. rlm@0: * This library is free software; you can redistribute it and/or rlm@0: * modify it under the terms of the GNU Library General Public rlm@0: * License as published by the Free Software Foundation; either rlm@0: * version 2 of the License, or (at your option) any later version. rlm@0: * rlm@0: * This library is distributed in the hope that it will be useful, rlm@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of rlm@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU rlm@0: * Library General Public License for more details. rlm@0: * rlm@0: * You should have received a copy of the GNU Library General Public rlm@0: * License along with this library; if not, write to the rlm@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, rlm@0: * Boston, MA 02111-1307, USA. rlm@0: * Or go to http://www.gnu.org/copyleft/lgpl.html rlm@0: */ rlm@0: rlm@0: #include "config.h" rlm@0: rlm@0: #include rlm@0: rlm@0: #include "alMain.h" rlm@0: #include "alThunk.h" rlm@0: rlm@0: rlm@0: static ALboolean *ThunkArray; rlm@0: static ALuint ThunkArraySize; rlm@0: rlm@0: static CRITICAL_SECTION ThunkLock; rlm@0: rlm@0: void ThunkInit(void) rlm@0: { rlm@0: InitializeCriticalSection(&ThunkLock); rlm@0: ThunkArraySize = 1; rlm@0: ThunkArray = calloc(1, ThunkArraySize * sizeof(*ThunkArray)); rlm@0: } rlm@0: rlm@0: void ThunkExit(void) rlm@0: { rlm@0: free(ThunkArray); rlm@0: ThunkArray = NULL; rlm@0: ThunkArraySize = 0; rlm@0: DeleteCriticalSection(&ThunkLock); rlm@0: } rlm@0: rlm@0: ALenum NewThunkEntry(ALuint *index) rlm@0: { rlm@0: ALuint i; rlm@0: rlm@0: EnterCriticalSection(&ThunkLock); rlm@0: rlm@0: for(i = 0;i < ThunkArraySize;i++) rlm@0: { rlm@0: if(ThunkArray[i] == AL_FALSE) rlm@0: break; rlm@0: } rlm@0: rlm@0: if(i == ThunkArraySize) rlm@0: { rlm@0: ALboolean *NewList; rlm@0: rlm@0: NewList = realloc(ThunkArray, ThunkArraySize*2 * sizeof(*ThunkArray)); rlm@0: if(!NewList) rlm@0: { rlm@0: LeaveCriticalSection(&ThunkLock); rlm@0: ERR("Realloc failed to increase to %u enties!\n", ThunkArraySize*2); rlm@0: return AL_OUT_OF_MEMORY; rlm@0: } rlm@0: memset(&NewList[ThunkArraySize], 0, ThunkArraySize*sizeof(*ThunkArray)); rlm@0: ThunkArraySize *= 2; rlm@0: ThunkArray = NewList; rlm@0: } rlm@0: rlm@0: ThunkArray[i] = AL_TRUE; rlm@0: *index = i+1; rlm@0: rlm@0: LeaveCriticalSection(&ThunkLock); rlm@0: rlm@0: return AL_NO_ERROR; rlm@0: } rlm@0: rlm@0: void FreeThunkEntry(ALuint index) rlm@0: { rlm@0: EnterCriticalSection(&ThunkLock); rlm@0: rlm@0: if(index > 0 && index <= ThunkArraySize) rlm@0: ThunkArray[index-1] = AL_FALSE; rlm@0: rlm@0: LeaveCriticalSection(&ThunkLock); rlm@0: }