Use the new AmThread facilities to get notified about shutdown. Use the
new `run_mut` in place of the existing mutex to protect `thread_list`
Stop watcher thread from main thread on shutdown.
Change-Id: I4214a5d2324dd7d7d5a424e425d3e2d0ef20aa14
Add a central mutex and condition variable to AmThread, which can be
used by subclasses in their ::run() to determine whether they should
sleep, run, or shut down. This will replace identical mechanism in
subclasses that have this implemented on their own.
Subclasses which don't need this are not affected.
Add `_state` to the list of members protected by this mutex, obsoleting
the need for atomic ops.
Refactor `_joined` as an enum state, also protected by run_mutex,
replacing the separate mutex. Use run_cond as signal to wake up thread
waiting on the join to the complete.
Notify this cond on shutdown, after setting the state to "stopping."
Add ::stop_requested_unlocked() for threads which use `run_mut`.
Change-Id: I0b640b54c9f601e86cbb25413cacb67e31fbe913
In some cases it can happen that ::join() is called from multiple
threads at the same time. Checking the ::joinable() flag is not
race-free and so is unreliable to make sure that only one other thread
attempts to join at any given time. Add a mutex and a state variable to
make sure only one thread attempts to join, and make any other threads
wait.
Change-Id: I02fd236a416b035c98642535f1521be4a3a63fd9
Request a thread shutdown in the dtor in case the thread is still
running. Prevents destruction of std::thread with an active thread.
Change-Id: I51c4a43cf8d6402f4a690add936c95c2f700129d
Provide a single place for a running thread to check if it ought to shut
down. Use it in AmThreadWatcher.
Change-Id: I206111b34e3c658f0c2ce55627274b463b1e98d5
Use a std::list instead of a std::queue so that we can use iterators,
which allows us to delete elements directly without having to rebuild a
new queue with every loop iteration. This eliminates the n_thread_queue
and the swap.
Eliminate the wait condition _run_cond. This is only woken up when a
thread is added, which we don't care about. We only care when a thread
finishes, and there is no condition for that.
Use a lock guard. With this we can make sure the lock is in a consistent
state in case of an exception. Still catch and report exceptions.
Remove stub methods.
Change-Id: I59903f6a03863e5c106631e3db8706109915c8fb
Use an atomic enum to track state: idle, running, stopping, or stopped.
Use atomic compare and exchange to ensure consistency without requiring
a mutex.
Never detach threads. Always require a join. This makes for an easy and
reliable way to wait for a thread to finish.
Provide a default on_stop so that it can be omitted in child classes.
Change-Id: Id59942638b7f769090ac91c2049b7d934e876ffc
Re-implement AmMutex as a subclass of std::mutex. Provide copy and
assignment constructors so that it can be used as a member of another
class without preventing it from being copy/assignment constructed.
Change-Id: Id300a6501105a7871396c2be9380d6e0eae02cc7
- splits the interface to the outer world from the core:
- use binrpcctrl plugin for SASI interface, or
- unixsockctrl for the good old unix socket interface.
git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@568 8eb893ce-cfd4-0310-b710-fb5ebe64c474
The patch is developed on FreeBSD 4.11-RELEASE and gcc 2.95.4, but is
expected to run on other BSD systems as well.
Note that it is "not done" to replace the gcc in a BSD base system,
hence the support for an older gcc.
The changes are minor:
* corrections in typing matters, including more header files
* alternative handling option for varargs in #define for pre-GCC3
* lowering the default UNIX_PATH_MAX value to 104 instead of 108
* clearing memory intended to store socket addresses
* a few remarks for FreeBSD-adopters and/or porters
git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@39 8eb893ce-cfd4-0310-b710-fb5ebe64c474