QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
object_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
43#ifndef QT_NO_DEBUG
44#ifndef _QX_MODE_RELEASE
45#if _QX_USE_MEM_LEAK_DETECTION
46
47#ifndef _OBJECT_LEVEL_LOCK_H
48#define _OBJECT_LEVEL_LOCK_H
49
50#ifdef _MSC_VER
51#pragma once
52#endif
53
54#include "fast_mutex.h"
55
56namespace qx {
57namespace memory {
58
59# ifdef _NOTHREADS
64 template <class _Host>
66 {
67 public:
69 class lock
70 {
71#ifndef _QX_MODE_RELEASE
72#ifndef QT_NO_DEBUG
74#endif // QT_NO_DEBUG
75#endif // _QX_MODE_RELEASE
76 lock(const lock&);
78 public:
79 explicit lock(const object_level_lock& __host)
80#ifndef _QX_MODE_RELEASE
81#ifndef QT_NO_DEBUG
82 : _M_host(__host)
83#endif // QT_NO_DEBUG
84#endif // _QX_MODE_RELEASE
85 {}
86#ifndef _QX_MODE_RELEASE
87#ifndef QT_NO_DEBUG
88 // The purpose of this method is allow one to write code
89 // like "assert(guard.get_locked_object() == this)" to
90 // ensure that the locked object is exactly the object being
91 // accessed.
93 {
94 return &_M_host;
95 }
96#endif // QT_NO_DEBUG
97#endif // _QX_MODE_RELEASE
98 };
99
100 typedef _Host volatile_type;
101 };
102# else
107 template <class _Host>
109 {
110 mutable fast_mutex _M_mtx;
111
112 public:
113 class lock;
114 friend class lock;
115
117 class lock
118 {
120
121 lock(const lock&);
122 lock& operator=(const lock&);
123 public:
124 explicit lock(const object_level_lock& __host) : _M_host(__host)
125 {
126 _M_host._M_mtx.lock();
127 }
128 ~lock()
129 {
130 _M_host._M_mtx.unlock();
131 }
132#ifndef _QX_MODE_RELEASE
133#ifndef QT_NO_DEBUG
134 // The purpose of this method is allow one to write code
135 // like "assert(guard.get_locked_object() == this)" to
136 // ensure that the locked object is exactly the object being
137 // accessed.
139 {
140 return &_M_host;
141 }
142#endif // QT_NO_DEBUG
143#endif // _QX_MODE_RELEASE
144 };
145
146 typedef volatile _Host volatile_type;
147 };
148# endif // _NOTHREADS
149
150} // namespace memory
151} // namespace qx
152
153#endif // _OBJECT_LEVEL_LOCK_H
154#endif // _QX_USE_MEM_LEAK_DETECTION
155#endif // _QX_MODE_RELEASE
156#endif // QT_NO_DEBUG
lock(const object_level_lock &__host)
const object_level_lock * get_locked_object() const
const object_level_lock & _M_host
Root namespace for all QxOrm library features.