I added a void* data field to fluid_event_t to store the data pointer

of timer events instead of storing it in the duration field.
The event heap now allocates the events dynamically. It preallocates a
number of events in the init function, as before. More events are allocated
as needed. I also added a mutex to protected the free list from concurrent
access.
This commit is contained in:
Peter Hanappe 2004-01-06 09:51:30 +00:00
parent 8628e7aae8
commit 9444b03d43
3 changed files with 266 additions and 61 deletions

View File

@ -1,174 +1,275 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
/* Define to enable ALSA driver */
/*
Define to enable ALSA driver */
#undef ALSA_SUPPORT
/* whether or not we are supporting CoreAudio */
/*
whether or not we are supporting CoreAudio */
#undef COREAUDIO_SUPPORT
/* Define if building for Mac OS X Darwin */
/*
Define if building for Mac OS X Darwin
*/
#undef DARWIN
/* Define to activate debugging message */
/*
Define to activate debugging message */
#undef DEBUG
/* Use the SSE instructions of Pentium 3 and higher */
/*
Use the SSE instructions of Pentium 3 and
higher */
#undef ENABLE_SSE
/* Define to 1 if you have the <arpa/inet.h> header file. */
/*
Define to 1 if you have the <arpa/inet.h>
header file. */
#undef HAVE_ARPA_INET_H
/* Define to 1 if you have the <dlfcn.h> header file. */
/*
Define to 1 if you have the <dlfcn.h>
header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <errno.h> header file. */
/*
Define to 1 if you have the <errno.h>
header file. */
#undef HAVE_ERRNO_H
/* Define to 1 if you have the <fcntl.h> header file. */
/*
Define to 1 if you have the <fcntl.h>
header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the <inttypes.h> header file. */
/*
Define to 1 if you have the <inttypes.h>
header file. */
#undef HAVE_INTTYPES_H
/* whether or not we are supporting ladcca */
/*
whether or not we are supporting ladcca */
#undef HAVE_LADCCA
/* Define to 1 if you have the `dl' library (-ldl). */
/*
Define to 1 if you have the `dl'
library (-ldl). */
#undef HAVE_LIBDL
/* Define to 1 if you have the `MidiShare' library (-lMidiShare). */
/*
Define to 1 if you have the `MidiShare'
library (-lMidiShare). */
#undef HAVE_LIBMIDISHARE
/* Define to 1 if you have the `pthread' library (-lpthread). */
/*
Define to 1 if you have the `pthread'
library (-lpthread). */
#undef HAVE_LIBPTHREAD
/* Define to 1 if you have the <limits.h> header file. */
/*
Define to 1 if you have the <limits.h>
header file. */
#undef HAVE_LIMITS_H
/* Define to 1 if you have the <machine/soundcard.h> header file. */
/*
Define to 1 if you have the <machine/soundcard.h>
header file. */
#undef HAVE_MACHINE_SOUNDCARD_H
/* Define to 1 if you have the <math.h> header file. */
/*
Define to 1 if you have the <math.h>
header file. */
#undef HAVE_MATH_H
/* Define to 1 if you have the <memory.h> header file. */
/*
Define to 1 if you have the <memory.h>
header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <MidiShare.h> header file. */
/*
Define to 1 if you have the <MidiShare.h>
header file. */
#undef HAVE_MIDISHARE_H
/* Define to 1 if you have the <netinet/in.h> header file. */
/*
Define to 1 if you have the <netinet/in.h>
header file. */
#undef HAVE_NETINET_IN_H
/* Define to 1 if you have the <netinet/tcp.h> header file. */
/*
Define to 1 if you have the <netinet/tcp.h>
header file. */
#undef HAVE_NETINET_TCP_H
/* Define to 1 if you have the <pthread.h> header file. */
/*
Define to 1 if you have the <pthread.h>
header file. */
#undef HAVE_PTHREAD_H
/* Define to 1 if you have the <signal.h> header file. */
/*
Define to 1 if you have the <signal.h>
header file. */
#undef HAVE_SIGNAL_H
/* Define to 1 if you have the <stdarg.h> header file. */
/*
Define to 1 if you have the <stdarg.h>
header file. */
#undef HAVE_STDARG_H
/* Define to 1 if you have the <stdint.h> header file. */
/*
Define to 1 if you have the <stdint.h>
header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdio.h> header file. */
/*
Define to 1 if you have the <stdio.h>
header file. */
#undef HAVE_STDIO_H
/* Define to 1 if you have the <stdlib.h> header file. */
/*
Define to 1 if you have the <stdlib.h>
header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
/*
Define to 1 if you have the <strings.h>
header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
/*
Define to 1 if you have the <string.h>
header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
/*
Define to 1 if you have the <sys/ioctl.h>
header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/mman.h> header file. */
/*
Define to 1 if you have the <sys/mman.h>
header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/socket.h> header file. */
/*
Define to 1 if you have the <sys/socket.h>
header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/soundcard.h> header file. */
/*
Define to 1 if you have the <sys/soundcard.h>
header file. */
#undef HAVE_SYS_SOUNDCARD_H
/* Define to 1 if you have the <sys/stat.h> header file. */
/*
Define to 1 if you have the <sys/stat.h>
header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/time.h> header file. */
/*
Define to 1 if you have the <sys/time.h>
header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
/*
Define to 1 if you have the <sys/types.h>
header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
/*
Define to 1 if you have the <unistd.h>
header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <windows.h> header file. */
/*
Define to 1 if you have the <windows.h>
header file. */
#undef HAVE_WINDOWS_H
/* Define to enable JACK driver */
/*
Define to enable JACK driver */
#undef JACK_SUPPORT
/* Include the LADSPA Fx unit */
/*
Include the LADSPA Fx unit */
#undef LADSPA
/* Define to enable MidiShare driver */
/*
Define to enable MidiShare driver */
#undef MIDISHARE_SUPPORT
/* Define if using the MinGW32 environment */
/*
Define if using the MinGW32 environment */
#undef MINGW32
/* Define to enable OSS driver */
/*
Define to enable OSS driver */
#undef OSS_SUPPORT
/* Name of package */
/*
Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
/*
Define to the address where bug reports for
this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
/*
Define to the full name of this package.
*/
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
/*
Define to the full name and version of
this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
/*
Define to the one symbol short name of
this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
/*
Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
/*
Define to 1 if you have the ANSI
C header files. */
#undef STDC_HEADERS
/* Define to use long long type, where appropriate */
/*
Define to use long long type, where appropriate
*/
#undef USE_LONGLONG
/* Version number of package */
/*
Version number of package */
#undef VERSION
/* Define to do all DSP in single floating point precision */
/*
Define to do all DSP in single floating
point precision */
#undef WITH_FLOAT
/* Define to profile the DSP code */
/*
Define to profile the DSP code */
#undef WITH_PROFILING
/* Define to use the readline library for line editing */
/*
Define to use the readline library for line
editing */
#undef WITH_READLINE
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
/*
Define to 1 if your processor stores words
with the most significant byte first (like Motorola and
SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Define as `__inline' if that's what the C compiler calls it, or to nothing
if it is not supported. */
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif

View File

@ -94,7 +94,7 @@ void
fluid_event_timer(fluid_event_t* evt, void* data)
{
evt->type = FLUID_SEQ_TIMER;
evt->duration = (unsigned int)data;
evt->data = data;
}
@ -310,7 +310,7 @@ short fluid_event_get_value(fluid_event_t* evt)
void* fluid_event_get_data(fluid_event_t* evt)
{
return (void *)(evt->duration);
return evt->data;
}
unsigned int fluid_event_get_duration(fluid_event_t* evt)
@ -345,6 +345,36 @@ fluid_event_get_sfont_id(fluid_event_t* evt)
fluid_evt_heap_t*
_fluid_evt_heap_init(int nbEvents)
{
#ifdef HEAP_WITH_DYNALLOC
int i;
fluid_evt_heap_t* heap;
fluid_evt_entry *tmp;
heap = FLUID_NEW(fluid_evt_heap_t);
if (heap == NULL) {
fluid_log(FLUID_PANIC, "sequencer: Out of memory\n");
return NULL;
}
heap->freelist = NULL;
fluid_mutex_init(heap->mutex);
/* LOCK */
fluid_mutex_lock(heap->mutex);
/* Allocate the event entries */
for (i = 0; i < nbEvents; i++) {
tmp = FLUID_NEW(fluid_evt_entry);
tmp->next = heap->freelist;
heap->freelist = tmp;
}
/* UNLOCK */
fluid_mutex_unlock(heap->mutex);
#else
int i;
fluid_evt_heap_t* heap;
int siz = 2*sizeof(fluid_evt_entry *) + sizeof(fluid_evt_entry)*nbEvents;
@ -367,18 +397,68 @@ _fluid_evt_heap_init(int nbEvents)
heap->tail = &(tmp[nbEvents-1]);
heap->head = &(heap->pool);
}
#endif
return (heap);
}
void
_fluid_evt_heap_free(fluid_evt_heap_t* heap)
{
#ifdef HEAP_WITH_DYNALLOC
fluid_evt_entry *tmp, *next;
/* LOCK */
fluid_mutex_lock(heap->mutex);
tmp = heap->freelist;
while (tmp) {
next = tmp->next;
FLUID_FREE(tmp);
tmp = next;
}
/* UNLOCK */
fluid_mutex_unlock(heap->mutex);
fluid_mutex_destroy(heap->mutex);
FLUID_FREE(heap);
#else
FLUID_FREE(heap);
#endif
}
fluid_evt_entry*
_fluid_seq_heap_get_free(fluid_evt_heap_t* heap)
{
#ifdef HEAP_WITH_DYNALLOC
fluid_evt_entry* evt = NULL;
/* LOCK */
fluid_mutex_lock(heap->mutex);
#if !defined(MACOS9)
if (heap->freelist == NULL) {
heap->freelist = FLUID_NEW(fluid_evt_entry);
if (heap->freelist != NULL) {
heap->freelist->next = NULL;
}
}
#endif
evt = heap->freelist;
if (evt != NULL) {
heap->freelist = heap->freelist->next;
evt->next = NULL;
}
/* UNLOCK */
fluid_mutex_unlock(heap->mutex);
return evt;
#else
fluid_evt_entry* evt;
if (heap->head == NULL) return NULL;
@ -388,14 +468,28 @@ _fluid_seq_heap_get_free(fluid_evt_heap_t* heap)
heap->head = heap->head->next;
return evt;
#endif
}
void
_fluid_seq_heap_set_free(fluid_evt_heap_t* heap, fluid_evt_entry* evt)
{
#ifdef HEAP_WITH_DYNALLOC
/* LOCK */
fluid_mutex_lock(heap->mutex);
evt->next = heap->freelist;
heap->freelist = evt;
/* UNLOCK */
fluid_mutex_unlock(heap->mutex);
#else
/* append to the end of the heap */
/* critical - should threadlock ? */
heap->tail->next = evt;
heap->tail = evt;
evt->next = NULL;
#endif
}

View File

@ -23,6 +23,7 @@
#define _FLUID_EVENT_PRIV_H
#include "fluidsynth.h"
#include "fluid_sys.h"
/* Private data for event */
/* ?? should be optimized in size, using unions */
@ -39,6 +40,7 @@ struct _fluid_event_t {
short id; //?? unused ?
int pitch;
unsigned int duration;
void* data;
};
unsigned int fluid_event_get_time(fluid_event_t* evt);
@ -57,10 +59,18 @@ struct _fluid_evt_entry {
fluid_event_t evt;
};
#define HEAP_WITH_DYNALLOC 1
/* #undef HEAP_WITH_DYNALLOC */
typedef struct _fluid_evt_heap_t {
#ifdef HEAP_WITH_DYNALLOC
fluid_evt_entry* freelist;
fluid_mutex_t mutex;
#else
fluid_evt_entry* head;
fluid_evt_entry* tail;
fluid_evt_entry pool;
#endif
} fluid_evt_heap_t;
fluid_evt_heap_t* _fluid_evt_heap_init(int nbEvents);