2007-11-13 18:02:18 -08:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2007 by authors.
|
|
|
|
* 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 Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
2008-01-16 14:09:04 -08:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alThunk.h"
|
|
|
|
|
|
|
|
|
2011-08-22 07:22:02 -07:00
|
|
|
static ALboolean *g_ThunkArray;
|
2007-11-13 18:02:18 -08:00
|
|
|
static ALuint g_ThunkArraySize;
|
|
|
|
|
|
|
|
static CRITICAL_SECTION g_ThunkLock;
|
|
|
|
|
2011-08-22 07:40:14 -07:00
|
|
|
void ThunkInit(void)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
|
|
|
InitializeCriticalSection(&g_ThunkLock);
|
|
|
|
g_ThunkArraySize = 1;
|
2011-08-22 07:22:02 -07:00
|
|
|
g_ThunkArray = calloc(1, g_ThunkArraySize * sizeof(*g_ThunkArray));
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
|
|
|
|
2011-08-22 07:40:14 -07:00
|
|
|
void ThunkExit(void)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
|
|
|
free(g_ThunkArray);
|
|
|
|
g_ThunkArray = NULL;
|
|
|
|
g_ThunkArraySize = 0;
|
|
|
|
DeleteCriticalSection(&g_ThunkLock);
|
|
|
|
}
|
|
|
|
|
2011-08-22 07:44:22 -07:00
|
|
|
ALenum NewThunkEntry(ALuint *index)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
2011-08-22 07:44:22 -07:00
|
|
|
ALuint i;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
EnterCriticalSection(&g_ThunkLock);
|
|
|
|
|
2011-08-22 07:44:22 -07:00
|
|
|
for(i = 0;i < g_ThunkArraySize;i++)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
2011-08-22 07:44:22 -07:00
|
|
|
if(g_ThunkArray[i] == AL_FALSE)
|
2007-11-13 18:02:18 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-22 07:44:22 -07:00
|
|
|
if(i == g_ThunkArraySize)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
2011-08-22 07:22:02 -07:00
|
|
|
ALboolean *NewList;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2011-08-22 07:22:02 -07:00
|
|
|
NewList = realloc(g_ThunkArray, g_ThunkArraySize*2 * sizeof(*g_ThunkArray));
|
2007-11-13 18:02:18 -08:00
|
|
|
if(!NewList)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&g_ThunkLock);
|
2011-07-13 01:43:00 -07:00
|
|
|
ERR("Realloc failed to increase to %u enties!\n", g_ThunkArraySize*2);
|
2011-06-17 23:59:25 -07:00
|
|
|
return AL_OUT_OF_MEMORY;
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
2011-08-22 07:22:02 -07:00
|
|
|
memset(&NewList[g_ThunkArraySize], 0, g_ThunkArraySize*sizeof(*g_ThunkArray));
|
2007-11-13 18:02:18 -08:00
|
|
|
g_ThunkArraySize *= 2;
|
|
|
|
g_ThunkArray = NewList;
|
|
|
|
}
|
|
|
|
|
2011-08-22 07:44:22 -07:00
|
|
|
g_ThunkArray[i] = AL_TRUE;
|
|
|
|
*index = i+1;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
LeaveCriticalSection(&g_ThunkLock);
|
|
|
|
|
2011-06-17 23:59:25 -07:00
|
|
|
return AL_NO_ERROR;
|
2007-11-13 18:02:18 -08:00
|
|
|
}
|
|
|
|
|
2011-08-22 07:40:14 -07:00
|
|
|
void FreeThunkEntry(ALuint index)
|
2007-11-13 18:02:18 -08:00
|
|
|
{
|
|
|
|
EnterCriticalSection(&g_ThunkLock);
|
|
|
|
|
|
|
|
if(index > 0 && index <= g_ThunkArraySize)
|
2011-08-22 07:22:02 -07:00
|
|
|
g_ThunkArray[index-1] = AL_FALSE;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
LeaveCriticalSection(&g_ThunkLock);
|
|
|
|
}
|