mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 20:43:03 +01:00
Increase time interval, given to thread with high priority in JRD_reschedule
Cleanup
This commit is contained in:
parent
0798f44283
commit
2dab094729
@ -53,6 +53,7 @@ private:
|
|||||||
static ThreadPriorityScheduler * news; // where starts new thps chain
|
static ThreadPriorityScheduler * news; // where starts new thps chain
|
||||||
static BOOLEAN initialized;
|
static BOOLEAN initialized;
|
||||||
static DWORD specific_key; // for thread LS access
|
static DWORD specific_key; // for thread LS access
|
||||||
|
static BOOLEAN shutdown; // server shutting down
|
||||||
|
|
||||||
ThreadPriorityScheduler * next; // next thread in list
|
ThreadPriorityScheduler * next; // next thread in list
|
||||||
union {
|
union {
|
||||||
@ -76,6 +77,7 @@ public:
|
|||||||
static void Exit(void);
|
static void Exit(void);
|
||||||
static thdd *Get(void);
|
static thdd *Get(void);
|
||||||
static void Set(thdd *val);
|
static void Set(thdd *val);
|
||||||
|
static BOOLEAN Boosted(void);
|
||||||
static void Cleanup(void);
|
static void Cleanup(void);
|
||||||
static void Init(void);
|
static void Init(void);
|
||||||
static void Attach(HANDLE tHandle, DWORD thread_id, int &p);
|
static void Attach(HANDLE tHandle, DWORD thread_id, int &p);
|
||||||
@ -96,6 +98,7 @@ public:
|
|||||||
#define THPS_FINI() ThreadPriorityScheduler::Cleanup()
|
#define THPS_FINI() ThreadPriorityScheduler::Cleanup()
|
||||||
#define THPS_ATTACH(handle, thread_id, priority) \
|
#define THPS_ATTACH(handle, thread_id, priority) \
|
||||||
ThreadPriorityScheduler::Attach(handle, thread_id, priority)
|
ThreadPriorityScheduler::Attach(handle, thread_id, priority)
|
||||||
|
#define THPS_BOOSTDONE() ThreadPriorityScheduler::Boosted()
|
||||||
|
|
||||||
#else // THREAD_PSCHED
|
#else // THREAD_PSCHED
|
||||||
|
|
||||||
@ -106,6 +109,7 @@ public:
|
|||||||
#define THPS_INIT()
|
#define THPS_INIT()
|
||||||
#define THPS_FINI()
|
#define THPS_FINI()
|
||||||
#define THPS_ATTACH(handle, thread_id, priority)
|
#define THPS_ATTACH(handle, thread_id, priority)
|
||||||
|
#define THPS_BOOSTDONE() FALSE
|
||||||
|
|
||||||
#endif // THREAD_PSCHED
|
#endif // THREAD_PSCHED
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ ThreadPriorityScheduler * ThreadPriorityScheduler::chain = 0;
|
|||||||
ThreadPriorityScheduler * ThreadPriorityScheduler::news = 0;
|
ThreadPriorityScheduler * ThreadPriorityScheduler::news = 0;
|
||||||
BOOLEAN ThreadPriorityScheduler::initialized = FALSE;
|
BOOLEAN ThreadPriorityScheduler::initialized = FALSE;
|
||||||
DWORD ThreadPriorityScheduler::specific_key = -1;
|
DWORD ThreadPriorityScheduler::specific_key = -1;
|
||||||
|
BOOLEAN ThreadPriorityScheduler::shutdown = FALSE;
|
||||||
|
|
||||||
//____________________________________________________________
|
//____________________________________________________________
|
||||||
//
|
//
|
||||||
// Shutdown
|
// Shutdown
|
||||||
@ -54,13 +56,7 @@ void ThreadPriorityScheduler::Cleanup(void) {
|
|||||||
if (initialized)
|
if (initialized)
|
||||||
{
|
{
|
||||||
initialized = FALSE;
|
initialized = FALSE;
|
||||||
TlsFree(specific_key);
|
shutdown = TRUE;
|
||||||
|
|
||||||
#pragma FB_COMPILER_MESSAGE("Fix! Adjust cleanup !!!")
|
|
||||||
// we must stop Scheduler, clear all intances
|
|
||||||
// and then
|
|
||||||
// delete pool;
|
|
||||||
THD_mutex_destroy(&mutex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,8 +114,7 @@ void ThreadPriorityScheduler::Init(void)
|
|||||||
HANDLE real_handle = (HANDLE)_beginthreadex(NULL, 0,
|
HANDLE real_handle = (HANDLE)_beginthreadex(NULL, 0,
|
||||||
Scheduler, 0, 0, &thread_id);
|
Scheduler, 0, 0, &thread_id);
|
||||||
if (! real_handle)
|
if (! real_handle)
|
||||||
#pragma FB_COMPILER_MESSAGE("Fix! Replace with MORE appropriate handling.")
|
Firebird::system_call_failed::raise();
|
||||||
Firebird::memory_corrupt::raise();
|
|
||||||
SetThreadPriority(real_handle, THREAD_PRIORITY_TIME_CRITICAL);
|
SetThreadPriority(real_handle, THREAD_PRIORITY_TIME_CRITICAL);
|
||||||
CloseHandle(real_handle);
|
CloseHandle(real_handle);
|
||||||
}
|
}
|
||||||
@ -132,7 +127,7 @@ void ThreadPriorityScheduler::Init(void)
|
|||||||
void ThreadPriorityScheduler::Attach(HANDLE tHandle, DWORD thread_id, int &p) {
|
void ThreadPriorityScheduler::Attach(HANDLE tHandle, DWORD thread_id, int &p) {
|
||||||
#ifdef DEV_BUILD
|
#ifdef DEV_BUILD
|
||||||
if (! pool)
|
if (! pool)
|
||||||
Firebird::memory_corrupt::raise();
|
Firebird::fatal_exception::raise("Missing pool in ThreadPriorityScheduler");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UCHAR flags = 0;
|
UCHAR flags = 0;
|
||||||
@ -162,8 +157,7 @@ void ThreadPriorityScheduler::Attach(HANDLE tHandle, DWORD thread_id, UCHAR flag
|
|||||||
if (! DuplicateHandle(process, tHandle,
|
if (! DuplicateHandle(process, tHandle,
|
||||||
process, &m->handle, 0,
|
process, &m->handle, 0,
|
||||||
FALSE, DUPLICATE_SAME_ACCESS))
|
FALSE, DUPLICATE_SAME_ACCESS))
|
||||||
#pragma FB_COMPILER_MESSAGE("Fix! Replace with MORE appropriate handling.")
|
Firebird::system_call_failed::raise();
|
||||||
Firebird::memory_corrupt::raise();
|
|
||||||
|
|
||||||
THD_mutex_lock(&mutex);
|
THD_mutex_lock(&mutex);
|
||||||
m->next = news;
|
m->next = news;
|
||||||
@ -195,7 +189,7 @@ ThreadPriorityScheduler * ThreadPriorityScheduler::Attach(void) {
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
THD_mutex_unlock(&mutex);
|
THD_mutex_unlock(&mutex);
|
||||||
Firebird::memory_corrupt::raise();
|
Firebird::fatal_exception::raise("Unknown thread tried to attach to ThreadPriorityScheduler");
|
||||||
// Never get - avoid warnings
|
// Never get - avoid warnings
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -221,6 +215,14 @@ void ThreadPriorityScheduler::Exit(void) {
|
|||||||
t->goneout = 1;
|
t->goneout = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//____________________________________________________________
|
||||||
|
//
|
||||||
|
// Check whether current thread has high priority
|
||||||
|
//
|
||||||
|
BOOLEAN ThreadPriorityScheduler::Boosted(void) {
|
||||||
|
return InternalGet()->flags & THPS_BOOSTED ? TRUE : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
//____________________________________________________________
|
//____________________________________________________________
|
||||||
//
|
//
|
||||||
// Scheduler Thread
|
// Scheduler Thread
|
||||||
@ -243,12 +245,15 @@ unsigned int __stdcall ThreadPriorityScheduler::Scheduler(LPVOID) {
|
|||||||
t->goneout = 0;
|
t->goneout = 0;
|
||||||
t->flags &= ~(THPS_UP | THPS_LOW); // clean them
|
t->flags &= ~(THPS_UP | THPS_LOW); // clean them
|
||||||
#pragma FB_COMPILER_MESSAGE("Fix! May have problems with long running UDFs.")
|
#pragma FB_COMPILER_MESSAGE("Fix! May have problems with long running UDFs.")
|
||||||
// 1. thread went out of single thread zone
|
if ((! gonein) && (! (p_flags & THPS_BOOSTED))) {
|
||||||
// and didn't return into it since last cycle:
|
if (p_flags & THPS_UP) {
|
||||||
|
// 1. thread exited single thread zone and didn't
|
||||||
|
// return into it since this &last cycle:
|
||||||
// increase priority
|
// increase priority
|
||||||
if ((p_flags & THPS_UP) && (! gonein) &&
|
if (! SetThreadPriority(t->handle,
|
||||||
(! (p_flags & THPS_BOOSTED))) {
|
THREAD_PRIORITY_HIGHEST))
|
||||||
SetThreadPriority(t->handle, THREAD_PRIORITY_HIGHEST);
|
Firebird::system_call_failed::raise();
|
||||||
|
|
||||||
#ifdef THREAD_PSCHED_DEBUG
|
#ifdef THREAD_PSCHED_DEBUG
|
||||||
gds__log("+ handle=%p priority=%d", t->handle, THREAD_PRIORITY_HIGHEST);
|
gds__log("+ handle=%p priority=%d", t->handle, THREAD_PRIORITY_HIGHEST);
|
||||||
#endif
|
#endif
|
||||||
@ -258,17 +263,18 @@ unsigned int __stdcall ThreadPriorityScheduler::Scheduler(LPVOID) {
|
|||||||
// 2. thread exited single thread zone
|
// 2. thread exited single thread zone
|
||||||
// and never returned there during this cycle:
|
// and never returned there during this cycle:
|
||||||
// candidate for priority increase
|
// candidate for priority increase
|
||||||
if ((! gonein) && (! (p_flags & THPS_BOOSTED))) {
|
|
||||||
t->flags |= THPS_UP;
|
t->flags |= THPS_UP;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ((gonein || t->inside) && (p_flags & THPS_BOOSTED)) {
|
||||||
|
if (p_flags & THPS_LOW) {
|
||||||
// 3. thread entered single thread zone
|
// 3. thread entered single thread zone
|
||||||
// last cycle and didn't leave it completely
|
// last cycle and didn't leave it completely
|
||||||
// this cycle:
|
// this cycle:
|
||||||
// decrease priority
|
// decrease priority
|
||||||
if ((p_flags & THPS_LOW) && (gonein || t->inside)
|
if (! SetThreadPriority(t->handle,
|
||||||
&& (p_flags & THPS_BOOSTED)) {
|
THREAD_PRIORITY_NORMAL))
|
||||||
SetThreadPriority(t->handle, THREAD_PRIORITY_NORMAL);
|
Firebird::system_call_failed::raise();
|
||||||
#ifdef THREAD_PSCHED_DEBUG
|
#ifdef THREAD_PSCHED_DEBUG
|
||||||
gds__log("- handle=%p priority=%d", t->handle, THREAD_PRIORITY_NORMAL);
|
gds__log("- handle=%p priority=%d", t->handle, THREAD_PRIORITY_NORMAL);
|
||||||
#endif
|
#endif
|
||||||
@ -277,7 +283,6 @@ unsigned int __stdcall ThreadPriorityScheduler::Scheduler(LPVOID) {
|
|||||||
}
|
}
|
||||||
// 4. thread entered single thread zone this cycle:
|
// 4. thread entered single thread zone this cycle:
|
||||||
// candidate for priority decrease
|
// candidate for priority decrease
|
||||||
if (gonein && (p_flags & THPS_BOOSTED)) {
|
|
||||||
t->flags |= THPS_LOW;
|
t->flags |= THPS_LOW;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -294,11 +299,13 @@ unsigned int __stdcall ThreadPriorityScheduler::Scheduler(LPVOID) {
|
|||||||
t->ticks--;
|
t->ticks--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (! shutdown) {
|
||||||
if (GlobalTicks-- > 0)
|
if (GlobalTicks-- > 0)
|
||||||
continue;
|
continue;
|
||||||
GlobalTicks = THPS_TICKS;
|
GlobalTicks = THPS_TICKS;
|
||||||
if (StateCloseHandles == 0)
|
}
|
||||||
continue;
|
|
||||||
|
if (StateCloseHandles > 0) {
|
||||||
for (ThreadPriorityScheduler ** pt = &chain; *pt; pt = &(*pt)->next) {
|
for (ThreadPriorityScheduler ** pt = &chain; *pt; pt = &(*pt)->next) {
|
||||||
start_label:
|
start_label:
|
||||||
if ((*pt)->inside)
|
if ((*pt)->inside)
|
||||||
@ -307,8 +314,7 @@ start_label:
|
|||||||
continue;
|
continue;
|
||||||
DWORD ExitCode;
|
DWORD ExitCode;
|
||||||
if (! GetExitCodeThread((*pt)->handle, &ExitCode))
|
if (! GetExitCodeThread((*pt)->handle, &ExitCode))
|
||||||
#pragma FB_COMPILER_MESSAGE("Fix! Replace with MORE appropriate handling.")
|
Firebird::system_call_failed::raise();
|
||||||
Firebird::memory_corrupt::raise();
|
|
||||||
if (ExitCode == STILL_ACTIVE) {
|
if (ExitCode == STILL_ACTIVE) {
|
||||||
(*pt)->ticks = THPS_TICKS;
|
(*pt)->ticks = THPS_TICKS;
|
||||||
continue;
|
continue;
|
||||||
@ -333,7 +339,13 @@ start_label:
|
|||||||
if (StateCloseHandles == 2)
|
if (StateCloseHandles == 2)
|
||||||
THD_mutex_unlock(&mutex);
|
THD_mutex_unlock(&mutex);
|
||||||
}
|
}
|
||||||
// never get
|
if (shutdown && (! chain) && (! news))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// cleanup
|
||||||
|
delete pool;
|
||||||
|
THD_mutex_destroy(&mutex);
|
||||||
|
TlsFree(specific_key);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user