QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
class_level_lock.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2// vim:tabstop=4:shiftwidth=4:expandtab:
3
4/*
5 * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
6 *
7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any
9 * damages arising from the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute
13 * it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must
16 * not claim that you wrote the original software. If you use this
17 * software in a product, an acknowledgement in the product
18 * documentation would be appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must
20 * not be misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source
22 * distribution.
23 *
24 * This file is part of Stones of Nvwa:
25 * http://sourceforge.net/projects/nvwa
26 *
27 */
28
40#ifndef QT_NO_DEBUG
41#ifndef _QX_MODE_RELEASE
42#if _QX_USE_MEM_LEAK_DETECTION
43
44#ifndef _CLASS_LEVEL_LOCK_H
45#define _CLASS_LEVEL_LOCK_H
46
47#ifdef _MSC_VER
48#pragma once
49#endif
50
51#include "fast_mutex.h"
52
53namespace qx {
54namespace memory {
55
56#ifdef _NOTHREADS
61 template <class _Host, bool _RealLock = false>
63 {
64 public:
66 class lock
67 {
68 public:
69 lock() {}
70 };
71
72 typedef _Host volatile_type;
73 };
74#else
82 template <class _Host, bool _RealLock = true>
84 {
85 static fast_mutex _S_mtx;
86
87 public:
88 class lock;
89 friend class lock;
90
92 class lock
93 {
94 lock(const lock&);
95 lock& operator=(const lock&);
96 public:
97 lock()
98 {
99 if (_RealLock)
100 _S_mtx.lock();
101 }
102 ~lock()
103 {
104 if (_RealLock)
105 _S_mtx.unlock();
106 }
107 };
108
109 typedef volatile _Host volatile_type;
110 };
111
112#if HAVE_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
114 template <class _Host>
115 class class_level_lock<_Host, false>
116 {
117 public:
119 class lock
120 {
121 public:
122 lock() {}
123 };
124
125 typedef _Host volatile_type;
126 };
127#endif // HAVE_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
128
129 template <class _Host, bool _RealLock>
130 fast_mutex class_level_lock<_Host, _RealLock>::_S_mtx;
131#endif // _NOTHREADS
132
133} // namespace memory
134} // namespace qx
135
136#endif // _CLASS_LEVEL_LOCK_H
137#endif // _QX_USE_MEM_LEAK_DETECTION
138#endif // _QX_MODE_RELEASE
139#endif // QT_NO_DEBUG
Root namespace for all QxOrm library features.