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*);
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);

View File

@ -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<unsigned, timer_group> threadmap_;
std::map<thread_t, timer_group> threadmap_;
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);
if(timer_.runner)

View File

@ -35,7 +35,7 @@ namespace detail
{
struct thread_binder
{
unsigned tid;
thread_t tid;
std::mutex mutex;
std::condition_variable cond;
std::list<msg_packet_tag> 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<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())
{
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<unsigned, thread_binder*> thr_table;
std::map<thread_t, thread_binder*> thr_table;
std::map<Window, thread_binder*> wnd_table;
}table_;

View File

@ -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);

View File

@ -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);
}

View File

@ -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_guard<decltype(impl_->mutex)> 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)
{

View File

@ -273,10 +273,10 @@ namespace detail
//class revertible_mutex
struct thread_refcount
{
unsigned tid; //Thread ID
thread_t tid; //Thread ID
std::vector<unsigned> 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<thread_refcount> 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<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)
{

View File

@ -26,6 +26,27 @@
#include <pthread.h>
#include <sys/stat.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
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<char *>(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