Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
reader_writer_lock.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
18
19#if !defined(__TBB_show_deprecation_message_reader_writer_lock_H) && defined(__TBB_show_deprecated_header_message)
20#define __TBB_show_deprecation_message_reader_writer_lock_H
21#pragma message("TBB Warning: tbb/reader_writer_lock.h is deprecated. For details, please see Deprecated Features appendix in the TBB reference manual.")
22#endif
23
24#if defined(__TBB_show_deprecated_header_message)
25#undef __TBB_show_deprecated_header_message
26#endif
27
28#ifndef __TBB_reader_writer_lock_H
29#define __TBB_reader_writer_lock_H
30
31#define __TBB_reader_writer_lock_H_include_area
33
34#include "tbb_thread.h"
35#include "tbb_allocator.h"
36#include "atomic.h"
37
38namespace tbb {
39namespace interface5 {
41
44 class __TBB_DEPRECATED_IN_VERBOSE_MODE_MSG("tbb::reader_writer_lock is deprecated, use std::shared_mutex")
45 reader_writer_lock : tbb::internal::no_copy {
46 public:
47 friend class scoped_lock;
48 friend class scoped_lock_read;
50
85 enum status_t { waiting_nonblocking, waiting, active, invalid };
86
88 reader_writer_lock() {
89 internal_construct();
90 }
91
93 ~reader_writer_lock() {
94 internal_destroy();
95 }
96
98
100 class scoped_lock : tbb::internal::no_copy {
101 public:
102 friend class reader_writer_lock;
103
105 scoped_lock(reader_writer_lock& lock) {
106 internal_construct(lock);
107 }
108
110 ~scoped_lock() {
111 internal_destroy();
112 }
113
114 void* operator new(size_t s) {
116 }
117 void operator delete(void* p) {
119 }
120
121 private:
123 reader_writer_lock *mutex;
125 scoped_lock* next;
127 atomic<status_t> status;
128
130 scoped_lock();
131
132 void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock&);
133 void __TBB_EXPORTED_METHOD internal_destroy();
134 };
135
137 class scoped_lock_read : tbb::internal::no_copy {
138 public:
139 friend class reader_writer_lock;
140
142 scoped_lock_read(reader_writer_lock& lock) {
143 internal_construct(lock);
144 }
145
147 ~scoped_lock_read() {
148 internal_destroy();
149 }
150
151 void* operator new(size_t s) {
153 }
154 void operator delete(void* p) {
156 }
157
158 private:
160 reader_writer_lock *mutex;
162 scoped_lock_read *next;
164 atomic<status_t> status;
165
167 scoped_lock_read();
168
169 void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock&);
170 void __TBB_EXPORTED_METHOD internal_destroy();
171 };
172
174
180
182
186 bool __TBB_EXPORTED_METHOD try_lock();
187
189
193 void __TBB_EXPORTED_METHOD lock_read();
194
196
198 bool __TBB_EXPORTED_METHOD try_lock_read();
199
201 void __TBB_EXPORTED_METHOD unlock();
202
203 private:
204 void __TBB_EXPORTED_METHOD internal_construct();
205 void __TBB_EXPORTED_METHOD internal_destroy();
206
208
209 bool start_write(scoped_lock *);
211 void set_next_writer(scoped_lock *w);
213 void end_write(scoped_lock *);
215 bool is_current_writer();
216
218
219 void start_read(scoped_lock_read *);
221 void unblock_readers();
223 void end_read();
224
226 atomic<scoped_lock_read*> reader_head;
228 atomic<scoped_lock*> writer_head;
230 atomic<scoped_lock*> writer_tail;
232 tbb_thread::id my_current_writer;
234 atomic<uintptr_t> rdr_count_and_flags; // used with __TBB_AtomicOR, which assumes uintptr_t
235};
236
237} // namespace interface5
238
239using interface5::reader_writer_lock;
240
241} // namespace tbb
242
244#undef __TBB_reader_writer_lock_H_include_area
245
246#endif /* __TBB_reader_writer_lock_H */
#define __TBB_DEPRECATED_IN_VERBOSE_MODE_MSG(msg)
Definition: tbb_config.h:648
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
void const char const char int ITT_FORMAT __itt_group_sync s
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void * lock
void const char const char int ITT_FORMAT __itt_group_sync p
The graph class.
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
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.