More thread_t fixes (dont use a 32 bit type to hold a 64 bit handle).

This commit is contained in:
unitrunker
2018-01-22 11:46:29 -06:00
parent e9c381e1de
commit f2baba7c77
9 changed files with 49 additions and 44 deletions

View File

@@ -139,7 +139,7 @@ namespace detail
void enable_tabstop(core_window_t*); void enable_tabstop(core_window_t*);
core_window_t* tabstop(core_window_t*, bool forward) const; //forward means move to next in logic. 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); bool enable_effects_bground(core_window_t*, bool);

View File

@@ -214,7 +214,7 @@ namespace detail
struct timer_tag struct timer_tag
{ {
std::size_t id; std::size_t id;
unsigned tid; thread_t tid;
std::size_t interval; std::size_t interval;
std::size_t timestamp; std::size_t timestamp;
timer_proc_t proc; timer_proc_t proc;
@@ -295,7 +295,7 @@ namespace detail
return (holder_.empty()); return (holder_.empty());
} }
void timer_proc(unsigned tid) void timer_proc(thread_t tid)
{ {
is_proc_handling_ = true; is_proc_handling_ = true;
auto i = threadmap_.find(tid); auto i = threadmap_.find(tid);
@@ -329,7 +329,7 @@ namespace detail
} }
private: private:
bool is_proc_handling_; bool is_proc_handling_;
std::map<unsigned, timer_group> threadmap_; std::map<thread_t, timer_group> threadmap_;
std::map<std::size_t, timer_tag> holder_; std::map<std::size_t, timer_tag> 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<decltype(timer_.mutex)> lock(timer_.mutex); std::lock_guard<decltype(timer_.mutex)> lock(timer_.mutex);
if(timer_.runner) if(timer_.runner)

View File

@@ -35,7 +35,7 @@ namespace detail
{ {
struct thread_binder struct thread_binder
{ {
unsigned tid; thread_t tid;
std::mutex mutex; std::mutex mutex;
std::condition_variable cond; std::condition_variable cond;
std::list<msg_packet_tag> msg_queue; std::list<msg_packet_tag> msg_queue;
@@ -44,7 +44,7 @@ namespace detail
public: public:
typedef msg_packet_tag msg_packet; 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 void (*event_proc_type)(Display*, msg_packet_tag&);
typedef int (*event_filter_type)(XEvent&, 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()); start_driver = (0 == table_.thr_table.size());
thread_binder * thr; thread_binder * thr;
std::map<unsigned, thread_binder*>::iterator i = table_.thr_table.find(tid); std::map<thread_t, thread_binder*>::iterator i = table_.thr_table.find(tid);
if(i == table_.thr_table.end()) if(i == table_.thr_table.end())
{ {
thr = new thread_binder; thr = new thread_binder;
@@ -270,7 +270,7 @@ namespace detail
//_m_read_queue //_m_read_queue
//@brief:Read the event from a specified thread queue. //@brief:Read the event from a specified thread queue.
//@return: 0 = exit the queue, 1 = fetch the msg, -1 = no msg //@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; bool stop_driver = false;
@@ -317,7 +317,7 @@ namespace detail
//_m_wait_for_queue //_m_wait_for_queue
// wait for the insertion of queue. // wait for the insertion of queue.
//return@ it returns true if the queue is not empty, otherwise the wait is timeout. //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; thread_binder * thr = nullptr;
{ {
@@ -344,7 +344,7 @@ namespace detail
struct table_tag struct table_tag
{ {
std::recursive_mutex mutex; std::recursive_mutex mutex;
std::map<unsigned, thread_binder*> thr_table; std::map<thread_t, thread_binder*> thr_table;
std::map<Window, thread_binder*> wnd_table; std::map<Window, thread_binder*> wnd_table;
}table_; }table_;

View File

@@ -186,7 +186,7 @@ namespace detail
public: public:
int error_code; int error_code;
public: 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 void (*event_proc_type)(Display*, msg_packet_tag&);
typedef ::nana::event_code event_code; typedef ::nana::event_code event_code;
typedef ::nana::native_window_type native_window_type; typedef ::nana::native_window_type native_window_type;
@@ -235,7 +235,7 @@ namespace detail
Window grab(Window); Window grab(Window);
void set_timer(std::size_t id, std::size_t interval, void (*timer_proc)(std::size_t id)); 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 kill_timer(std::size_t id);
void timer_proc(unsigned tid); void timer_proc(thread_t tid);
//Message dispatcher //Message dispatcher
void msg_insert(native_window_type); void msg_insert(native_window_type);

View File

@@ -93,13 +93,13 @@ namespace detail
{ {
struct thread_context_cache struct thread_context_cache
{ {
unsigned tid{ 0 }; thread_t tid{ 0 };
thread_context *object{ nullptr }; thread_context *object{ nullptr };
}tcontext; }tcontext;
}cache; }cache;
}; };
void timer_proc(unsigned); void timer_proc(thread_t);
void window_proc_dispatcher(Display*, nana::detail::msg_packet_tag&); 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_packet(Display *, nana::detail::msg_packet_tag&);
void window_proc_for_xevent(Display*, XEvent&); 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); nana::detail::platform_spec::instance().timer_proc(tid);
} }

View File

@@ -176,7 +176,7 @@ namespace detail
{ {
struct thread_context_cache struct thread_context_cache
{ {
unsigned tid{ 0 }; thread_t tid{ 0 };
thread_context *object{ nullptr }; thread_context *object{ nullptr };
}tcontext; }tcontext;
}cache; }cache;
@@ -245,7 +245,7 @@ namespace detail
/// @brief increament the number of windows in the thread id /// @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. //impl refers to the object of private_impl, the object is created when bedrock is creating.
private_impl * impl = instance().impl_; private_impl * impl = instance().impl_;
@@ -255,7 +255,7 @@ namespace detail
return (cnt < 0 ? cnt = 1 : ++cnt); 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(); if(0 == tid) tid = nana::system::this_thread_id();
std::lock_guard<decltype(impl_->mutex)> lock(impl_->mutex); std::lock_guard<decltype(impl_->mutex)> lock(impl_->mutex);
@@ -269,7 +269,7 @@ namespace detail
return context; 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(); if(0 == tid) tid = nana::system::this_thread_id();
@@ -289,7 +289,7 @@ namespace detail
return nullptr; 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(); 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) 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); auto context = this->open_thread_context(tid);
if(0 == context->window_count) if(0 == context->window_count)
{ {

View File

@@ -273,10 +273,10 @@ namespace detail
//class revertible_mutex //class revertible_mutex
struct thread_refcount struct thread_refcount
{ {
unsigned tid; //Thread ID thread_t tid; //Thread ID
std::vector<unsigned> callstack_refs; std::vector<unsigned> callstack_refs;
thread_refcount(unsigned thread_id, unsigned refs) thread_refcount(thread_t thread_id, unsigned refs)
: tid(thread_id) : tid(thread_id)
{ {
callstack_refs.push_back(refs); callstack_refs.push_back(refs);
@@ -287,7 +287,7 @@ namespace detail
{ {
std::recursive_mutex mutex; std::recursive_mutex mutex;
unsigned thread_id; //Thread ID thread_t thread_id; //Thread ID
unsigned refs; //Ref count unsigned refs; //Ref count
std::vector<thread_refcount> records; std::vector<thread_refcount> records;
@@ -1442,7 +1442,7 @@ namespace detail
return nullptr; return nullptr;
} }
void window_manager::remove_trash_handle(unsigned tid) void window_manager::remove_trash_handle(thread_t tid)
{ {
//Thread-Safe Required! //Thread-Safe Required!
std::lock_guard<mutex_type> lock(mutex_); std::lock_guard<mutex_type> lock(mutex_);

View File

@@ -153,7 +153,7 @@ namespace nana
} }
} }
void delete_trash(unsigned thread_id) void delete_trash(thread_t thread_id)
{ {
if (0 == thread_id) if (0 == thread_id)
{ {

View File

@@ -26,6 +26,27 @@
#include <pthread.h> #include <pthread.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <spawn.h> #include <spawn.h>
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<char *>(url_utf8), nullptr};
posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
}
}
#endif #endif
namespace nana namespace nana
@@ -120,23 +141,7 @@ namespace system
::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL); ::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL);
} }
#elif defined(NANA_POSIX) #elif defined(NANA_POSIX)
const char *home = getenv("HOME"); posix_open_url(url_utf8.c_str());
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<char *>(url_utf8.c_str()), nullptr};
posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
}
#endif #endif
} }
}//end namespace system }//end namespace system