8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 21:23:04 +01:00

Avoid GetThreadId() which is not present in WinXP (see CORE-5772)

This commit is contained in:
hvlad 2018-03-18 15:47:01 +02:00
parent 15d37fc989
commit ccfea1c192
5 changed files with 21 additions and 15 deletions

View File

@ -98,7 +98,7 @@ THREAD_ENTRY_DECLARE threadStart(THREAD_ENTRY_PARAM arg)
#ifdef USE_POSIX_THREADS
#define START_THREAD
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
ThreadId Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*
@ -180,6 +180,7 @@ void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handl
#endif
*p_handle = thread;
}
return getId();
}
void Thread::waitForCompletion(Handle& thread)
@ -208,9 +209,9 @@ ThreadId Thread::getId()
#endif
}
bool Thread::isCurrent(Handle& thread)
bool Thread::isCurrent(const ThreadId threadId)
{
return pthread_self() == thread;
return getId() == threadId;
}
void Thread::sleep(unsigned milliseconds)
@ -257,7 +258,7 @@ void Thread::yield()
#ifdef WIN_NT
#define START_THREAD
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
ThreadId Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*
@ -321,6 +322,8 @@ void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handl
{
CloseHandle(handle);
}
return thread_id;
}
void Thread::waitForCompletion(Handle& handle)
@ -347,9 +350,9 @@ ThreadId Thread::getId()
return GetCurrentThreadId();
}
bool Thread::isCurrent(Handle& thread)
bool Thread::isCurrent(const ThreadId threadId)
{
return GetCurrentThreadId() == GetThreadId(thread);
return GetCurrentThreadId() == threadId;
}
void Thread::sleep(unsigned milliseconds)
@ -366,7 +369,7 @@ void Thread::yield()
#ifndef START_THREAD
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
ThreadId Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*
@ -378,7 +381,8 @@ void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handl
* Wrong attempt to start a new thread.
*
**************************************/
fb_assert(false);
return 0;
}
void Thread::waitForCompletion(Handle&)

View File

@ -75,10 +75,10 @@ public:
typedef pthread_t Handle;
#endif
static void start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle = NULL);
static ThreadId start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle = NULL);
static void waitForCompletion(Handle& handle);
static void kill(Handle& handle);
static bool isCurrent(Handle& handle);
static bool isCurrent(const ThreadId threadId);
static ThreadId getId();

View File

@ -5013,10 +5013,11 @@ Firebird::IEvents* Attachment::queEvents(CheckStatusWrapper* status, Firebird::I
receive_response(status, rdb, packet);
port->connect(packet);
Thread::start(event_thread, port->port_async, THREAD_high,
&port->port_async->port_events_thread);
rem_port* port_async = port->port_async;
port_async->port_events_threadId =
Thread::start(event_thread, port_async, THREAD_high, &port_async->port_events_thread);
port->port_async->port_context = rdb;
port_async->port_context = rdb;
}
// Add event block to port's list of active remote events

View File

@ -1695,7 +1695,7 @@ static void disconnect(rem_port* const port)
SOCLOSE(port->port_channel);
}
if (port->port_thread_guard && port->port_events_thread && !Thread::isCurrent(port->port_events_thread))
if (port->port_thread_guard && port->port_events_thread && !Thread::isCurrent(port->port_events_threadId))
port->port_thread_guard->setWait(port->port_events_thread);
else
port->release();

View File

@ -977,6 +977,7 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
struct linger port_linger; // linger value as defined by SO_LINGER
Rdb* port_context;
Thread::Handle port_events_thread; // handle of thread, handling incoming events
ThreadId port_events_threadId;
RemotePortGuard* port_thread_guard; // will close port_events_thread in safe way
#ifdef WIN_NT
HANDLE port_pipe; // port pipe handle
@ -1044,7 +1045,7 @@ public:
port_server(0), port_server_flags(0), port_protocol(0), port_buff_size(rpt / 2),
port_flags(0), port_connect_timeout(0), port_dummy_packet_interval(0),
port_dummy_timeout(0), port_handle(INVALID_SOCKET), port_channel(INVALID_SOCKET), port_context(0),
port_events_thread(0), port_thread_guard(0),
port_events_thread(0), port_events_threadId(0), port_thread_guard(0),
#ifdef WIN_NT
port_pipe(INVALID_HANDLE_VALUE), port_event(INVALID_HANDLE_VALUE),
#endif