Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
spin_mutex.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2005-2020 Intel Corporation
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 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef __TBB_spin_mutex_H
18#define __TBB_spin_mutex_H
19
20#define __TBB_spin_mutex_H_include_area
22
23#include <cstddef>
24#include <new>
25#include "aligned_space.h"
26#include "tbb_stddef.h"
27#include "tbb_machine.h"
28#include "tbb_profiling.h"
30
31namespace tbb {
32
34
42
43public:
45
47#if TBB_USE_THREADING_TOOLS
49#endif
50 }
51
54 private:
57
59
63
66
69
72
73 friend class spin_mutex;
74
75 public:
78
82#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
83 my_mutex=NULL;
85#else
86 my_mutex=&m;
88#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
89 }
90
92 void acquire( spin_mutex& m ) {
93#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
95#else
96 my_mutex = &m;
98#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
99 }
100
102
104#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
105 return internal_try_acquire(m);
106#else
107 bool result = __TBB_TryLockByte(m.flag);
108 if( result )
109 my_mutex = &m;
110 return result;
111#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT*/
112 }
113
115 void release() {
116#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
118#else
120 my_mutex = NULL;
121#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
122 }
123
126 if( my_mutex ) {
127#if TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT
129#else
131#endif /* TBB_USE_THREADING_TOOLS||TBB_USE_ASSERT */
132 }
133 }
134 };
135
138
139 // Mutex traits
140 static const bool is_rw_mutex = false;
141 static const bool is_recursive_mutex = false;
142 static const bool is_fair_mutex = false;
143
144 // ISO C++0x compatibility methods
145
147 void lock() {
148#if TBB_USE_THREADING_TOOLS
149 aligned_space<scoped_lock> tmp;
150 new(tmp.begin()) scoped_lock(*this);
151#else
153#endif /* TBB_USE_THREADING_TOOLS*/
154 }
155
157
158 bool try_lock() {
159#if TBB_USE_THREADING_TOOLS
160 aligned_space<scoped_lock> tmp;
161 return (new(tmp.begin()) scoped_lock)->internal_try_acquire(*this);
162#else
163 return __TBB_TryLockByte(flag);
164#endif /* TBB_USE_THREADING_TOOLS*/
165 }
166
168 void unlock() {
169#if TBB_USE_THREADING_TOOLS
170 aligned_space<scoped_lock> tmp;
171 scoped_lock& s = *tmp.begin();
172 s.my_mutex = this;
173 s.internal_release();
174#else
176#endif /* TBB_USE_THREADING_TOOLS */
177 }
178
179 friend class scoped_lock;
180}; // end of spin_mutex
181
183
184} // namespace tbb
185
186#if ( __TBB_x86_32 || __TBB_x86_64 )
188#endif
189
190namespace tbb {
192
202#if ( __TBB_x86_32 || __TBB_x86_64 )
203typedef interface7::internal::padded_mutex<interface7::internal::x86_eliding_mutex,false> speculative_spin_mutex;
204#else
206#endif
208
209} // namespace tbb
210
212#undef __TBB_spin_mutex_H_include_area
213
214#endif /* __TBB_spin_mutex_H */
#define __TBB_EXPORTED_METHOD
Definition tbb_stddef.h:98
#define __TBB_DEFINE_PROFILING_SET_NAME(sync_object_type)
#define __TBB_LockByte(P)
Definition linux_ia64.h:173
unsigned char __TBB_Flag
#define __TBB_UnlockByte
#define __TBB_TryLockByte
__TBB_atomic __TBB_Flag __TBB_atomic_flag
void const char const char int ITT_FORMAT __itt_group_sync s
interface7::internal::padded_mutex< spin_mutex, false > speculative_spin_mutex
A cross-platform spin mutex with speculative lock acquisition.
Definition spin_mutex.h:205
The graph class.
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition tbb_stddef.h:398
A lock that occupies a single byte.
Definition spin_mutex.h:39
bool try_lock()
Try acquiring lock (non-blocking)
Definition spin_mutex.h:158
static const bool is_recursive_mutex
Definition spin_mutex.h:141
void __TBB_EXPORTED_METHOD internal_construct()
Internal constructor with ITT instrumentation.
spin_mutex()
Construct unacquired lock.
Definition spin_mutex.h:46
static const bool is_rw_mutex
Definition spin_mutex.h:140
void lock()
Acquire lock.
Definition spin_mutex.h:147
static const bool is_fair_mutex
Definition spin_mutex.h:142
void unlock()
Release lock.
Definition spin_mutex.h:168
__TBB_atomic_flag flag
0 if lock is released, 1 if lock is acquired.
Definition spin_mutex.h:41
Represents acquisition of a mutex.
Definition spin_mutex.h:53
scoped_lock()
Construct without acquiring a mutex.
Definition spin_mutex.h:77
__TBB_Flag my_unlock_value
Value to store into spin_mutex::flag to unlock the mutex.
Definition spin_mutex.h:62
spin_mutex * my_mutex
Points to currently held mutex, or NULL if no lock is held.
Definition spin_mutex.h:56
void __TBB_EXPORTED_METHOD internal_acquire(spin_mutex &m)
Like acquire, but with ITT instrumentation.
void __TBB_EXPORTED_METHOD internal_release()
Like release, but with ITT instrumentation.
scoped_lock(spin_mutex &m)
Construct and acquire lock on a mutex.
Definition spin_mutex.h:80
bool try_acquire(spin_mutex &m)
Try acquiring lock (non-blocking)
Definition spin_mutex.h:103
void acquire(spin_mutex &m)
Acquire lock.
Definition spin_mutex.h:92
void release()
Release lock.
Definition spin_mutex.h:115
~scoped_lock()
Destroy lock. If holding a lock, releases the lock first.
Definition spin_mutex.h:125
bool __TBB_EXPORTED_METHOD internal_try_acquire(spin_mutex &m)
Like try_acquire, but with ITT instrumentation.
Base class for types that should not be copied or assigned.
Definition tbb_stddef.h:330

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.