From 350d0b5071eb4ee0b13e865b2ae5d0c84ea1a213 Mon Sep 17 00:00:00 2001 From: karel-burda <38255062+karel-burda@users.noreply.github.com> Date: Tue, 29 May 2018 10:47:02 +0200 Subject: [PATCH 1/7] Fixed documentation [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a2f4a7..3950635 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ timer.start(2m, nullptr); ### Asynchronous single-shot ```cpp -timers::single_shot_async timer_async; +timers::single_shot_async timer; // this call is asynchronous timer.start(2s, [](){ std::cout << "Hi there" << std::endl; }); From cccd0043d8e49bd1d27d6afb9e3400779efe496f Mon Sep 17 00:00:00 2001 From: karel-burda <38255062+karel-burda@users.noreply.github.com> Date: Tue, 29 May 2018 12:23:05 +0200 Subject: [PATCH 2/7] Updated README [skip ci] --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3950635..c3aa420 100644 --- a/README.md +++ b/README.md @@ -139,14 +139,14 @@ private: class_that_uses_timers foo; foo.work(); -// "foo" goes out of scope, so the scoped timer (member of "foo") and its underlying -// asynchronous periodic timer will be stopped as well +// "foo" goes out of scope, so the scoped timer (member of "foo") will go out of scope as well +// and its underlying asynchronous periodic timer will be stopped ``` For full use cases, see [main.cpp](example/src/main.cpp) or implementation of unit tests at [tests/unit](tests/unit). # Build Process -Library itself is just header-only, so no need for additional linking, just `pthreads` have to be linked to the final executable on POSIX systems. +Library itself is just header-only, so no need for additional linking, just threading library might need to be linked to the final executable on most Linux standard library implementations. See section [Usage](#Usage) for more info. In order to build the usage example ([main.cpp](example/src/main.cpp)) run the cmake in the top-level directory like this: From 0099672c46d60d1d23babe464d39af6d1bb93aeb Mon Sep 17 00:00:00 2001 From: Karel Burda Date: Sun, 10 Jun 2018 20:43:58 +0200 Subject: [PATCH 3/7] Disabling copy and move helper classes splitted into 2 classes --- include/timers/async.h | 2 +- include/timers/blocking.h | 5 +++-- include/timers/private/disable_copy.h | 19 +++++++++++++++++++ .../timers/private/disable_copy_and_move.h | 18 ------------------ include/timers/private/disable_move.h | 19 +++++++++++++++++++ include/timers/private/type_traits.h | 3 +++ include/timers/scoped.h | 5 +++-- 7 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 include/timers/private/disable_copy.h delete mode 100644 include/timers/private/disable_copy_and_move.h create mode 100644 include/timers/private/disable_move.h diff --git a/include/timers/async.h b/include/timers/async.h index bbcf4fe..171f509 100644 --- a/include/timers/async.h +++ b/include/timers/async.h @@ -52,7 +52,7 @@ static_assert(std::is_same::value || std::is_same> m_async_task; + std::future> m_async_task; std::mutex m_async_protection; }; } diff --git a/include/timers/blocking.h b/include/timers/blocking.h index b760e17..d3cfb72 100644 --- a/include/timers/blocking.h +++ b/include/timers/blocking.h @@ -6,14 +6,15 @@ #include "timers/exceptions.h" #include "timers/type_definitions.h" -#include "timers/private/disable_copy_and_move.h" +#include "timers/private/disable_copy.h" +#include "timers/private/disable_move.h" namespace burda { namespace timers { /// Timer that blocks current thread for given amount of time -class blocking : disable_copy_and_move +class blocking : private detail::disable_copy, private detail::disable_move { public: /// Waits and blocks current thread until the "time" elapses OR client code calls "stop()" diff --git a/include/timers/private/disable_copy.h b/include/timers/private/disable_copy.h new file mode 100644 index 0000000..116656e --- /dev/null +++ b/include/timers/private/disable_copy.h @@ -0,0 +1,19 @@ +#pragma once + +namespace burda +{ +namespace timers +{ +namespace detail +{ +/// Helper class that enables default construction and disables copy operations +struct disable_copy +{ + disable_copy() = default; + + disable_copy(const disable_copy &) = delete; + disable_copy(disable_copy &&) = delete; +}; +} +} +} diff --git a/include/timers/private/disable_copy_and_move.h b/include/timers/private/disable_copy_and_move.h deleted file mode 100644 index 284f547..0000000 --- a/include/timers/private/disable_copy_and_move.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -namespace burda -{ -namespace timers -{ -/// Helper class that enables default construction and disables copy and move operations -struct disable_copy_and_move -{ - disable_copy_and_move() = default; - - disable_copy_and_move(const disable_copy_and_move &) = delete; - disable_copy_and_move(disable_copy_and_move &&) = delete; - disable_copy_and_move & operator=(const disable_copy_and_move &) = delete; - disable_copy_and_move & operator=(disable_copy_and_move &&) = delete; -}; -} -} diff --git a/include/timers/private/disable_move.h b/include/timers/private/disable_move.h new file mode 100644 index 0000000..fd479bd --- /dev/null +++ b/include/timers/private/disable_move.h @@ -0,0 +1,19 @@ +#pragma once + +namespace burda +{ +namespace timers +{ +namespace detail +{ +/// Helper class that enables default construction and disables move operations +struct disable_move +{ + disable_move() = default; + + disable_move & operator=(const disable_move &) = delete; + disable_move & operator=(disable_move &&) = delete; +}; +} +} +} diff --git a/include/timers/private/type_traits.h b/include/timers/private/type_traits.h index d95924c..63019df 100644 --- a/include/timers/private/type_traits.h +++ b/include/timers/private/type_traits.h @@ -6,6 +6,8 @@ namespace burda { namespace timers { +namespace detail +{ namespace traits { /// Helper structure to deduce return type of given method @@ -25,3 +27,4 @@ using return_type = typename return_type_templated::type; } } } +} diff --git a/include/timers/scoped.h b/include/timers/scoped.h index e566e8c..d40033a 100644 --- a/include/timers/scoped.h +++ b/include/timers/scoped.h @@ -2,7 +2,8 @@ #include -#include "timers/private/disable_copy_and_move.h" +#include "timers/private/disable_copy.h" +#include "timers/private/disable_move.h" namespace burda { @@ -11,7 +12,7 @@ namespace timers class blocking; template -class scoped : public disable_copy_and_move +class scoped : private detail::disable_copy, private detail::disable_move { /// We allow only timers to be scoped except for the "blocking" that doesn't make sence static_assert(!std::is_same::value, "Blocking timer is not allowed be scoped"); From 83526cd38911f506eb29a76bda97e2e1dfbd0eb5 Mon Sep 17 00:00:00 2001 From: Karel Burda Date: Sun, 10 Jun 2018 20:50:44 +0200 Subject: [PATCH 4/7] Fixed formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3aa420..d5abc3c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ * Its asynchronous version: `single_shot_async` * Timer that does some action periodically: `periodic` * Its asynchronous version: `periodic_async` -* Scoped "RAII" timer that stops underlying timer automatically upon destruction: `scoped` +* Scoped "RAII" timer that stops underlying timer automatically upon destruction: `scoped` Implemented using C++11 with the use of `std::conditional_variable`, `std::promise` and `std::async`. From d9eae1a8dd613d8bce3fbbfd4b7842cde1662f69 Mon Sep 17 00:00:00 2001 From: Karel Burda Date: Sun, 10 Jun 2018 20:54:45 +0200 Subject: [PATCH 5/7] Ensuring that exception is catched during the destructor --- include/timers/scoped.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/timers/scoped.h b/include/timers/scoped.h index d40033a..1330092 100644 --- a/include/timers/scoped.h +++ b/include/timers/scoped.h @@ -11,6 +11,8 @@ namespace timers { class blocking; +/// RAII-like timer wrapper that automatically stops inner timer when going out of scope (during destructor) +/// @tparam underlying_timer might be whichever one except for the blocking template class scoped : private detail::disable_copy, private detail::disable_move { @@ -21,7 +23,7 @@ static_assert(std::is_base_of::value, "Only timers i public: ~scoped() { - m_timer.stop(); + stop(); } underlying_timer * operator->() @@ -35,6 +37,17 @@ static_assert(std::is_base_of::value, "Only timers i } private: + void stop() noexcept + { + try + { + m_timer.stop(); + } + catch (...) + { + } + } + underlying_timer m_timer; }; } From dbec3ba74edd1333b74824bfc5b36438b11ae11e Mon Sep 17 00:00:00 2001 From: Karel Burda Date: Sun, 10 Jun 2018 21:01:42 +0200 Subject: [PATCH 6/7] Raised version to 1.2.0 [skip ci] --- CMakeLists.txt | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 961049b..d7cd5c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -project(timers VERSION 1.1.0 LANGUAGES CXX) +project(timers VERSION 1.2.0 LANGUAGES CXX) include("cmake-helpers/messages.cmake") include("cmake-helpers/settings.cmake") diff --git a/README.md b/README.md index d5abc3c..9f5b639 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Version](https://img.shields.io/badge/version-1.1.0-green.svg) +![Version](https://img.shields.io/badge/version-1.2.0-green.svg) [![License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat)](LICENSE) [![Build Status](https://travis-ci.org/karel-burda/timers.svg?branch=develop)](https://travis-ci.org/karel-burda/timers) [![Coverage Status](https://coveralls.io/repos/github/karel-burda/timers/badge.svg?branch=develop)](https://coveralls.io/github/karel-burda/timers?branch=develop) From 3de6e1f1a412ee935bfb610d86e214f479c2928c Mon Sep 17 00:00:00 2001 From: karel-burda <38255062+karel-burda@users.noreply.github.com> Date: Sun, 10 Jun 2018 21:18:20 +0200 Subject: [PATCH 7/7] Fixed branches in badges [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9f5b639..08e71d2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![Version](https://img.shields.io/badge/version-1.2.0-green.svg) [![License](https://img.shields.io/badge/license-MIT_License-green.svg?style=flat)](LICENSE) -[![Build Status](https://travis-ci.org/karel-burda/timers.svg?branch=develop)](https://travis-ci.org/karel-burda/timers) -[![Coverage Status](https://coveralls.io/repos/github/karel-burda/timers/badge.svg?branch=develop)](https://coveralls.io/github/karel-burda/timers?branch=develop) +[![Build Status](https://travis-ci.org/karel-burda/timers.svg?branch=release/1.2)](https://travis-ci.org/karel-burda/timers) +[![Coverage Status](https://coveralls.io/repos/github/karel-burda/timers/badge.svg?branch=develop)](https://coveralls.io/github/karel-burda/timers?branch=release/1.2) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/27e08eaa6aa64eddbe4a79085e95ebcc)](https://www.codacy.com/app/karel-burda/timers?utm_source=github.com&utm_medium=referral&utm_content=karel-burda/timers&utm_campaign=Badge_Grade) # Introduction