From f2baba7c778ebef1aa6894e00090e6ca6ab04c68 Mon Sep 17 00:00:00 2001 From: unitrunker Date: Mon, 22 Jan 2018 11:46:29 -0600 Subject: [PATCH] More thread_t fixes (dont use a 32 bit type to hold a 64 bit handle). --- include/nana/gui/detail/window_manager.hpp | 2 +- source/detail/platform_spec_posix.cpp | 8 ++--- source/detail/posix/msg_dispatcher.hpp | 12 +++---- source/detail/posix/platform_spec.hpp | 4 +-- source/gui/detail/bedrock_posix.cpp | 6 ++-- source/gui/detail/bedrock_windows.cpp | 12 +++---- source/gui/detail/window_manager.cpp | 8 ++--- source/gui/detail/window_register.hpp | 2 +- source/system/platform.cpp | 39 ++++++++++++---------- 9 files changed, 49 insertions(+), 44 deletions(-) diff --git a/include/nana/gui/detail/window_manager.hpp b/include/nana/gui/detail/window_manager.hpp index bc5c9b03..0807978d 100644 --- a/include/nana/gui/detail/window_manager.hpp +++ b/include/nana/gui/detail/window_manager.hpp @@ -139,7 +139,7 @@ namespace detail void enable_tabstop(core_window_t*); core_window_t* tabstop(core_window_t*, bool forward) const; //forward means move to next in logic. - void remove_trash_handle(unsigned tid); + void remove_trash_handle(thread_t tid); bool enable_effects_bground(core_window_t*, bool); diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 853f4df1..c6ee7abf 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -214,7 +214,7 @@ namespace detail struct timer_tag { std::size_t id; - unsigned tid; + thread_t tid; std::size_t interval; std::size_t timestamp; timer_proc_t proc; @@ -295,7 +295,7 @@ namespace detail return (holder_.empty()); } - void timer_proc(unsigned tid) + void timer_proc(thread_t tid) { is_proc_handling_ = true; auto i = threadmap_.find(tid); @@ -329,7 +329,7 @@ namespace detail } private: bool is_proc_handling_; - std::map threadmap_; + std::map threadmap_; std::map holder_; }; @@ -966,7 +966,7 @@ namespace detail } } - void platform_spec::timer_proc(unsigned tid) + void platform_spec::timer_proc(thread_t tid) { std::lock_guard lock(timer_.mutex); if(timer_.runner) diff --git a/source/detail/posix/msg_dispatcher.hpp b/source/detail/posix/msg_dispatcher.hpp index 58adf7b0..8aed6ce5 100644 --- a/source/detail/posix/msg_dispatcher.hpp +++ b/source/detail/posix/msg_dispatcher.hpp @@ -35,7 +35,7 @@ namespace detail { struct thread_binder { - unsigned tid; + thread_t tid; std::mutex mutex; std::condition_variable cond; std::list msg_queue; @@ -44,7 +44,7 @@ namespace detail public: typedef msg_packet_tag msg_packet; - typedef void (*timer_proc_type)(unsigned tid); + typedef void (*timer_proc_type)(thread_t tid); typedef void (*event_proc_type)(Display*, msg_packet_tag&); typedef int (*event_filter_type)(XEvent&, msg_packet_tag&); @@ -87,7 +87,7 @@ namespace detail start_driver = (0 == table_.thr_table.size()); thread_binder * thr; - std::map::iterator i = table_.thr_table.find(tid); + std::map::iterator i = table_.thr_table.find(tid); if(i == table_.thr_table.end()) { thr = new thread_binder; @@ -270,7 +270,7 @@ namespace detail //_m_read_queue //@brief:Read the event from a specified thread queue. //@return: 0 = exit the queue, 1 = fetch the msg, -1 = no msg - int _m_read_queue(unsigned tid, msg_packet_tag& msg, Window modal) + int _m_read_queue(thread_t tid, msg_packet_tag& msg, Window modal) { bool stop_driver = false; @@ -317,7 +317,7 @@ namespace detail //_m_wait_for_queue // wait for the insertion of queue. //return@ it returns true if the queue is not empty, otherwise the wait is timeout. - bool _m_wait_for_queue(unsigned tid) + bool _m_wait_for_queue(thread_t tid) { thread_binder * thr = nullptr; { @@ -344,7 +344,7 @@ namespace detail struct table_tag { std::recursive_mutex mutex; - std::map thr_table; + std::map thr_table; std::map wnd_table; }table_; diff --git a/source/detail/posix/platform_spec.hpp b/source/detail/posix/platform_spec.hpp index fc8cc644..e8b2be24 100644 --- a/source/detail/posix/platform_spec.hpp +++ b/source/detail/posix/platform_spec.hpp @@ -186,7 +186,7 @@ namespace detail public: int error_code; public: - typedef void (*timer_proc_type)(unsigned tid); + typedef void (*timer_proc_type)(thread_t tid); typedef void (*event_proc_type)(Display*, msg_packet_tag&); typedef ::nana::event_code event_code; typedef ::nana::native_window_type native_window_type; @@ -235,7 +235,7 @@ namespace detail Window grab(Window); void set_timer(std::size_t id, std::size_t interval, void (*timer_proc)(std::size_t id)); void kill_timer(std::size_t id); - void timer_proc(unsigned tid); + void timer_proc(thread_t tid); //Message dispatcher void msg_insert(native_window_type); diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 9609fe7f..8412cb04 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -93,13 +93,13 @@ namespace detail { struct thread_context_cache { - unsigned tid{ 0 }; + thread_t tid{ 0 }; thread_context *object{ nullptr }; }tcontext; }cache; }; - void timer_proc(unsigned); + void timer_proc(thread_t); void window_proc_dispatcher(Display*, nana::detail::msg_packet_tag&); void window_proc_for_packet(Display *, nana::detail::msg_packet_tag&); void window_proc_for_xevent(Display*, XEvent&); @@ -352,7 +352,7 @@ namespace detail } - void timer_proc(unsigned tid) + void timer_proc(thread_t tid) { nana::detail::platform_spec::instance().timer_proc(tid); } diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index 2d75e7d4..c97618b8 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -176,7 +176,7 @@ namespace detail { struct thread_context_cache { - unsigned tid{ 0 }; + thread_t tid{ 0 }; thread_context *object{ nullptr }; }tcontext; }cache; @@ -245,7 +245,7 @@ namespace detail /// @brief increament the number of windows in the thread id - int bedrock::inc_window(unsigned tid) + int bedrock::inc_window(thread_t tid) { //impl refers to the object of private_impl, the object is created when bedrock is creating. private_impl * impl = instance().impl_; @@ -255,7 +255,7 @@ namespace detail return (cnt < 0 ? cnt = 1 : ++cnt); } - auto bedrock::open_thread_context(unsigned tid) -> thread_context* + auto bedrock::open_thread_context(thread_t tid) -> thread_context* { if(0 == tid) tid = nana::system::this_thread_id(); std::lock_guardmutex)> lock(impl_->mutex); @@ -269,7 +269,7 @@ namespace detail return context; } - auto bedrock::get_thread_context(unsigned tid) -> thread_context * + auto bedrock::get_thread_context(thread_t tid) -> thread_context * { if(0 == tid) tid = nana::system::this_thread_id(); @@ -289,7 +289,7 @@ namespace detail return nullptr; } - void bedrock::remove_thread_context(unsigned tid) + void bedrock::remove_thread_context(thread_t tid) { if(0 == tid) tid = nana::system::this_thread_id(); @@ -347,7 +347,7 @@ namespace detail void bedrock::pump_event(window condition_wd, bool is_modal) { - const unsigned tid = ::GetCurrentThreadId(); + thread_t tid = ::GetCurrentThreadId(); auto context = this->open_thread_context(tid); if(0 == context->window_count) { diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 83eb2ef4..cd85c260 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -273,10 +273,10 @@ namespace detail //class revertible_mutex struct thread_refcount { - unsigned tid; //Thread ID + thread_t tid; //Thread ID std::vector callstack_refs; - thread_refcount(unsigned thread_id, unsigned refs) + thread_refcount(thread_t thread_id, unsigned refs) : tid(thread_id) { callstack_refs.push_back(refs); @@ -287,7 +287,7 @@ namespace detail { std::recursive_mutex mutex; - unsigned thread_id; //Thread ID + thread_t thread_id; //Thread ID unsigned refs; //Ref count std::vector records; @@ -1442,7 +1442,7 @@ namespace detail return nullptr; } - void window_manager::remove_trash_handle(unsigned tid) + void window_manager::remove_trash_handle(thread_t tid) { //Thread-Safe Required! std::lock_guard lock(mutex_); diff --git a/source/gui/detail/window_register.hpp b/source/gui/detail/window_register.hpp index 40b2fae6..7a2500e4 100644 --- a/source/gui/detail/window_register.hpp +++ b/source/gui/detail/window_register.hpp @@ -153,7 +153,7 @@ namespace nana } } - void delete_trash(unsigned thread_id) + void delete_trash(thread_t thread_id) { if (0 == thread_id) { diff --git a/source/system/platform.cpp b/source/system/platform.cpp index dd255f46..95221a37 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -26,6 +26,27 @@ #include #include #include + +static void posix_open_url(const char *url_utf8) +{ + extern char **environ; + const char *home = getenv("HOME"); + std::string cheat(home); + cheat += "/.mozilla"; + struct stat exists{}; + // Look for $HOME/.mozilla directory as + // strong evidence they use firefox. + if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) + { + pid_t pid = 0; + static const char firefox[] = "firefox"; + char name[sizeof firefox]{}; + // argv does not like const-literals so make a copy. + strcpy(name, firefox); + char *argv[3] = {name, const_cast(url_utf8), nullptr}; + posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); + } +} #endif namespace nana @@ -120,23 +141,7 @@ namespace system ::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL); } #elif defined(NANA_POSIX) - const char *home = getenv("HOME"); - std::string cheat(home); - cheat += "/.mozilla"; - struct stat exists{}; - // Look for $HOME/.mozilla directory as - // strong evidence they use firefox. - if ( stat(cheat.c_str(), &exists) == 0 && S_ISDIR(exists.st_mode)) - { - extern char **environ; - pid_t pid = 0; - static const char firefox[] = "firefox"; - char name[sizeof firefox]{}; - // argv does not like const-literals so make a copy. - strcpy(name, firefox); - char *argv[3] = {name, const_cast(url_utf8.c_str()), nullptr}; - posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ); - } + posix_open_url(url_utf8.c_str()); #endif } }//end namespace system