Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
38 namespace tbb {
39 namespace interface5 {
41 
44  class __TBB_DEPRECATED_IN_VERBOSE_MODE_MSG("tbb::reader_writer_lock is deprecated, use std::shared_mutex")
46  public:
47  friend class scoped_lock;
48  friend class scoped_lock_read;
50 
86 
90  }
91 
95  }
96 
98 
101  public:
102  friend class reader_writer_lock;
103 
106  internal_construct(lock);
107  }
108 
112  }
113 
114  void* operator new(size_t s) {
116  }
117  void operator delete(void* p) {
119  }
120 
121  private:
127  atomic<status_t> status;
128 
130  scoped_lock();
131 
134  };
135 
138  public:
139  friend class reader_writer_lock;
140 
143  internal_construct(lock);
144  }
145 
149  }
150 
151  void* operator new(size_t s) {
153  }
154  void operator delete(void* p) {
156  }
157 
158  private:
164  atomic<status_t> status;
165 
168 
171  };
172 
174 
180 
182 
187 
189 
194 
196 
199 
202 
203  private:
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 
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;
234  atomic<uintptr_t> rdr_count_and_flags; // used with __TBB_AtomicOR, which assumes uintptr_t
235 };
236 
237 } // namespace interface5
238 
240 
241 } // namespace tbb
242 
244 #undef __TBB_reader_writer_lock_H_include_area
245 
246 #endif /* __TBB_reader_writer_lock_H */
void const char const char int ITT_FORMAT __itt_group_sync s
tbb_thread::id my_current_writer
Writer that owns the mutex; tbb_thread::id() otherwise.
atomic< scoped_lock * > writer_head
The list of pending writers.
scoped_lock_read * next
The next queued competitor for the mutex.
scoped_lock_read(reader_writer_lock &lock)
Construct with blocking attempt to acquire read lock on the passed-in lock.
bool start_write(scoped_lock *)
Attempts to acquire write lock.
void set_next_writer(scoped_lock *w)
Sets writer_head to w and attempts to unblock.
status_t
Status type for nodes associated with lock instances.
The scoped lock pattern for write locks.
bool is_current_writer()
Checks if current thread holds write lock.
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:330
reader_writer_lock * mutex
The pointer to the mutex to lock.
void end_read()
Relinquishes read lock by decrementing counter; last reader wakes pending writer. ...
atomic< status_t > status
Status flag of the thread associated with this node.
reader_writer_lock()
Constructs a new reader_writer_lock.
void __TBB_EXPORTED_METHOD internal_construct()
scoped_lock * next
The next queued competitor for the mutex.
class __TBB_DEPRECATED_IN_VERBOSE_MODE_MSG("tbb::aligned_space is deprecated, use std::aligned_storage") aligned_space
Block of space aligned sufficiently to construct an array T with N elements.
Definition: aligned_space.h:43
~reader_writer_lock()
Destructs a reader_writer_lock object.
bool __TBB_EXPORTED_METHOD try_lock()
Tries to acquire the reader_writer_lock for write.
Definition: mutex.h:174
friend class scoped_lock
Definition: mutex.h:79
void start_read(scoped_lock_read *)
Attempts to acquire read lock.
void __TBB_EXPORTED_METHOD internal_destroy()
void __TBB_EXPORTED_METHOD lock_read()
Acquires the reader_writer_lock for read.
The scoped lock pattern for read locks.
atomic< status_t > status
Status flag of the thread associated with this node.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
atomic< scoped_lock * > writer_tail
The last node in the list of pending writers.
void __TBB_EXPORTED_METHOD unlock()
Releases the reader_writer_lock.
Definition: mutex.h:190
void const char const char int ITT_FORMAT __itt_group_sync p
~scoped_lock_read()
Destructor, releases the read lock.
atomic< scoped_lock_read * > reader_head
The list of pending readers.
~scoped_lock()
Destructor, releases the write lock.
reader_writer_lock * mutex
The pointer to the mutex to lock.
void __TBB_EXPORTED_METHOD lock()
Acquires the reader_writer_lock for write.
Definition: mutex.h:157
scoped_lock(reader_writer_lock &lock)
Construct with blocking attempt to acquire write lock on the passed-in lock.
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
void unblock_readers()
Unblocks pending readers.
void end_write(scoped_lock *)
Relinquishes write lock to next waiting writer or group of readers.
bool __TBB_EXPORTED_METHOD try_lock_read()
Tries to acquire the reader_writer_lock for read.
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 ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
class friend class("tbb::reader_writer_lock is deprecated, use std::shared_mutex") reader_writer_lock scoped_lock_read
Writer-preference reader-writer lock with local-only spinning on readers.

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.