![]() |
Kea
1.5.0
|
Provides a thread and controls for monitoring its activities. More...
#include <watched_thread.h>
Public Types | |
| enum | WatchType { ERROR = 0, READY = 1, TERMINATE = 2 } |
| Enumerates the list of watch sockets used to mark events These are used as arguments to watch socket accessor methods. More... | |
Public Member Functions | |
| WatchedThread () | |
| Constructor. More... | |
| virtual | ~WatchedThread () |
| Virtual destructor. More... | |
| void | clearReady (WatchType watch_type) |
| Sets a watch socket state to not ready. More... | |
| std::string | getLastError () |
| Fetches the error message text for the most recent error. More... | |
| int | getWatchFd (WatchType watch_type) |
| Fetches the fd of a watch socket. More... | |
| bool | isReady (WatchType watch_type) |
| Indicates if a watch socket state is ready. More... | |
| bool | isRunning () |
| Returns true if the thread is running. More... | |
| void | markReady (WatchType watch_type) |
| Sets a watch socket state to ready. More... | |
| void | setError (const std::string &error_msg) |
| Sets the error state. More... | |
| bool | shouldTerminate () |
| Checks if the thread should terminate. More... | |
| void | start (const boost::function< void()> &thread_main) |
| Creates and runs the thread. More... | |
| void | stop () |
| Terminates the thread. More... | |
Public Attributes | |
| std::string | last_error_ |
| Error message of the last error encountered. More... | |
| WatchSocket | sockets_ [TERMINATE+1] |
WatchSockets that are used to communicate with the owning thread There are three:
| |
| thread::ThreadPtr | thread_ |
| Current thread instance. More... | |
Provides a thread and controls for monitoring its activities.
Given a "worker function", this class creates a thread which runs the function and provides the means to monitor the thread for "error" and "ready" conditions, and finally to stop the thread. It uses three WatchSockets: one to indicate an error, one to indicate data is ready, and a third to monitor as a shut-down command.
Definition at line 26 of file watched_thread.h.
Enumerates the list of watch sockets used to mark events These are used as arguments to watch socket accessor methods.
| Enumerator | |
|---|---|
| ERROR | |
| READY | |
| TERMINATE | |
Definition at line 30 of file watched_thread.h.
|
inline |
Constructor.
Definition at line 37 of file watched_thread.h.
|
inlinevirtual |
Virtual destructor.
Definition at line 40 of file watched_thread.h.
| void isc::util::thread::WatchedThread::clearReady | ( | WatchType | watch_type | ) |
Sets a watch socket state to not ready.
| watch_type | indicates which watch socket to clear |
Definition at line 39 of file watched_thread.cc.
References isc::util::WatchSocket::clearReady(), and sockets_.
Referenced by shouldTerminate(), start(), and stop().
Here is the call graph for this function:| std::string isc::util::thread::WatchedThread::getLastError | ( | ) |
Fetches the error message text for the most recent error.
Definition at line 73 of file watched_thread.cc.
References last_error_.
| int isc::util::thread::WatchedThread::getWatchFd | ( | WatchType | watch_type | ) |
Fetches the fd of a watch socket.
| watch_type | indicates which watch socket |
Definition at line 24 of file watched_thread.cc.
References sockets_.
| bool isc::util::thread::WatchedThread::isReady | ( | WatchType | watch_type | ) |
Indicates if a watch socket state is ready.
| watch_type | indicates which watch socket to mark |
Definition at line 34 of file watched_thread.cc.
References sockets_.
Referenced by shouldTerminate().
|
inline |
Returns true if the thread is running.
Definition at line 81 of file watched_thread.h.
References thread_.
| void isc::util::thread::WatchedThread::markReady | ( | WatchType | watch_type | ) |
Sets a watch socket state to ready.
| watch_type | indicates which watch socket to mark |
Definition at line 29 of file watched_thread.cc.
References isc::util::WatchSocket::markReady(), and sockets_.
Referenced by setError(), and stop().
Here is the call graph for this function:| void isc::util::thread::WatchedThread::setError | ( | const std::string & | error_msg | ) |
Sets the error state.
This records the given error message and sets the error watch socket to ready.
| error_msg |
Definition at line 67 of file watched_thread.cc.
References ERROR, last_error_, and markReady().
Here is the call graph for this function:| bool isc::util::thread::WatchedThread::shouldTerminate | ( | ) |
Checks if the thread should terminate.
Performs a "one-shot" check of the terminate watch socket. If it is ready, return true and then clear it, otherwise return false.
Definition at line 44 of file watched_thread.cc.
References clearReady(), isReady(), sockets_, and TERMINATE.
Here is the call graph for this function:| void isc::util::thread::WatchedThread::start | ( | const boost::function< void()> & | thread_main | ) |
Creates and runs the thread.
Creates the thread, passing into it the given function to run.
| thread_main | function the thread should run |
Definition at line 15 of file watched_thread.cc.
References clearReady(), ERROR, last_error_, READY, TERMINATE, and thread_.
Here is the call graph for this function:| void isc::util::thread::WatchedThread::stop | ( | ) |
Terminates the thread.
It marks the terminate watch socket ready, and then waits for the thread to stop. At this point, the thread is defunct. This is not done in the destructor to avoid race conditions.
Definition at line 54 of file watched_thread.cc.
References clearReady(), ERROR, last_error_, markReady(), READY, TERMINATE, and thread_.
Here is the call graph for this function:| std::string isc::util::thread::WatchedThread::last_error_ |
Error message of the last error encountered.
Definition at line 106 of file watched_thread.h.
Referenced by getLastError(), setError(), start(), and stop().
| WatchSocket isc::util::thread::WatchedThread::sockets_[TERMINATE+1] |
WatchSockets that are used to communicate with the owning thread There are three:
shouldTerminate Definition at line 116 of file watched_thread.h.
Referenced by clearReady(), getWatchFd(), isReady(), markReady(), and shouldTerminate().
| thread::ThreadPtr isc::util::thread::WatchedThread::thread_ |
Current thread instance.
Definition at line 119 of file watched_thread.h.
Referenced by isRunning(), start(), and stop().