~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/common/classes/locks.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      PROGRAM:                Client/Server Common Code
 
3
 *      MODULE:                 locks.cpp
 
4
 *      DESCRIPTION:    Win32 Mutex support compatible with 
 
5
 *                                      old OS versions (like Windows 95)
 
6
 *
 
7
 *  The contents of this file are subject to the Initial
 
8
 *  Developer's Public License Version 1.0 (the "License");
 
9
 *  you may not use this file except in compliance with the
 
10
 *  License. You may obtain a copy of the License at
 
11
 *  http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
 
12
 *
 
13
 *  Software distributed under the License is distributed AS IS,
 
14
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied.
 
15
 *  See the License for the specific language governing rights
 
16
 *  and limitations under the License.
 
17
 *
 
18
 *  The Original Code was created by Alexander Peshkoff
 
19
 *  for the Firebird Open Source RDBMS project.
 
20
 *
 
21
 *  Copyright (c) 2003 Alexander Peshkoff <peshkoff@mail.ru>
 
22
 *  and all contributors signed below.
 
23
 *
 
24
 *  All Rights Reserved.
 
25
 *  Contributor(s): ______________________________________.
 
26
 */
 
27
 
 
28
#include "../../include/firebird.h"
 
29
#include "../../common/classes/locks.h"
 
30
 
 
31
namespace Firebird {
 
32
 
 
33
#ifdef WIN_NT
 
34
 
 
35
#define MISS_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(-1))
 
36
#define INIT_SPIN_COUNT ((tSetCriticalSectionSpinCount *)(0))
 
37
 
 
38
tSetCriticalSectionSpinCount* 
 
39
        Spinlock::SetCriticalSectionSpinCount = INIT_SPIN_COUNT;
 
40
 
 
41
Spinlock::Spinlock() {
 
42
        if (SetCriticalSectionSpinCount == MISS_SPIN_COUNT)
 
43
                return;
 
44
        if (SetCriticalSectionSpinCount == INIT_SPIN_COUNT) {
 
45
                HMODULE kernel32 = LoadLibrary("kernel32.dll");
 
46
                if (! kernel32) {
 
47
                        SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
 
48
                        return;
 
49
                }
 
50
                SetCriticalSectionSpinCount = 
 
51
                        (tSetCriticalSectionSpinCount *) GetProcAddress(
 
52
                                        kernel32, "SetCriticalSectionSpinCount");
 
53
                if (! SetCriticalSectionSpinCount) {
 
54
                        SetCriticalSectionSpinCount = MISS_SPIN_COUNT;
 
55
                        return;
 
56
                }
 
57
        }
 
58
        SetCriticalSectionSpinCount(&spinlock, 4000);
 
59
}
 
60
 
 
61
#endif  // WIN_NT
 
62
 
 
63
}               // namespace Firebird