MySQL  8.0.17
Source Code Documentation
mutex_lock.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef MUTEX_LOCK_INCLUDED
24 #define MUTEX_LOCK_INCLUDED
25 
26 /**
27  @file include/mutex_lock.h
28 */
29 
30 #include <mysql/psi/mysql_mutex.h>
31 
32 /**
33  A simple wrapper around a mutex:
34  Grabs the mutex in the CTOR, releases it in the DTOR.
35  The mutex may be NULL, in which case this is a no-op.
36 */
37 class Mutex_lock {
38  public:
39  explicit Mutex_lock(mysql_mutex_t *mutex, const char *src_file, int src_line)
40  : m_mutex(mutex), m_src_file(src_file), m_src_line(src_line) {
41  if (m_mutex) {
43  }
44  }
46  if (m_mutex) {
48  }
49  }
50 
51  private:
53  const char *m_src_file;
55 
56  Mutex_lock(const Mutex_lock &); /* Not copyable. */
57  void operator=(const Mutex_lock &); /* Not assignable. */
58 };
59 
60 #define MUTEX_LOCK(NAME, X) Mutex_lock NAME(X, __FILE__, __LINE__)
61 
62 #endif // MUTEX_LOCK_INCLUDED
Instrumentation helpers for mutexes.
void operator=(const Mutex_lock &)
pthread_mutex_t mutex
Definition: memcached.c:384
Mutex_lock(mysql_mutex_t *mutex, const char *src_file, int src_line)
Definition: mutex_lock.h:39
#define mysql_mutex_unlock_with_src(M, F, L)
Definition: mysql_mutex.h:54
#define mysql_mutex_lock_with_src(M, F, L)
Definition: mysql_mutex.h:45
A simple wrapper around a mutex: Grabs the mutex in the CTOR, releases it in the DTOR.
Definition: mutex_lock.h:37
~Mutex_lock()
Definition: mutex_lock.h:45
const char * m_src_file
Definition: mutex_lock.h:53
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
int m_src_line
Definition: mutex_lock.h:54
mysql_mutex_t * m_mutex
Definition: mutex_lock.h:52