refactoring and fix
fix a potential dead-lock caused by timer
This commit is contained in:
@@ -13,10 +13,11 @@
|
||||
#include "../../detail/platform_spec_selector.hpp"
|
||||
#include "basic_window.hpp"
|
||||
#include "bedrock_types.hpp"
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/widgets/widget.hpp>
|
||||
#include <nana/gui/detail/event_code.hpp>
|
||||
#include <nana/system/platform.hpp>
|
||||
#include <nana/system/timepiece.hpp>
|
||||
#include <nana/gui/wvl.hpp>
|
||||
#include <nana/gui/detail/native_window_interface.hpp>
|
||||
#include <nana/gui/layout_utility.hpp>
|
||||
#include <nana/gui/detail/element_store.hpp>
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
#include <nana/gui/detail/event_code.hpp>
|
||||
#include <nana/system/platform.hpp>
|
||||
#include <nana/system/timepiece.hpp>
|
||||
#include <nana/gui.hpp>
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/msgbox.hpp>
|
||||
#include <nana/gui/detail/native_window_interface.hpp>
|
||||
#include <nana/gui/layout_utility.hpp>
|
||||
#include <nana/gui/detail/window_layout.hpp>
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
* James Bremner
|
||||
*/
|
||||
|
||||
#include <nana/gui.hpp>
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/msgbox.hpp>
|
||||
#include <nana/gui/widgets/form.hpp>
|
||||
#include <nana/gui/widgets/label.hpp>
|
||||
#include <nana/gui/widgets/button.hpp>
|
||||
#include <nana/gui/widgets/spinbox.hpp>
|
||||
|
||||
@@ -43,8 +43,6 @@ namespace nana
|
||||
|
||||
class timer_driver
|
||||
{
|
||||
typedef std::lock_guard<std::recursive_mutex> lock_guard;
|
||||
|
||||
friend class timer_core;
|
||||
|
||||
timer_driver() = default;
|
||||
@@ -70,7 +68,7 @@ namespace nana
|
||||
auto tmid = p;
|
||||
::nana::detail::platform_spec::instance().set_timer(reinterpret_cast<std::size_t>(tmid), ms, &timer_driver::_m_timer_proc);
|
||||
#endif
|
||||
lock_guard lock(mutex_);
|
||||
::nana::internal_scope_guard lock;
|
||||
timer_table_[tmid].reset(p);
|
||||
return p;
|
||||
}
|
||||
@@ -82,7 +80,8 @@ namespace nana
|
||||
|
||||
void destroy(timer_identifier tid)
|
||||
{
|
||||
lock_guard lock(mutex_);
|
||||
::nana::internal_scope_guard lock;
|
||||
|
||||
auto i = timer_table_.find(tid);
|
||||
if (i != timer_table_.end())
|
||||
{
|
||||
@@ -101,7 +100,6 @@ namespace nana
|
||||
static void _m_timer_proc(std::size_t id);
|
||||
#endif
|
||||
private:
|
||||
std::recursive_mutex mutex_;
|
||||
std::map<timer_identifier, std::unique_ptr<timer_core>> timer_table_;
|
||||
};
|
||||
|
||||
@@ -141,21 +139,19 @@ namespace nana
|
||||
nana::basic_event<arg_elapse> & evt_elapse_;
|
||||
}; //end class timer_core
|
||||
|
||||
|
||||
#if defined(NANA_WINDOWS)
|
||||
void __stdcall timer_driver::_m_timer_proc(HWND /*hwnd*/, UINT /*uMsg*/, UINT_PTR id, DWORD /*dwTime*/)
|
||||
#else
|
||||
void timer_driver::_m_timer_proc(std::size_t id)
|
||||
#endif
|
||||
{
|
||||
auto & driver = instance();
|
||||
auto & time_tbl = instance().timer_table_;
|
||||
|
||||
lock_guard lock(driver.mutex_);
|
||||
#if defined(NANA_WINDOWS)
|
||||
auto i = driver.timer_table_.find(id);
|
||||
#else
|
||||
auto i = driver.timer_table_.find(reinterpret_cast<timer_identifier>(id));
|
||||
#endif
|
||||
if (i == driver.timer_table_.end())
|
||||
::nana::internal_scope_guard lock;
|
||||
|
||||
auto i = time_tbl.find(id);
|
||||
if (i == time_tbl.end())
|
||||
return;
|
||||
|
||||
arg_elapse arg;
|
||||
@@ -183,8 +179,7 @@ namespace nana
|
||||
|
||||
timer::~timer()
|
||||
{
|
||||
if (impl_->tm_core)
|
||||
timer_driver::instance().destroy(impl_->tm_core->id());
|
||||
stop();
|
||||
delete impl_;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* A Categorize Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -10,7 +10,7 @@
|
||||
* @file nana/gui/widgets/categorize.cpp
|
||||
*/
|
||||
|
||||
#include <nana/gui/wvl.hpp>
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/widgets/categorize.hpp>
|
||||
#include <nana/gui/widgets/float_listbox.hpp>
|
||||
#include <nana/gui/element.hpp>
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
* @file: nana/gui/widgets/combox.cpp
|
||||
*/
|
||||
|
||||
#include <nana/gui.hpp>
|
||||
#include <nana/gui/widgets/combox.hpp>
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/element.hpp>
|
||||
#include <nana/gui/widgets/combox.hpp>
|
||||
#include <nana/system/dataexch.hpp>
|
||||
#include <nana/gui/widgets/float_listbox.hpp>
|
||||
#include <nana/gui/widgets/skeletons/text_editor.hpp>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* Benjamin Navarro(pr#81)
|
||||
* besh81(pr#130)
|
||||
* dankan1890(pr#158)
|
||||
* ErrorFlynn(pr#418)
|
||||
* ErrorFlynn(pr#418,pr#448,pr#454)
|
||||
*
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
@@ -13,12 +13,13 @@
|
||||
* dankan1890(pr#158)
|
||||
*/
|
||||
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/screen.hpp>
|
||||
#include <nana/gui/widgets/menu.hpp>
|
||||
#include <nana/gui/timer.hpp>
|
||||
|
||||
#include <nana/system/platform.hpp>
|
||||
#include <nana/gui/element.hpp>
|
||||
#include <nana/gui/wvl.hpp>
|
||||
#include <nana/paint/text_renderer.hpp>
|
||||
#include <cctype> //introduces tolower
|
||||
#include <vector>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Nana GUI Library Definition
|
||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -11,7 +11,8 @@
|
||||
* the file contains the files required for running of Nana.GUI
|
||||
*/
|
||||
|
||||
#include <nana/gui/wvl.hpp>
|
||||
#include <nana/gui/compact.hpp>
|
||||
#include <nana/gui/widgets/widget.hpp>
|
||||
#include <nana/gui/detail/bedrock.hpp>
|
||||
#include <nana/std_thread.hpp>
|
||||
#include <iostream>
|
||||
|
||||
Reference in New Issue
Block a user