Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
reader_writer_lock.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 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 
18 
19 */
20 
21 #ifndef __TBB_reader_writer_lock_H
22 #define __TBB_reader_writer_lock_H
23 
24 #include "tbb_thread.h"
25 #include "tbb_allocator.h"
26 #include "atomic.h"
27 
28 namespace tbb {
29 namespace interface5 {
31 
35  public:
36  friend class scoped_lock;
37  friend class scoped_lock_read;
39 
75 
79  }
80 
84  }
85 
87 
90  public:
91  friend class reader_writer_lock;
92 
96  }
97 
101  }
102 
103  void* operator new(size_t s) {
105  }
106  void operator delete(void* p) {
108  }
109 
110  private:
117 
119  scoped_lock();
120 
123  };
124 
127  public:
128  friend class reader_writer_lock;
129 
133  }
134 
138  }
139 
140  void* operator new(size_t s) {
142  }
143  void operator delete(void* p) {
145  }
146 
147  private:
154 
157 
160  };
161 
163 
169 
171 
176 
178 
183 
185 
188 
191 
192  private:
195 
197 
198  bool start_write(scoped_lock *);
200  void set_next_writer(scoped_lock *w);
202  void end_write(scoped_lock *);
204  bool is_current_writer();
205 
207 
210  void unblock_readers();
212  void end_read();
213 
223  atomic<uintptr_t> rdr_count_and_flags; // used with __TBB_AtomicOR, which assumes uintptr_t
224 };
225 
226 } // namespace interface5
227 
229 
230 } // namespace tbb
231 
232 #endif /* __TBB_reader_writer_lock_H */
tbb_thread::id my_current_writer
Writer that owns the mutex; tbb_thread::id() otherwise.
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
atomic< scoped_lock * > writer_head
The list of pending writers.
scoped_lock()
Construct scoped_lock that is not holding lock.
void unblock_readers()
Unblocks pending readers.
void start_read(scoped_lock_read *)
Attempts to acquire read lock.
scoped_lock(reader_writer_lock &lock)
Construct with blocking attempt to acquire write lock on the passed-in lock.
~scoped_lock()
Destructor, releases the write lock.
scoped_lock * next
The next queued competitor for the mutex.
void set_next_writer(scoped_lock *w)
Sets writer_head to w and attempts to unblock.
scoped_lock_read * next
The next queued competitor for the mutex.
bool start_write(scoped_lock *)
Attempts to acquire write lock.
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:335
bool is_current_writer()
Checks if current thread holds write lock.
The scoped lock pattern for write locks.
atomic< scoped_lock_read * > reader_head
The list of pending readers.
void end_read()
Relinquishes read lock by decrementing counter; last reader wakes pending writer.
void const char const char int ITT_FORMAT __itt_group_sync p
atomic< status_t > status
Status flag of the thread associated with this node.
void __TBB_EXPORTED_METHOD internal_construct()
scoped_lock_read(reader_writer_lock &lock)
Construct with blocking attempt to acquire read lock on the passed-in lock.
void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock &)
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
bool __TBB_EXPORTED_METHOD try_lock()
Tries to acquire the reader_writer_lock for write.
reader_writer_lock * mutex
The pointer to the mutex to lock.
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
The graph class.
void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock &)
~reader_writer_lock()
Destructs a reader_writer_lock object.
status_t
Status type for nodes associated with lock instances.
atomic< status_t > status
Status flag of the thread associated with this node.
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
reader_writer_lock * mutex
The pointer to the mutex to lock.
void const char const char int ITT_FORMAT __itt_group_sync s
void __TBB_EXPORTED_METHOD internal_destroy()
void __TBB_EXPORTED_METHOD lock_read()
Acquires the reader_writer_lock for read.
bool __TBB_EXPORTED_METHOD try_lock_read()
Tries to acquire the reader_writer_lock for read.
scoped_lock_read()
Construct scoped_lock_read that is not holding lock.
atomic< scoped_lock * > writer_tail
The last node in the list of pending writers.
void __TBB_EXPORTED_METHOD lock()
Acquires the reader_writer_lock for write.
Writer-preference reader-writer lock with local-only spinning on readers.
void end_write(scoped_lock *)
Relinquishes write lock to next waiting writer or group of readers.
void __TBB_EXPORTED_METHOD unlock()
Releases the reader_writer_lock.
~scoped_lock_read()
Destructor, releases the read lock.
reader_writer_lock()
Constructs a new reader_writer_lock.
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.

Copyright © 2005-2019 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.