MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lock.cpp
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 /* Locking functions
20  */
21 
22 #include "runtime.hpp"
23 #include "lock.hpp"
24 
25 
26 namespace yaSSL {
27 
28 
29 #ifdef MULTI_THREADED
30  #ifdef _WIN32
31 
32  Mutex::Mutex()
33  {
34  InitializeCriticalSection(&cs_);
35  }
36 
37 
38  Mutex::~Mutex()
39  {
40  DeleteCriticalSection(&cs_);
41  }
42 
43 
44  Mutex::Lock::Lock(Mutex& lm) : mutex_(lm)
45  {
46  EnterCriticalSection(&mutex_.cs_);
47  }
48 
49 
50  Mutex::Lock::~Lock()
51  {
52  LeaveCriticalSection(&mutex_.cs_);
53  }
54 
55  #else // _WIN32
56 
57  Mutex::Mutex()
58  {
59  pthread_mutex_init(&mutex_, 0);
60  }
61 
62 
63  Mutex::~Mutex()
64  {
65  pthread_mutex_destroy(&mutex_);
66  }
67 
68 
69  Mutex::Lock::Lock(Mutex& lm) : mutex_(lm)
70  {
71  pthread_mutex_lock(&mutex_.mutex_);
72  }
73 
74 
75  Mutex::Lock::~Lock()
76  {
77  pthread_mutex_unlock(&mutex_.mutex_);
78  }
79 
80 
81  #endif // _WIN32
82 #endif // MULTI_THREADED
83 
84 
85 
86 } // namespace yaSSL
87