MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lock.hpp
1 /*
2  Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
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  Visual Studio Source Annotations header (sourceannotations.h) fails
28  to compile if outside of the global namespace.
29 */
30 #ifdef MULTI_THREADED
31 #ifdef _WIN32
32 #include <windows.h>
33 #endif
34 #endif
35 
36 namespace yaSSL {
37 
38 
39 #ifdef MULTI_THREADED
40  #ifdef _WIN32
41  #include <windows.h>
42 
43  class Mutex {
44  CRITICAL_SECTION cs_;
45  public:
46  Mutex();
47  ~Mutex();
48 
49  class Lock;
50  friend class Lock;
51 
52  class Lock {
53  Mutex& mutex_;
54  public:
55  explicit Lock(Mutex& lm);
56  ~Lock();
57  };
58  };
59  #else // _WIN32
60  #include <pthread.h>
61 
62  class Mutex {
63  pthread_mutex_t mutex_;
64  public:
65 
66  Mutex();
67  ~Mutex();
68 
69  class Lock;
70  friend class Lock;
71 
72  class Lock {
73  Mutex& mutex_;
74  public:
75  explicit Lock(Mutex& lm);
76  ~Lock();
77  };
78  };
79 
80  #endif // _WIN32
81 #else // MULTI_THREADED (WE'RE SINGLE)
82 
83  class Mutex {
84  public:
85  class Lock {
86  public:
87  explicit Lock(Mutex&) {}
88  };
89  };
90 
91 #endif // MULTI_THREADED
92 
93 
94 
95 } // namespace
96 #endif // yaSSL_LOCK_HPP