SeExpr
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
SeExpr
Mutex.h
Go to the documentation of this file.
1
/*
2
Copyright Disney Enterprises, Inc. All rights reserved.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License
6
and the following modification to it: Section 6 Trademarks.
7
deleted and replaced with:
8
9
6. Trademarks. This License does not grant permission to use the
10
trade names, trademarks, service marks, or product names of the
11
Licensor and its affiliates, except as required for reproducing
12
the content of the NOTICE file.
13
14
You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
16
*/
17
#ifndef Mutex_h
18
#define Mutex_h
19
20
// #define DEBUG_THREADING
21
22
#include "
Platform.h
"
23
25
namespace
SeExprInternal2 {
26
#ifndef NDEBUG
27
template
<
class
T>
28
class
DebugLock
:
public
T {
29
public
:
30
DebugLock
() :
_locked
(0) {}
31
void
lock
() {
32
T::lock();
33
_locked
= 1;
34
}
35
void
unlock
() {
36
assert(
_locked
);
37
_locked
= 0;
38
T::unlock();
39
}
40
bool
locked
() {
return
_locked
!= 0; }
41
42
private
:
43
int
_locked
;
44
};
45
#endif
46
48
template
<
class
T>
49
class
AutoLock
{
50
public
:
51
AutoLock
(T& m) :
_m
(m) {
_m
.lock(); }
52
~AutoLock
() {
_m
.unlock(); }
53
54
private
:
55
T&
_m
;
56
};
57
58
#ifndef NDEBUG
59
// add debug wrappers to mutex and spinlock
60
typedef
DebugLock<_Mutex>
Mutex
;
61
typedef
DebugLock<_SpinLock>
SpinLock
;
62
#else
63
typedef
_Mutex
Mutex
;
64
typedef
_SpinLock
SpinLock
;
65
#endif
66
67
typedef
AutoLock<Mutex>
AutoMutex
;
68
typedef
AutoLock<SpinLock>
AutoSpin
;
69
}
70
71
#endif
SeExprInternal2::AutoLock::~AutoLock
~AutoLock()
Definition:
Mutex.h:52
SeExprInternal2::SpinLock
DebugLock< _SpinLock > SpinLock
Definition:
Mutex.h:61
SeExprInternal2::_SpinLock
Definition:
Platform.h:203
SeExprInternal2::AutoLock::AutoLock
AutoLock(T &m)
Definition:
Mutex.h:51
SeExprInternal2::DebugLock::lock
void lock()
Definition:
Mutex.h:31
SeExprInternal2::AutoLock::_m
T & _m
Definition:
Mutex.h:55
SeExprInternal2::_Mutex
Definition:
Platform.h:180
SeExprInternal2::DebugLock::locked
bool locked()
Definition:
Mutex.h:40
SeExprInternal2::DebugLock::unlock
void unlock()
Definition:
Mutex.h:35
SeExprInternal2::AutoMutex
AutoLock< Mutex > AutoMutex
Definition:
Mutex.h:67
SeExprInternal2::AutoLock
Definition:
Mutex.h:49
SeExprInternal2::DebugLock::DebugLock
DebugLock()
Definition:
Mutex.h:30
SeExprInternal2::DebugLock
Definition:
Mutex.h:28
SeExprInternal2::Mutex
DebugLock< _Mutex > Mutex
Definition:
Mutex.h:60
SeExprInternal2::DebugLock::_locked
int _locked
Definition:
Mutex.h:43
SeExprInternal2::AutoSpin
AutoLock< SpinLock > AutoSpin
Definition:
Mutex.h:68
Platform.h
Platform-specific classes, functions, and includes.
Generated by
1.8.5