volatile varibles in favor of std::atmoc<>

This commit is contained in:
Jinhao 2018-08-11 00:46:07 +08:00
parent 04e57771a4
commit a5f0d013c5
6 changed files with 18 additions and 14 deletions

View File

@ -23,6 +23,8 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include <atomic>
namespace nana{ namespace audio namespace nana{ namespace audio
{ {
namespace detail namespace detail
@ -52,8 +54,8 @@ namespace nana{ namespace audio
private: private:
void _m_prepare_routine(); void _m_prepare_routine();
private: private:
volatile bool running_; std::atomic<bool> running_;
volatile bool wait_for_buffer_; std::atomic<bool> wait_for_buffer_;
std::thread thr_; std::thread thr_;
mutable std::mutex token_buffer_, token_prepared_; mutable std::mutex token_buffer_, token_prepared_;
mutable std::condition_variable cond_buffer_, cond_prepared_; mutable std::condition_variable cond_buffer_, cond_prepared_;

View File

@ -193,7 +193,7 @@ namespace nana{ namespace pat{
cwrapper_.reset(); cwrapper_.reset();
} }
operator operator_bool_t() const volatile noexcept operator operator_bool_t() const noexcept
{ {
return (fast_ptr_ ? &inner_bool::true_stand : nullptr); return (fast_ptr_ ? &inner_bool::true_stand : nullptr);
} }

View File

@ -1,6 +1,6 @@
/* /*
* Timepiece Implementation * Timepiece Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -21,11 +21,11 @@ namespace system
{ {
public: public:
timepiece(); timepiece();
timepiece(const volatile timepiece&); timepiece(const timepiece&);
~timepiece(); ~timepiece();
timepiece & operator=(const volatile timepiece &); timepiece & operator=(const timepiece &);
void start() volatile; ///< Set the begin time. void start() noexcept; ///< Set the begin time.
double calc() const volatile; ///< Get the intervals from the begin time. double calc() const noexcept; ///< Get the intervals from the begin time.
private: private:
struct impl_t; struct impl_t;
impl_t * impl_; impl_t * impl_;

View File

@ -26,6 +26,7 @@
#include <condition_variable> #include <condition_variable>
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <atomic>
namespace nana namespace nana
{ {
@ -340,7 +341,7 @@ namespace detail
private: private:
Display * display_; Display * display_;
volatile bool is_work_{ false }; std::atomic<bool> is_work_{ false };
std::unique_ptr<std::thread> thrd_; std::unique_ptr<std::thread> thrd_;
struct table_tag struct table_tag

View File

@ -20,6 +20,7 @@
#include <nana/push_ignore_diagnostic> #include <nana/push_ignore_diagnostic>
#include <atomic>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <memory> #include <memory>
@ -268,7 +269,7 @@ namespace detail
std::recursive_mutex xlib_locker_; std::recursive_mutex xlib_locker_;
struct caret_holder_tag struct caret_holder_tag
{ {
volatile bool exit_thread; std::atomic<bool> exit_thread;
std::unique_ptr<std::thread> thr; std::unique_ptr<std::thread> thr;
std::map<native_window_type, caret_rep*> carets; std::map<native_window_type, caret_rep*> carets;
}caret_holder_; }caret_holder_;

View File

@ -24,7 +24,7 @@ namespace system
: impl_(new impl_t) : impl_(new impl_t)
{} {}
timepiece::timepiece(const volatile timepiece& rhs) timepiece::timepiece(const timepiece& rhs)
: impl_(new impl_t(*rhs.impl_)) : impl_(new impl_t(*rhs.impl_))
{} {}
@ -33,7 +33,7 @@ namespace system
delete impl_; delete impl_;
} }
timepiece & timepiece::operator=(const volatile timepiece & rhs) timepiece & timepiece::operator=(const timepiece & rhs)
{ {
if(this != &rhs) if(this != &rhs)
*impl_ = *rhs.impl_; *impl_ = *rhs.impl_;
@ -41,7 +41,7 @@ namespace system
return *this; return *this;
} }
void timepiece::start() volatile void timepiece::start() noexcept
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::QueryPerformanceCounter(&impl_->beg_timestamp); ::QueryPerformanceCounter(&impl_->beg_timestamp);
@ -51,7 +51,7 @@ namespace system
#endif #endif
} }
double timepiece::calc() const volatile double timepiece::calc() const noexcept
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
LARGE_INTEGER li; LARGE_INTEGER li;