diff --git a/CMakeLists.txt b/CMakeLists.txt index 2daf374..ef370b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(SHADOWD) # Version set(SHADOWD_MAJOR_VERSION 1) set(SHADOWD_MINOR_VERSION 1) -set(SHADOWD_PATCH_VERSION 0) +set(SHADOWD_PATCH_VERSION 1) set(SHADOWD_VERSION ${SHADOWD_MAJOR_VERSION}.${SHADOWD_MINOR_VERSION}.${SHADOWD_PATCH_VERSION}) diff --git a/Doxyfile b/Doxyfile index 3a625a1..2eabf1d 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "Shadow Daemon" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "1.1.0" +PROJECT_NUMBER = "1.1.1" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/include/storage.h b/include/storage.h index 8735ad4..26bc850 100644 --- a/include/storage.h +++ b/include/storage.h @@ -46,11 +46,21 @@ namespace swd { class storage : public swd::singleton { public: + /** + * @brief Initialize the storage object. + */ + storage(); + /** * @brief Start insert thread. */ void start(); + /** + * @brief Gracefully stop process_next. + */ + void stop(); + /** * @brief Add request to insert queue. * @@ -85,6 +95,11 @@ namespace swd { * @brief Thread that constantly checks queue for new entries. */ boost::thread worker_thread_; + + /** + * @brief Switch to exit process_next loop. + */ + bool stop_; }; } diff --git a/src/server.cpp b/src/server.cpp index ff8a075..e6d9739 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -37,6 +37,7 @@ #include #include "server.h" +#include "storage.h" #include "config.h" #include "log.h" #include "shared.h" @@ -174,5 +175,9 @@ void swd::server::handle_accept(const boost::system::error_code& e) { } void swd::server::handle_stop() { + /* Stop the threads of asio. */ io_service_.stop(); + + /* Also stop the storage thread. */ + swd::storage::i()->stop(); } diff --git a/src/storage.cpp b/src/storage.cpp index 7efc1be..4da7a4f 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -36,12 +36,20 @@ #include "database.h" #include "log.h" +swd::storage::storage() : + stop_(false) { +} + void swd::storage::start() { worker_thread_ = boost::thread( boost::bind(&swd::storage::process_next, this) ); } +void swd::storage::stop() { + stop_ = true; +} + void swd::storage::add(swd::request_ptr request) { /* Mutex to avoid race conditions. */ boost::unique_lock scoped_lock(queue_mutex_); @@ -51,7 +59,7 @@ void swd::storage::add(swd::request_ptr request) { } void swd::storage::process_next() { - while (1) { + while (!stop_) { queue_mutex_.lock(); if (!queue_.empty()) {