thread function return type (#254)

typedef the return value of thread starting routines, as suggested by @loki666
This commit is contained in:
Philippe Simons 2017-10-26 18:08:10 +02:00 committed by Tom M
parent a1810385e1
commit cdd9f75112
8 changed files with 76 additions and 41 deletions

View file

@ -75,7 +75,7 @@ typedef struct {
const char *help; /**< A help string */
} fluid_cmd_int_t;
static int fluid_shell_run(fluid_shell_t* shell);
static fluid_thread_return_t fluid_shell_run(void* data);
static void fluid_shell_init(fluid_shell_t* shell,
fluid_settings_t* settings, fluid_cmd_handler_t* handler,
fluid_istream_t in, fluid_ostream_t out);
@ -270,7 +270,7 @@ new_fluid_shell(fluid_settings_t* settings, fluid_cmd_handler_t* handler,
fluid_shell_init(shell, settings, handler, in, out);
if (thread) {
shell->thread = new_fluid_thread("shell", (fluid_thread_func_t) fluid_shell_run, shell,
shell->thread = new_fluid_thread("shell", fluid_shell_run, shell,
0, TRUE);
if (shell->thread == NULL) {
delete_fluid_shell(shell);
@ -309,13 +309,14 @@ delete_fluid_shell(fluid_shell_t* shell)
FLUID_FREE(shell);
}
static int
fluid_shell_run(fluid_shell_t* shell)
static fluid_thread_return_t
fluid_shell_run(void* data)
{
fluid_shell_t* shell = (fluid_shell_t*)data;
char workline[FLUID_WORKLINELENGTH];
char* prompt = NULL;
int cont = 1;
int errors = 0;
int errors = FALSE;
int n;
if (shell->settings)
@ -343,7 +344,7 @@ fluid_shell_run(fluid_shell_t* shell)
break;
case -1: /* erronous command */
errors++;
errors |= TRUE;
case 0: /* valid command */
break;
@ -359,7 +360,7 @@ fluid_shell_run(fluid_shell_t* shell)
if (prompt) FLUID_FREE (prompt); /* -- free prompt */
return errors;
return errors ? (fluid_thread_return_t)(-1) : FLUID_THREAD_RETURN_VALUE;
}
/**
@ -380,7 +381,7 @@ fluid_usershell(fluid_settings_t* settings, fluid_cmd_handler_t* handler)
* Execute shell commands in a file.
* @param handler Command handler callback
* @param filename File name
* @return 0 on success, a value >1 on error
* @return 0 on success, a negative value on error
*/
int
fluid_source(fluid_cmd_handler_t* handler, const char *filename)
@ -398,7 +399,7 @@ fluid_source(fluid_cmd_handler_t* handler, const char *filename)
return file;
}
fluid_shell_init(&shell, NULL, handler, file, fluid_get_stdout());
result = fluid_shell_run(&shell);
result = (fluid_shell_run(&shell) == FLUID_THREAD_RETURN_VALUE) ? 0 : -1;
#ifdef WIN32
_close(file);
@ -2472,9 +2473,11 @@ struct _fluid_client_t {
};
static void fluid_client_run(fluid_client_t* client)
static fluid_thread_return_t fluid_client_run(void* data)
{
fluid_shell_t shell;
fluid_client_t* client = (fluid_client_t*)data;
fluid_shell_init(&shell,
client->settings,
client->handler,
@ -2483,6 +2486,8 @@ static void fluid_client_run(fluid_client_t* client)
fluid_shell_run(&shell);
fluid_server_remove_client(client->server, client);
delete_fluid_client(client);
return FLUID_THREAD_RETURN_VALUE;
}
@ -2501,7 +2506,7 @@ new_fluid_client(fluid_server_t* server, fluid_settings_t* settings, fluid_socke
client->socket = sock;
client->settings = settings;
client->handler = new_fluid_cmd_handler(server->synth, server->router);
client->thread = new_fluid_thread("client", (fluid_thread_func_t) fluid_client_run, client,
client->thread = new_fluid_thread("client", fluid_client_run, client,
0, FALSE);
if (client->handler == NULL || client->thread == NULL) {

View file

@ -72,8 +72,8 @@ fluid_audio_driver_t* new_fluid_alsa_audio_driver2(fluid_settings_t* settings,
int delete_fluid_alsa_audio_driver(fluid_audio_driver_t* p);
void fluid_alsa_audio_driver_settings(fluid_settings_t* settings);
static void fluid_alsa_audio_run_float(void* d);
static void fluid_alsa_audio_run_s16(void* d);
static fluid_thread_return_t fluid_alsa_audio_run_float(void* d);
static fluid_thread_return_t fluid_alsa_audio_run_s16(void* d);
struct fluid_alsa_formats_t {
@ -118,7 +118,7 @@ fluid_midi_driver_t* new_fluid_alsa_rawmidi_driver(fluid_settings_t* settings,
void* event_handler_data);
int delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p);
static void fluid_alsa_midi_run(void* d);
static fluid_thread_return_t fluid_alsa_midi_run(void* d);
/*
@ -139,7 +139,7 @@ fluid_midi_driver_t* new_fluid_alsa_seq_driver(fluid_settings_t* settings,
handle_midi_event_func_t handler,
void* data);
int delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p);
static void fluid_alsa_seq_run(void* d);
static fluid_thread_return_t fluid_alsa_seq_run(void* d);
/**************************************************************
*
@ -377,7 +377,7 @@ static int fluid_alsa_handle_write_error (snd_pcm_t *pcm, int errval)
return FLUID_OK;
}
static void fluid_alsa_audio_run_float (void *d)
static fluid_thread_return_t fluid_alsa_audio_run_float (void *d)
{
fluid_alsa_audio_driver_t* dev = (fluid_alsa_audio_driver_t*) d;
fluid_synth_t *synth = (fluid_synth_t *)(dev->data);
@ -450,9 +450,11 @@ static void fluid_alsa_audio_run_float (void *d)
FLUID_FREE(left);
FLUID_FREE(right);
return FLUID_THREAD_RETURN_VALUE;
}
static void fluid_alsa_audio_run_s16 (void *d)
static fluid_thread_return_t fluid_alsa_audio_run_s16 (void *d)
{
fluid_alsa_audio_driver_t* dev = (fluid_alsa_audio_driver_t*) d;
float* left;
@ -535,6 +537,8 @@ static void fluid_alsa_audio_run_s16 (void *d)
FLUID_FREE(left);
FLUID_FREE(right);
FLUID_FREE(buf);
return FLUID_THREAD_RETURN_VALUE;
}
@ -674,7 +678,7 @@ delete_fluid_alsa_rawmidi_driver(fluid_midi_driver_t* p)
/*
* fluid_alsa_midi_run
*/
void
fluid_thread_return_t
fluid_alsa_midi_run(void* d)
{
fluid_midi_event_t* evt;
@ -706,6 +710,8 @@ fluid_alsa_midi_run(void* d)
}
}
}
return FLUID_THREAD_RETURN_VALUE;
}
/**************************************************************
@ -953,7 +959,7 @@ delete_fluid_alsa_seq_driver(fluid_midi_driver_t* p)
/*
* fluid_alsa_seq_run
*/
void
fluid_thread_return_t
fluid_alsa_seq_run(void* d)
{
int n, ev;
@ -1046,6 +1052,8 @@ fluid_alsa_seq_run(void* d)
while (ev > 0);
} /* if poll() > 0 */
} /* while (!dev->should_quit) */
return FLUID_THREAD_RETURN_VALUE;
}
#endif /* #if ALSA_SUPPORT */

View file

@ -77,8 +77,8 @@ int delete_fluid_oss_audio_driver(fluid_audio_driver_t* p);
/* local utilities */
static int fluid_oss_set_queue_size(fluid_oss_audio_driver_t* dev, int ss, int ch, int qs, int bs);
static void fluid_oss_audio_run(void* d);
static void fluid_oss_audio_run2(void* d);
static fluid_thread_return_t fluid_oss_audio_run(void* d);
static fluid_thread_return_t fluid_oss_audio_run2(void* d);
typedef struct {
@ -95,7 +95,7 @@ new_fluid_oss_midi_driver(fluid_settings_t* settings,
handle_midi_event_func_t handler, void* data);
int delete_fluid_oss_midi_driver(fluid_midi_driver_t* p);
int fluid_oss_midi_driver_status(fluid_midi_driver_t* p);
static void fluid_oss_midi_run(void* d);
static fluid_thread_return_t fluid_oss_midi_run(void* d);
void
@ -441,7 +441,7 @@ fluid_oss_set_queue_size(fluid_oss_audio_driver_t* dev, int ss, int ch, int qs,
/*
* fluid_oss_audio_run
*/
void
fluid_thread_return_t
fluid_oss_audio_run(void* d)
{
fluid_oss_audio_driver_t* dev = (fluid_oss_audio_driver_t*) d;
@ -463,13 +463,15 @@ fluid_oss_audio_run(void* d)
}
FLUID_LOG(FLUID_DBG, "Audio thread finished");
return FLUID_THREAD_RETURN_VALUE;
}
/*
* fluid_oss_audio_run
*/
void
fluid_thread_return_t
fluid_oss_audio_run2(void* d)
{
fluid_oss_audio_driver_t* dev = (fluid_oss_audio_driver_t*) d;
@ -498,6 +500,8 @@ fluid_oss_audio_run2(void* d)
}
FLUID_LOG(FLUID_DBG, "Audio thread finished");
return FLUID_THREAD_RETURN_VALUE;
}
@ -621,7 +625,7 @@ delete_fluid_oss_midi_driver(fluid_midi_driver_t* p)
/*
* fluid_oss_midi_run
*/
void
fluid_thread_return_t
fluid_oss_midi_run(void* d)
{
fluid_oss_midi_driver_t* dev = (fluid_oss_midi_driver_t*) d;
@ -668,6 +672,8 @@ fluid_oss_midi_run(void* d)
}
}
}
return FLUID_THREAD_RETURN_VALUE;
}
int

View file

@ -55,8 +55,8 @@ fluid_audio_driver_t* new_fluid_pulse_audio_driver2(fluid_settings_t* settings,
fluid_audio_func_t func, void* data);
int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p);
void fluid_pulse_audio_driver_settings(fluid_settings_t* settings);
static void fluid_pulse_audio_run(void* d);
static void fluid_pulse_audio_run2(void* d);
static fluid_thread_return_t fluid_pulse_audio_run(void* d);
static fluid_thread_return_t fluid_pulse_audio_run2(void* d);
void fluid_pulse_audio_driver_settings(fluid_settings_t* settings)
@ -196,7 +196,7 @@ int delete_fluid_pulse_audio_driver(fluid_audio_driver_t* p)
}
/* Thread without audio callback, more efficient */
static void
static fluid_thread_return_t
fluid_pulse_audio_run(void* d)
{
fluid_pulse_audio_driver_t* dev = (fluid_pulse_audio_driver_t*) d;
@ -212,7 +212,7 @@ fluid_pulse_audio_run(void* d)
if (buf == NULL)
{
FLUID_LOG(FLUID_ERR, "Out of memory.");
return;
return FLUID_THREAD_RETURN_VALUE;
}
while (dev->cont)
@ -228,9 +228,11 @@ fluid_pulse_audio_run(void* d)
} /* while (dev->cont) */
FLUID_FREE(buf);
return FLUID_THREAD_RETURN_VALUE;
}
static void
static fluid_thread_return_t
fluid_pulse_audio_run2(void* d)
{
fluid_pulse_audio_driver_t* dev = (fluid_pulse_audio_driver_t*) d;
@ -254,7 +256,7 @@ fluid_pulse_audio_run2(void* d)
FLUID_FREE(right);
FLUID_FREE(buf);
FLUID_LOG(FLUID_ERR, "Out of memory.");
return;
return FLUID_THREAD_RETURN_VALUE;
}
handle[0] = left;
@ -282,4 +284,6 @@ fluid_pulse_audio_run2(void* d)
FLUID_FREE(left);
FLUID_FREE(right);
FLUID_FREE(buf);
return FLUID_THREAD_RETURN_VALUE;
}

View file

@ -76,7 +76,7 @@ int delete_fluid_winmidi_driver(fluid_midi_driver_t* p);
void CALLBACK fluid_winmidi_callback(HMIDIIN hmi, UINT wMsg, DWORD_PTR dwInstance,
DWORD_PTR msg, DWORD_PTR extra);
static void fluid_winmidi_add_sysex_thread (void *data);
static fluid_thread_return_t fluid_winmidi_add_sysex_thread (void *data);
static char* fluid_winmidi_input_error(int no);
int fluid_winmidi_driver_status(fluid_midi_driver_t* p);
@ -339,7 +339,7 @@ fluid_winmidi_callback(HMIDIIN hmi, UINT wMsg, DWORD_PTR dwInstance,
}
/* Thread for re-adding SYSEX buffers */
static void
static fluid_thread_return_t
fluid_winmidi_add_sysex_thread (void *data)
{
fluid_winmidi_driver_t *dev = data;
@ -360,6 +360,8 @@ fluid_winmidi_add_sysex_thread (void *data)
}
}
}
return FLUID_THREAD_RETURN_VALUE;
}
int

View file

@ -715,7 +715,7 @@ fluid_mixer_get_mt_rvoice(fluid_rvoice_mixer_t* mixer)
#define THREAD_BUF_TERMINATE 3
/* Core thread function (processes voices in parallel to primary synthesis thread) */
static void
static fluid_thread_return_t
fluid_mixer_thread_func (void* data)
{
fluid_mixer_buffers_t* buffers = data;
@ -756,6 +756,7 @@ fluid_mixer_thread_func (void* data)
}
}
return FLUID_THREAD_RETURN_VALUE;
}
static void

View file

@ -661,7 +661,7 @@ fluid_thread_join(fluid_thread_t* thread)
}
void
fluid_thread_return_t
fluid_timer_run (void *data)
{
fluid_timer_t *timer;
@ -694,7 +694,7 @@ fluid_timer_run (void *data)
if (timer->auto_destroy)
FLUID_FREE (timer);
return;
return FLUID_THREAD_RETURN_VALUE;
}
fluid_timer_t*
@ -959,7 +959,7 @@ void fluid_socket_close(fluid_socket_t sock)
close (sock);
}
static void
static fluid_thread_return_t
fluid_server_socket_run (void *data)
{
fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data;
@ -989,7 +989,7 @@ fluid_server_socket_run (void *data)
FLUID_LOG(FLUID_ERR, "Failed to accept connection");
server_socket->cont = 0;
return;
return FLUID_THREAD_RETURN_VALUE;
} else {
#ifdef HAVE_INETNTOP
#ifdef IPV6_SUPPORT
@ -1012,6 +1012,8 @@ fluid_server_socket_run (void *data)
}
FLUID_LOG(FLUID_DBG, "Server closing");
return FLUID_THREAD_RETURN_VALUE;
}
fluid_server_socket_t*
@ -1122,7 +1124,7 @@ void fluid_socket_close (fluid_socket_t sock)
closesocket (sock);
}
static void fluid_server_socket_run (void *data)
static fluid_thread_return_t fluid_server_socket_run (void *data)
{
fluid_server_socket_t *server_socket = (fluid_server_socket_t *)data;
fluid_socket_t client_socket;
@ -1153,7 +1155,7 @@ static void fluid_server_socket_run (void *data)
FLUID_LOG (FLUID_ERR, "Failed to accept connection: %ld", WSAGetLastError ());
server_socket->cont = 0;
return;
return FLUID_THREAD_RETURN_VALUE;
}
else
{
@ -1177,6 +1179,8 @@ static void fluid_server_socket_run (void *data)
}
FLUID_LOG (FLUID_DBG, "Server closing");
return FLUID_THREAD_RETURN_VALUE;
}
fluid_server_socket_t*

View file

@ -291,8 +291,13 @@ fluid_atomic_float_get(volatile float *fptr)
/* Threads */
/* other thread implementations might change this for their needs */
typedef void* fluid_thread_return_t;
/* static return value for thread functions which requires a return value */
#define FLUID_THREAD_RETURN_VALUE (NULL)
typedef GThread fluid_thread_t;
typedef void (*fluid_thread_func_t)(void* data);
typedef fluid_thread_return_t (*fluid_thread_func_t)(void* data);
#define FLUID_THREAD_ID_NULL NULL /* A NULL "ID" value */
#define fluid_thread_id_t GThread * /* Data type for a thread ID */