2003-01-20 19:38:34 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Client/Server Common Code
|
|
|
|
* MODULE: locks.cpp
|
2004-03-01 05:57:43 +01:00
|
|
|
* DESCRIPTION: Win32 Mutex support compatible with
|
2003-01-20 19:38:34 +01:00
|
|
|
* old OS versions (like Windows 95)
|
|
|
|
*
|
2005-01-10 19:06:14 +01:00
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
2003-01-20 19:38:34 +01:00
|
|
|
*
|
2005-01-10 19:06:14 +01:00
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
2003-01-20 19:38:34 +01:00
|
|
|
*
|
2005-01-10 19:06:14 +01:00
|
|
|
* The Original Code was created by Alexander Peshkoff
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
2003-01-20 19:38:34 +01:00
|
|
|
*
|
2005-01-10 19:06:14 +01:00
|
|
|
* Copyright (c) 2004 Alexander Peshkoff <peshkoff@mail.ru>
|
|
|
|
* and all contributors signed below.
|
2003-01-20 19:38:34 +01:00
|
|
|
*
|
2005-01-10 19:06:14 +01:00
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2003-01-20 19:38:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../../include/firebird.h"
|
|
|
|
#include "../../common/classes/locks.h"
|
|
|
|
|
|
|
|
namespace Firebird {
|
2003-01-21 12:08:59 +01:00
|
|
|
|
2003-01-20 19:38:34 +01:00
|
|
|
#ifdef WIN_NT
|
|
|
|
|
|
|
|
#define MISS_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(-1))
|
|
|
|
#define INIT_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(0))
|
|
|
|
|
|
|
|
tSetCriticalSectionSpinCount*
|
2004-03-01 05:57:43 +01:00
|
|
|
Mutex::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
|
2003-01-20 19:38:34 +01:00
|
|
|
|
2004-03-01 05:57:43 +01:00
|
|
|
Mutex::Mutex() {
|
2003-01-20 19:38:34 +01:00
|
|
|
InitializeCriticalSection(&spinlock);
|
|
|
|
if (SetCriticalSectionSpinCount == MISS_SPIN_COUNT)
|
|
|
|
return;
|
|
|
|
if (SetCriticalSectionSpinCount == INIT_SPIN_COUNT) {
|
|
|
|
HMODULE kernel32 = LoadLibrary("kernel32.dll");
|
|
|
|
if (! kernel32) {
|
|
|
|
SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetCriticalSectionSpinCount =
|
|
|
|
(tSetCriticalSectionSpinCount *) GetProcAddress(
|
|
|
|
kernel32, "SetCriticalSectionSpinCount");
|
|
|
|
if (! SetCriticalSectionSpinCount) {
|
|
|
|
SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetCriticalSectionSpinCount(&spinlock, 4000);
|
|
|
|
}
|
2003-01-21 12:08:59 +01:00
|
|
|
|
2003-01-20 19:38:34 +01:00
|
|
|
#endif // WIN_NT
|
2003-01-21 12:08:59 +01:00
|
|
|
|
2003-01-31 08:44:03 +01:00
|
|
|
} // namespace Firebird
|