Added a dynamically growing ring buffer for oss, alsa, arts, and nas.
This commit is contained in:
parent
df29ffa647
commit
a104d91ce8
|
@ -102,10 +102,10 @@ typedef struct {
|
|||
* (compared to passing thru the server)
|
||||
* this ring will be used by the input (resp output) record (resp playback) routine
|
||||
*/
|
||||
#define ALSA_RING_BUFFER_INCREMENT 64
|
||||
typedef struct {
|
||||
/* FIXME: this could be made a dynamically growing array (if needed) */
|
||||
#define ALSA_RING_BUFFER_SIZE 30
|
||||
ALSA_MSG messages[ALSA_RING_BUFFER_SIZE];
|
||||
ALSA_MSG * messages;
|
||||
int ring_buffer_size;
|
||||
int msg_tosave;
|
||||
int msg_toget;
|
||||
HANDLE msg_event;
|
||||
|
@ -527,7 +527,9 @@ static int ALSA_InitRingMessage(ALSA_MSG_RING* omr)
|
|||
omr->msg_toget = 0;
|
||||
omr->msg_tosave = 0;
|
||||
omr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
memset(omr->messages, 0, sizeof(ALSA_MSG) * ALSA_RING_BUFFER_SIZE);
|
||||
omr->ring_buffer_size = ALSA_RING_BUFFER_INCREMENT;
|
||||
omr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,omr->ring_buffer_size * sizeof(ALSA_MSG));
|
||||
|
||||
InitializeCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -539,6 +541,7 @@ static int ALSA_InitRingMessage(ALSA_MSG_RING* omr)
|
|||
static int ALSA_DestroyRingMessage(ALSA_MSG_RING* omr)
|
||||
{
|
||||
CloseHandle(omr->msg_event);
|
||||
HeapFree(GetProcessHeap(),0,omr->messages);
|
||||
DeleteCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -553,11 +556,11 @@ static int ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWOR
|
|||
HANDLE hEvent = INVALID_HANDLE_VALUE;
|
||||
|
||||
EnterCriticalSection(&omr->msg_crst);
|
||||
if ((omr->msg_toget == ((omr->msg_tosave + 1) % ALSA_RING_BUFFER_SIZE))) /* buffer overflow ? */
|
||||
if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
|
||||
{
|
||||
ERR("buffer overflow !?\n");
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
omr->ring_buffer_size += ALSA_RING_BUFFER_INCREMENT;
|
||||
TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
|
||||
omr->messages = HeapReAlloc(GetProcessHeap(),0,omr->messages, omr->ring_buffer_size * sizeof(ALSA_MSG));
|
||||
}
|
||||
if (wait)
|
||||
{
|
||||
|
@ -572,7 +575,7 @@ static int ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWOR
|
|||
FIXME("two fast messages in the queue!!!!\n");
|
||||
|
||||
/* fast messages have to be added at the start of the queue */
|
||||
omr->msg_toget = (omr->msg_toget + ALSA_RING_BUFFER_SIZE - 1) % ALSA_RING_BUFFER_SIZE;
|
||||
omr->msg_toget = (omr->msg_toget + omr->ring_buffer_size - 1) % omr->ring_buffer_size;
|
||||
|
||||
omr->messages[omr->msg_toget].msg = msg;
|
||||
omr->messages[omr->msg_toget].param = param;
|
||||
|
@ -583,7 +586,7 @@ static int ALSA_AddRingMessage(ALSA_MSG_RING* omr, enum win_wm_message msg, DWOR
|
|||
omr->messages[omr->msg_tosave].msg = msg;
|
||||
omr->messages[omr->msg_tosave].param = param;
|
||||
omr->messages[omr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
|
||||
omr->msg_tosave = (omr->msg_tosave + 1) % ALSA_RING_BUFFER_SIZE;
|
||||
omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
|
||||
}
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
/* signal a new message */
|
||||
|
@ -617,7 +620,7 @@ static int ALSA_RetrieveRingMessage(ALSA_MSG_RING* omr,
|
|||
omr->messages[omr->msg_toget].msg = 0;
|
||||
*param = omr->messages[omr->msg_toget].param;
|
||||
*hEvent = omr->messages[omr->msg_toget].hEvent;
|
||||
omr->msg_toget = (omr->msg_toget + 1) % ALSA_RING_BUFFER_SIZE;
|
||||
omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -107,9 +107,10 @@ typedef struct {
|
|||
* (compared to passing thru the server)
|
||||
* this ring will be used by the input (resp output) record (resp playback) routine
|
||||
*/
|
||||
#define ARTS_RING_BUFFER_INCREMENT 64
|
||||
typedef struct {
|
||||
#define ARTS_RING_BUFFER_SIZE 30
|
||||
RING_MSG messages[ARTS_RING_BUFFER_SIZE];
|
||||
RING_MSG * messages;
|
||||
int ring_buffer_size;
|
||||
int msg_tosave;
|
||||
int msg_toget;
|
||||
HANDLE msg_event;
|
||||
|
@ -343,7 +344,8 @@ static int ARTS_InitRingMessage(ARTS_MSG_RING* mr)
|
|||
mr->msg_toget = 0;
|
||||
mr->msg_tosave = 0;
|
||||
mr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
memset(mr->messages, 0, sizeof(RING_MSG) * ARTS_RING_BUFFER_SIZE);
|
||||
mr->ring_buffer_size = ARTS_RING_BUFFER_INCREMENT;
|
||||
mr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,mr->ring_buffer_size * sizeof(RING_MSG));
|
||||
InitializeCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -355,6 +357,7 @@ static int ARTS_InitRingMessage(ARTS_MSG_RING* mr)
|
|||
static int ARTS_DestroyRingMessage(ARTS_MSG_RING* mr)
|
||||
{
|
||||
CloseHandle(mr->msg_event);
|
||||
HeapFree(GetProcessHeap(),0,mr->messages);
|
||||
DeleteCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -369,11 +372,11 @@ static int ARTS_AddRingMessage(ARTS_MSG_RING* mr, enum win_wm_message msg, DWORD
|
|||
HANDLE hEvent = INVALID_HANDLE_VALUE;
|
||||
|
||||
EnterCriticalSection(&mr->msg_crst);
|
||||
if ((mr->msg_toget == ((mr->msg_tosave + 1) % ARTS_RING_BUFFER_SIZE))) /* buffer overflow? */
|
||||
if ((mr->msg_toget == ((mr->msg_tosave + 1) % mr->ring_buffer_size)))
|
||||
{
|
||||
ERR("buffer overflow !?\n");
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
mr->ring_buffer_size += ARTS_RING_BUFFER_INCREMENT;
|
||||
TRACE("mr->ring_buffer_size=%d\n",mr->ring_buffer_size);
|
||||
mr->messages = HeapReAlloc(GetProcessHeap(),0,mr->messages, mr->ring_buffer_size * sizeof(RING_MSG));
|
||||
}
|
||||
if (wait)
|
||||
{
|
||||
|
@ -388,7 +391,7 @@ static int ARTS_AddRingMessage(ARTS_MSG_RING* mr, enum win_wm_message msg, DWORD
|
|||
FIXME("two fast messages in the queue!!!!\n");
|
||||
|
||||
/* fast messages have to be added at the start of the queue */
|
||||
mr->msg_toget = (mr->msg_toget + ARTS_RING_BUFFER_SIZE - 1) % ARTS_RING_BUFFER_SIZE;
|
||||
mr->msg_toget = (mr->msg_toget + mr->ring_buffer_size - 1) % mr->ring_buffer_size;
|
||||
|
||||
mr->messages[mr->msg_toget].msg = msg;
|
||||
mr->messages[mr->msg_toget].param = param;
|
||||
|
@ -399,7 +402,7 @@ static int ARTS_AddRingMessage(ARTS_MSG_RING* mr, enum win_wm_message msg, DWORD
|
|||
mr->messages[mr->msg_tosave].msg = msg;
|
||||
mr->messages[mr->msg_tosave].param = param;
|
||||
mr->messages[mr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
|
||||
mr->msg_tosave = (mr->msg_tosave + 1) % ARTS_RING_BUFFER_SIZE;
|
||||
mr->msg_tosave = (mr->msg_tosave + 1) % mr->ring_buffer_size;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
|
@ -436,7 +439,7 @@ static int ARTS_RetrieveRingMessage(ARTS_MSG_RING* mr,
|
|||
mr->messages[mr->msg_toget].msg = 0;
|
||||
*param = mr->messages[mr->msg_toget].param;
|
||||
*hEvent = mr->messages[mr->msg_toget].hEvent;
|
||||
mr->msg_toget = (mr->msg_toget + 1) % ARTS_RING_BUFFER_SIZE;
|
||||
mr->msg_toget = (mr->msg_toget + 1) % mr->ring_buffer_size;
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -131,9 +131,10 @@ typedef struct {
|
|||
* (compared to passing thru the server)
|
||||
* this ring will be used by the input (resp output) record (resp playback) routine
|
||||
*/
|
||||
#define NAS_RING_BUFFER_INCREMENT 64
|
||||
typedef struct {
|
||||
#define NAS_RING_BUFFER_SIZE 30
|
||||
RING_MSG messages[NAS_RING_BUFFER_SIZE];
|
||||
RING_MSG * messages;
|
||||
int ring_buffer_size;
|
||||
int msg_tosave;
|
||||
int msg_toget;
|
||||
HANDLE msg_event;
|
||||
|
@ -421,7 +422,8 @@ static int NAS_InitRingMessage(MSG_RING* mr)
|
|||
mr->msg_toget = 0;
|
||||
mr->msg_tosave = 0;
|
||||
mr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
memset(mr->messages, 0, sizeof(RING_MSG) * NAS_RING_BUFFER_SIZE);
|
||||
mr->ring_buffer_size = NAS_RING_BUFFER_INCREMENT;
|
||||
mr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,mr->ring_buffer_size * sizeof(RING_MSG));
|
||||
InitializeCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -433,6 +435,7 @@ static int NAS_InitRingMessage(MSG_RING* mr)
|
|||
static int NAS_DestroyRingMessage(MSG_RING* mr)
|
||||
{
|
||||
CloseHandle(mr->msg_event);
|
||||
HeapFree(GetProcessHeap(),0,mr->messages);
|
||||
DeleteCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -447,11 +450,11 @@ static int NAS_AddRingMessage(MSG_RING* mr, enum win_wm_message msg, DWORD param
|
|||
HANDLE hEvent = INVALID_HANDLE_VALUE;
|
||||
|
||||
EnterCriticalSection(&mr->msg_crst);
|
||||
if ((mr->msg_toget == ((mr->msg_tosave + 1) % NAS_RING_BUFFER_SIZE))) /* buffer overflow? */
|
||||
if ((mr->msg_toget == ((mr->msg_tosave + 1) % mr->ring_buffer_size)))
|
||||
{
|
||||
ERR("buffer overflow !?\n");
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
return 0;
|
||||
mr->ring_buffer_size += NAS_RING_BUFFER_INCREMENT;
|
||||
TRACE("omr->ring_buffer_size=%d\n",mr->ring_buffer_size);
|
||||
mr->messages = HeapReAlloc(GetProcessHeap(),0,mr->messages, mr->ring_buffer_size * sizeof(RING_MSG));
|
||||
}
|
||||
if (wait)
|
||||
{
|
||||
|
@ -466,7 +469,7 @@ static int NAS_AddRingMessage(MSG_RING* mr, enum win_wm_message msg, DWORD param
|
|||
FIXME("two fast messages in the queue!!!!\n");
|
||||
|
||||
/* fast messages have to be added at the start of the queue */
|
||||
mr->msg_toget = (mr->msg_toget + NAS_RING_BUFFER_SIZE - 1) % NAS_RING_BUFFER_SIZE;
|
||||
mr->msg_toget = (mr->msg_toget + mr->ring_buffer_size - 1) % mr->ring_buffer_size;
|
||||
|
||||
mr->messages[mr->msg_toget].msg = msg;
|
||||
mr->messages[mr->msg_toget].param = param;
|
||||
|
@ -477,7 +480,7 @@ static int NAS_AddRingMessage(MSG_RING* mr, enum win_wm_message msg, DWORD param
|
|||
mr->messages[mr->msg_tosave].msg = msg;
|
||||
mr->messages[mr->msg_tosave].param = param;
|
||||
mr->messages[mr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
|
||||
mr->msg_tosave = (mr->msg_tosave + 1) % NAS_RING_BUFFER_SIZE;
|
||||
mr->msg_tosave = (mr->msg_tosave + 1) % mr->ring_buffer_size;
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
|
@ -514,7 +517,7 @@ static int NAS_RetrieveRingMessage(MSG_RING* mr,
|
|||
mr->messages[mr->msg_toget].msg = 0;
|
||||
*param = mr->messages[mr->msg_toget].param;
|
||||
*hEvent = mr->messages[mr->msg_toget].hEvent;
|
||||
mr->msg_toget = (mr->msg_toget + 1) % NAS_RING_BUFFER_SIZE;
|
||||
mr->msg_toget = (mr->msg_toget + 1) % mr->ring_buffer_size;
|
||||
LeaveCriticalSection(&mr->msg_crst);
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -129,11 +129,10 @@ typedef struct {
|
|||
* (compared to passing thru the server)
|
||||
* this ring will be used by the input (resp output) record (resp playback) routine
|
||||
*/
|
||||
#define OSS_RING_BUFFER_INCREMENT 64
|
||||
typedef struct {
|
||||
/* FIXME: this could be made a dynamically growing array (if needed) */
|
||||
/* maybe it's needed, a Humongous game manages to transmit 128 messages at once at startup */
|
||||
#define OSS_RING_BUFFER_SIZE 192
|
||||
OSS_MSG messages[OSS_RING_BUFFER_SIZE];
|
||||
int ring_buffer_size;
|
||||
OSS_MSG * messages;
|
||||
int msg_tosave;
|
||||
int msg_toget;
|
||||
#ifdef USE_PIPE_SYNC
|
||||
|
@ -844,7 +843,8 @@ static int OSS_InitRingMessage(OSS_MSG_RING* omr)
|
|||
#else
|
||||
omr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
|
||||
#endif
|
||||
memset(omr->messages, 0, sizeof(OSS_MSG) * OSS_RING_BUFFER_SIZE);
|
||||
omr->ring_buffer_size = OSS_RING_BUFFER_INCREMENT;
|
||||
omr->messages = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,omr->ring_buffer_size * sizeof(OSS_MSG));
|
||||
InitializeCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -861,6 +861,7 @@ static int OSS_DestroyRingMessage(OSS_MSG_RING* omr)
|
|||
#else
|
||||
CloseHandle(omr->msg_event);
|
||||
#endif
|
||||
HeapFree(GetProcessHeap(),0,omr->messages);
|
||||
DeleteCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
}
|
||||
|
@ -875,11 +876,11 @@ static int OSS_AddRingMessage(OSS_MSG_RING* omr, enum win_wm_message msg, DWORD
|
|||
HANDLE hEvent = INVALID_HANDLE_VALUE;
|
||||
|
||||
EnterCriticalSection(&omr->msg_crst);
|
||||
if ((omr->msg_toget == ((omr->msg_tosave + 1) % OSS_RING_BUFFER_SIZE))) /* buffer overflow ? */
|
||||
if ((omr->msg_toget == ((omr->msg_tosave + 1) % omr->ring_buffer_size)))
|
||||
{
|
||||
ERR("buffer overflow !?\n");
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
return 0;
|
||||
omr->ring_buffer_size += OSS_RING_BUFFER_INCREMENT;
|
||||
TRACE("omr->ring_buffer_size=%d\n",omr->ring_buffer_size);
|
||||
omr->messages = HeapReAlloc(GetProcessHeap(),0,omr->messages, omr->ring_buffer_size * sizeof(OSS_MSG));
|
||||
}
|
||||
if (wait)
|
||||
{
|
||||
|
@ -894,7 +895,7 @@ static int OSS_AddRingMessage(OSS_MSG_RING* omr, enum win_wm_message msg, DWORD
|
|||
FIXME("two fast messages in the queue!!!!\n");
|
||||
|
||||
/* fast messages have to be added at the start of the queue */
|
||||
omr->msg_toget = (omr->msg_toget + OSS_RING_BUFFER_SIZE - 1) % OSS_RING_BUFFER_SIZE;
|
||||
omr->msg_toget = (omr->msg_toget + omr->ring_buffer_size - 1) % omr->ring_buffer_size;
|
||||
|
||||
omr->messages[omr->msg_toget].msg = msg;
|
||||
omr->messages[omr->msg_toget].param = param;
|
||||
|
@ -905,7 +906,7 @@ static int OSS_AddRingMessage(OSS_MSG_RING* omr, enum win_wm_message msg, DWORD
|
|||
omr->messages[omr->msg_tosave].msg = msg;
|
||||
omr->messages[omr->msg_tosave].param = param;
|
||||
omr->messages[omr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
|
||||
omr->msg_tosave = (omr->msg_tosave + 1) % OSS_RING_BUFFER_SIZE;
|
||||
omr->msg_tosave = (omr->msg_tosave + 1) % omr->ring_buffer_size;
|
||||
}
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
/* signal a new message */
|
||||
|
@ -939,7 +940,7 @@ static int OSS_RetrieveRingMessage(OSS_MSG_RING* omr,
|
|||
omr->messages[omr->msg_toget].msg = 0;
|
||||
*param = omr->messages[omr->msg_toget].param;
|
||||
*hEvent = omr->messages[omr->msg_toget].hEvent;
|
||||
omr->msg_toget = (omr->msg_toget + 1) % OSS_RING_BUFFER_SIZE;
|
||||
omr->msg_toget = (omr->msg_toget + 1) % omr->ring_buffer_size;
|
||||
CLEAR_OMR(omr);
|
||||
LeaveCriticalSection(&omr->msg_crst);
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue