~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to extra/yassl/include/lock.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2000-2007 MySQL AB
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; see the file COPYING. If not, write to the
 
15
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 
16
   MA  02110-1301  USA.
 
17
*/
 
18
 
 
19
/* lock.hpp provides an os specific Lock, locks mutex on entry and unlocks
 
20
 * automatically upon exit, no-ops provided for Single Threaded
 
21
*/
 
22
 
 
23
#ifndef yaSSL_LOCK_HPP
 
24
#define yaSSL_LOCK_HPP
 
25
 
 
26
 
 
27
namespace yaSSL {
 
28
 
 
29
 
 
30
#ifdef MULTI_THREADED
 
31
    #ifdef _WIN32
 
32
        #include <windows.h>
 
33
 
 
34
        class Mutex {
 
35
            CRITICAL_SECTION cs_;
 
36
        public:
 
37
            Mutex();
 
38
            ~Mutex();
 
39
 
 
40
            class Lock;
 
41
            friend class Lock;
 
42
    
 
43
            class Lock {
 
44
                Mutex& mutex_;
 
45
            public:
 
46
                explicit Lock(Mutex& lm);
 
47
                ~Lock();
 
48
            };
 
49
        };
 
50
    #else  // _WIN32
 
51
        #include <pthread.h>
 
52
 
 
53
        class Mutex {
 
54
            pthread_mutex_t mutex_;
 
55
        public:
 
56
 
 
57
            Mutex();
 
58
            ~Mutex();
 
59
 
 
60
            class Lock;
 
61
            friend class Lock;
 
62
 
 
63
            class Lock {
 
64
                Mutex& mutex_;
 
65
            public:
 
66
                explicit Lock(Mutex& lm);
 
67
                ~Lock();
 
68
            };
 
69
        };
 
70
 
 
71
    #endif // _WIN32
 
72
#else  // MULTI_THREADED (WE'RE SINGLE)
 
73
 
 
74
    class Mutex {
 
75
    public:
 
76
        class Lock {
 
77
        public:
 
78
            explicit Lock(Mutex&) {}
 
79
        };
 
80
    };
 
81
 
 
82
#endif // MULTI_THREADED
 
83
 
 
84
 
 
85
 
 
86
} // namespace
 
87
#endif // yaSSL_LOCK_HPP