break],
[AC_MSG_RESULT([no])
continue])
+
+ AC_MSG_CHECKING(boost atomic_flag support)
+ feature="boost atomic_flag"
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [#include <boost/atomic.hpp>],
+ [boost::atomic_flag run_flag;])],
+ [AC_MSG_RESULT([yes])
+ break],
+ [AC_MSG_RESULT([no])
+ continue])
done
])dnl AX_ISC_RPATH
std::cout << "Running: " << stream.str() << std::endl;
}
+ if (!isSingleThreaded()) {
+ std::cout << "Multi-thread mode enabled." << std::endl;
+ }
+
// Handle the local '-l' address/interface
if (!localname_.empty()) {
if (server_name_.empty()) {
#include <perfdhcp/receiver.h>
#include <perfdhcp/command_options.h>
+#include <util/threads/thread.h>
#include <dhcp/iface_mgr.h>
+#include <boost/bind.hpp>
+
using namespace std;
using namespace isc::dhcp;
if (single_threaded_) {
return;
}
- assert(run_flag_.test_and_set() == false);
- recv_thread_.reset(new thread{&Receiver::run, this});
+ if (run_flag_.test_and_set()) {
+ run_flag_.clear();
+ isc_throw(isc::Unexpected, "run_flag_ should be false.");
+ }
+ recv_thread_.reset(new util::thread::Thread(boost::bind(&Receiver::run, this)));
}
void
if (single_threaded_) {
return;
}
- // Clear flags to order the thread to stop its main loop.
- run_flag_.clear();
- // To be sure first check if thread is running and ready to be joined.
- if (recv_thread_->joinable()) {
- recv_thread_->join();
+ // If thread is running then...
+ if (run_flag_.test_and_set()) {
+ // Clear flags to order the thread to stop its main loop.
+ run_flag_.clear();
+ recv_thread_->wait();
}
}
void
Receiver::run() {
- assert(single_threaded_ == false);
+ if (single_threaded_) {
+ isc_throw(isc::Unexpected, "run should not be invoked in single-thread mode.");
+ }
try {
// If the flag is still true receive packets.
while (run_flag_.test_and_set()) {
receivePackets();
}
+
+ // Clear run flag so that subsequent call to stop will not try to stop again.
+ run_flag_.clear();
} catch (const exception& e) {
cerr << "Something went wrong: " << e.what() << endl;
usleep(1000);
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
+#include <util/threads/thread.h>
#include <queue>
#include <thread>
boost::atomic_flag run_flag_;
/// \brief Thread for receiving packets.
- std::unique_ptr<std::thread> recv_thread_;
+ std::unique_ptr<util::thread::Thread> recv_thread_;
/// \brief Queue for passing packets from receiver thread to main thread.
std::queue<PktPtr> pkt_queue_;