8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-01 08:03:02 +01:00
firebird-mirror/src/common/classes/locks.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

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)
*
* 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
*
* 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
*
* The Original Code was created by Alexander Peshkoff
* for the Firebird Open Source RDBMS project.
2003-01-20 19:38:34 +01:00
*
* Copyright (c) 2003 Alexander Peshkoff <peshkoff@mail.ru>
* and all contributors signed below.
2003-01-20 19:38:34 +01:00
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
2003-01-20 19:38:34 +01:00
*/
#include "../../include/firebird.h"
#include "../../common/classes/locks.h"
#include "../../common/thd.h"
#include "../../jrd/common.h"
2003-01-20 19:38:34 +01:00
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
2003-01-20 19:38:34 +01:00
namespace Firebird {
2003-01-21 12:08:59 +01:00
#if defined(WIN_NT)
2003-01-20 19:38:34 +01:00
#define MISS_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(-1))
#define INIT_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(0))
tSetCriticalSectionSpinCount*
2006-05-03 07:44:26 +02:00
Spinlock::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
2003-01-20 19:38:34 +01:00
2008-01-23 20:27:36 +01:00
void Spinlock::init()
{
2003-01-20 19:38:34 +01:00
if (SetCriticalSectionSpinCount == MISS_SPIN_COUNT)
return;
2008-01-23 20:27:36 +01:00
2003-01-20 19:38:34 +01:00
if (SetCriticalSectionSpinCount == INIT_SPIN_COUNT) {
HMODULE kernel32 = LoadLibrary("kernel32.dll");
2008-01-23 20:27:36 +01:00
if (!kernel32) {
2003-01-20 19:38:34 +01:00
SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
return;
}
SetCriticalSectionSpinCount =
(tSetCriticalSectionSpinCount *) GetProcAddress(
kernel32, "SetCriticalSectionSpinCount");
2008-01-23 20:27:36 +01:00
if (!SetCriticalSectionSpinCount) {
2003-01-20 19:38:34 +01:00
SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
return;
}
}
2008-01-23 20:27:36 +01:00
2003-01-20 19:38:34 +01:00
SetCriticalSectionSpinCount(&spinlock, 4000);
}
2003-01-21 12:08:59 +01:00
#elif defined(SOLARIS_MT)
2003-01-21 12:08:59 +01:00
#error Fix me!
#else //posix mutex
pthread_mutexattr_t Mutex::attr;
2008-02-06 01:43:54 +01:00
void Mutex::initMutexes()
{
// Throw exceptions on errors, but they will not be processed in init
// (first constructor). Better logging facilities are required here.
int rc = pthread_mutexattr_init(&attr);
if (rc < 0)
system_call_failed::raise("pthread_mutexattr_init", rc);
rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (rc < 0)
system_call_failed::raise("pthread_mutexattr_settype", rc);
}
#endif
#ifdef DEV_BUILD
void MutexLockGuard::halt()
{
abort();
}
#endif
2008-01-23 20:27:36 +01:00
} // namespace Firebird