Skip to content

Commit

Permalink
Revert part of rationalizing input synchronization between main threa…
Browse files Browse the repository at this point in the history
…d and output thread

Making output_read_reply set waiting_for_reply itself means we set it
after sending the command, and then the event thread might be getting
the reply before we get to set waiting_for_reply.
  • Loading branch information
sthibaul committed Jul 10, 2024
1 parent 950589d commit 886704e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/server/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ GString *output_read_reply(OutputModule * output)
{
GString *message = NULL;
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = TRUE;
while (!message) {
while (output->reading_message && !output->reply)
/* Somebody reading events, wait for it */
Expand Down Expand Up @@ -331,7 +330,6 @@ GString *output_read_reply(OutputModule * output)
}
}
}
output->waiting_for_reply = FALSE;
pthread_mutex_unlock(&output->read_mutex);
return message;
}
Expand Down Expand Up @@ -399,9 +397,20 @@ int output_send_data(const char *cmd, OutputModule * output, int wfr)
if (cmd == NULL)
return -1;

if (wfr) {
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = TRUE;
pthread_mutex_unlock(&output->read_mutex);
}

ret = safe_write(output->pipe_in[1], cmd, strlen(cmd));
if (ret == -1) {
MSG(2, "Error: Broken pipe to module while sending data.");
if (wfr) {
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = FALSE;
pthread_mutex_unlock(&output->read_mutex);
}

output->working = 0;
output_check_module(output);
Expand All @@ -413,6 +422,9 @@ int output_send_data(const char *cmd, OutputModule * output, int wfr)
if (wfr) { /* wait for reply? */
int ret = 0;
response = output_read_reply(output);
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = FALSE;
pthread_mutex_unlock(&output->read_mutex);
if (response == NULL)
return -1;

Expand Down Expand Up @@ -492,14 +504,24 @@ SPDVoice **output_get_voices(OutputModule * output, const char *language, const
language && variant ? " " : "",
variant ? variant : "");
retry:
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = TRUE;
pthread_mutex_unlock(&output->read_mutex);

err = output_send_data(command, output, 0);
if (command != all_command)
free(command);
if (err < 0) {
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = FALSE;
pthread_mutex_unlock(&output->read_mutex);
output_unlock();
return NULL;
}
reply = output_read_reply(output);
pthread_mutex_lock(&output->read_mutex);
output->waiting_for_reply = FALSE;
pthread_mutex_unlock(&output->read_mutex);

if (reply == NULL) {
output_unlock();
Expand Down

0 comments on commit 886704e

Please sign in to comment.