8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:00:38 +01:00

Corrections for the prior commit:Explicitly distinguish between thread handle and thread id. Return LWP as thread id on Linux.

This commit is contained in:
dimitr 2014-08-15 14:59:38 +00:00
parent 1f630915db
commit 0fa3945f6a
9 changed files with 32 additions and 21 deletions

View File

@ -44,6 +44,10 @@
#include <unistd.h>
#endif
#ifdef HAVE_SYS_SYSCALL_H
#include <sys/syscall.h>
#endif
#include "../common/classes/locks.h"
#include "../common/classes/rwlock.h"
#include "../common/classes/Synchronize.h"
@ -93,7 +97,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, ThreadId* p_handle)
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*
@ -177,14 +181,14 @@ void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Threa
}
}
void Thread::waitForCompletion(ThreadId& thread)
void Thread::waitForCompletion(Handle& thread)
{
int state = pthread_join(thread, NULL);
if (state)
Firebird::system_call_failed::raise("pthread_join", state);
}
void Thread::kill(ThreadId& thread)
void Thread::kill(Handle& thread)
{
#ifdef HAVE_PTHREAD_CANCEL
int state = pthread_cancel(thread);
@ -196,7 +200,7 @@ void Thread::kill(ThreadId& thread)
ThreadId Thread::getId()
{
return pthread_self();
return syscall(SYS_gettid);
}
void Thread::sleep(unsigned milliseconds)
@ -243,7 +247,7 @@ void Thread::yield()
#ifdef WIN_NT
#define START_THREAD
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, ThreadId* p_handle)
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*
@ -309,14 +313,14 @@ void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Threa
}
}
void Thread::waitForCompletion(ThreadId& handle)
void Thread::waitForCompletion(Handle& handle)
{
WaitForSingleObject(handle, 500);
CloseHandle(handle);
handle = 0;
}
void Thread::kill(ThreadId& handle)
void Thread::kill(Handle& handle)
{
TerminateThread(handle, -1);
CloseHandle(handle);
@ -342,7 +346,7 @@ void Thread::yield()
#ifndef START_THREAD
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, ThreadId* p_handle)
void Thread::start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle)
{
/**************************************
*

View File

@ -50,19 +50,26 @@ const int THREAD_critical = 6;
typedef THREAD_ENTRY_DECLARE ThreadEntryPoint(THREAD_ENTRY_PARAM);
#ifdef WIN_NT
typedef HANDLE ThreadId;
typedef DWORD ThreadId;
#endif
#ifdef USE_POSIX_THREADS
typedef pthread_t ThreadId;
#ifdef LINUX
typedef int ThreadId;
#endif
class Thread
{
public:
static void start(ThreadEntryPoint* routine, void* arg, int priority_arg, ThreadId* p_handle = NULL);
static void waitForCompletion(ThreadId& handle);
static void kill(ThreadId& handle);
#ifdef WIN_NT
typedef HANDLE Handle;
#endif
#ifdef USE_POSIX_THREADS
typedef pthread_t Handle;
#endif
static void start(ThreadEntryPoint* routine, void* arg, int priority_arg, Handle* p_handle = NULL);
static void waitForCompletion(Handle& handle);
static void kill(Handle& handle);
static ThreadId getId();

View File

@ -144,7 +144,7 @@ private:
Firebird::AtomicCounter currentPage;
Firebird::Mutex pluginLoadMtx, cryptThreadMtx;
KeyHolderPlugins keyHolderPlugins;
ThreadId cryptThreadId;
Thread::Handle cryptThreadId;
Firebird::IDbCryptPlugin* cryptPlugin;
Database& dbb;
Lock* stateLock;

View File

@ -829,7 +829,7 @@ private:
AutoPtr<SharedMemory<MappingHeader> > sharedMemory;
Mutex initMutex;
ThreadId threadHandle;
Thread::Handle threadHandle;
const SLONG processId;
unsigned process;
};

View File

@ -4047,7 +4047,7 @@ void JProvider::shutdown(IStatus* status, unsigned int timeout, const int reason
{
Semaphore shutdown_semaphore;
ThreadId h;
Thread::Handle h;
Thread::start(shutdown_thread, &shutdown_semaphore, THREAD_medium, &h);
if (!shutdown_semaphore.tryEnter(0, timeout))

View File

@ -830,7 +830,7 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
SOCKET port_channel; // handle for connection (from by OS)
struct linger port_linger; // linger value as defined by SO_LINGER
Rdb* port_context;
ThreadId port_events_thread; // handle of thread, handling incoming events
Thread::Handle port_events_thread; // handle of thread, handling incoming events
void (*port_events_shutdown)(rem_port*); // hack - avoid changing API at beta stage
#ifdef WIN_NT
HANDLE port_pipe; // port pipe handle

View File

@ -485,7 +485,7 @@ GlobalPtr<Mutex> timerPause;
GlobalPtr<Semaphore> timerWakeup;
// Should use atomic flag for thread stop to provide correct membar
AtomicCounter stopTimerThread(0);
ThreadId timerThreadHandle = 0;
Thread::Handle timerThreadHandle = 0;
struct TimerEntry
{

View File

@ -2148,7 +2148,7 @@ int API_ROUTINE gds__thread_start(FPTR_INT_VOID_PTR* entrypoint,
int rc = 0;
try
{
Thread::start((ThreadEntryPoint*) entrypoint, arg, priority, (ThreadId*) thd_id);
Thread::start((ThreadEntryPoint*) entrypoint, arg, priority, (Thread::Handle*) thd_id);
}
catch (const status_exception& status)
{

View File

@ -880,7 +880,7 @@ private:
}
}
private:
ThreadId handle;
Thread::Handle handle;
};
#endif // UNIX