If we processed an entry from the queue successfully, we were removing
the entry itself from the queue but not freeing the memory allocated to
the entry.
When espeak_Cancel is called, change the value of user_data that is
passed to the events, and, in the callback, use this to test to see if
cancel was received. If the value of user_data has changed, discarde
events that have the old value. This patch is from Chris Brannon.
The user_data parameter is just a pointer that is passed into the
espeak_synth call that is passed back to the callback. In native mode,
we are not using it since there is not a callback. However, in alsa
mode, it will be used to indicate when a cancel was processed.
The signal handler stopped working after I moved the initialization
calls to the main function. Creating the signal handler thread first
fixed this issue.
pthread_cond_wait() can have spurious wakeups, so we need to be sure
that the condition is actually true when we return from this function.
Thanks to Chris Brannon for the patch.
The only time queue_process_entry should lock the queue gard is when it
is removing the item from the queue. This happens only when the item
was successfully processed.
1. Don't lock or unlock queue_guard during queue_clear.
It is locked when queue_clear is called, and it should remain so.
2. Protect runner_must_stop with queue_guard in
the request_espeak_stop function.
The following condition should always hold: queue_guard is locked while
testing or modifying runner_must_stop.
3. Rename stop_guard to acknowledge_guard. This is a more
descriptive name. This mutex simply protects the acknowledgement of
the stop request from being lost.
4. Remove the pthread_mutex_lock from the top of queue_process_entry,
because queue_guard is already locked when the function is called.
Most of the idea for this change came from William:
Renamed queue_runner to espeak_thread. Moved espeak initialization
and termination to espeak_thread. The while loops that process
the queue now use the variable should_run.
The goal is to create threads for the reader, que runner/espeak
processing and signal handling.
As of this commit, this code is still being worked on, so it is broken.
This adds retry processing back to the queue functions. queue_remove
should only be called after the head entry on the queue is processed
successfully.