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 #ifndef __TBB_reader_writer_lock_H
18 #define __TBB_reader_writer_lock_H
19 
20 #include "tbb_thread.h"
21 #include "tbb_allocator.h"
22 #include "atomic.h"
23 
24 namespace tbb {
25 namespace interface5 {
27 
31  public:
32  friend class scoped_lock;
33  friend class scoped_lock_read;
35 
71 
75  }
76 
80  }
81 
83 
86  public:
87  friend class reader_writer_lock;
88 
92  }
93 
97  }
98 
99  void* operator new(size_t s) {
101  }
102  void operator delete(void* p) {
104  }
105 
106  private:
113 
115  scoped_lock();
116 
119  };
120 
123  public:
124  friend class reader_writer_lock;
125 
129  }
130 
134  }
135 
136  void* operator new(size_t s) {
138  }
139  void operator delete(void* p) {
141  }
142 
143  private:
150 
153 
156  };
157 
159 
165 
167 
172 
174 
179 
181 
184 
187 
188  private:
191 
193 
194  bool start_write(scoped_lock *);
196  void set_next_writer(scoped_lock *w);
198  void end_write(scoped_lock *);
200  bool is_current_writer();
201 
203 
206  void unblock_readers();
208  void end_read();
209 
219  atomic<uintptr_t> rdr_count_and_flags; // used with __TBB_AtomicOR, which assumes uintptr_t
220 };
221 
222 } // namespace interface5
223 
225 
226 } // namespace tbb
227 
228 #endif /* __TBB_reader_writer_lock_H */
scoped_lock_read()
Construct scoped_lock_read that is not holding lock.
atomic< scoped_lock * > writer_head
The list of pending writers.
~reader_writer_lock()
Destructs a reader_writer_lock object.
void const char const char int ITT_FORMAT __itt_group_sync s
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.
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
bool is_current_writer()
Checks if current thread holds write lock.
scoped_lock * next
The next queued competitor for the mutex.
scoped_lock()
Construct scoped_lock that is not holding lock.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
Base class for types that should not be copied or assigned.
Definition: tbb_stddef.h:331
The scoped lock pattern for write locks.
The graph class.
~scoped_lock_read()
Destructor, releases the read lock.
void end_read()
Relinquishes read lock by decrementing counter; last reader wakes pending writer.
void __TBB_EXPORTED_METHOD internal_construct()
atomic< status_t > status
Status flag of the thread associated with this node.
void __TBB_EXPORTED_METHOD lock_read()
Acquires the reader_writer_lock for read.
status_t
Status type for nodes associated with lock instances.
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
Writer-preference reader-writer lock with local-only spinning on readers.
reader_writer_lock()
Constructs a new reader_writer_lock.
scoped_lock_read * next
The next queued competitor for the mutex.
void start_read(scoped_lock_read *)
Attempts to acquire read lock.
reader_writer_lock * mutex
The pointer to the mutex to lock.
void __TBB_EXPORTED_METHOD unlock()
Releases the reader_writer_lock.
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
void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock &)
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock &)
reader_writer_lock * mutex
The pointer to the mutex to lock.
void const char const char int ITT_FORMAT __itt_group_sync p
bool __TBB_EXPORTED_METHOD try_lock_read()
Tries to acquire the reader_writer_lock for read.
atomic< scoped_lock_read * > reader_head
The list of pending readers.
void __TBB_EXPORTED_METHOD lock()
Acquires the reader_writer_lock for write.
void end_write(scoped_lock *)
Relinquishes write lock to next waiting writer or group of readers.
void unblock_readers()
Unblocks pending readers.
atomic< status_t > status
Status flag of the thread associated with this node.
void __TBB_EXPORTED_METHOD internal_destroy()
scoped_lock_read(reader_writer_lock &lock)
Construct with blocking attempt to acquire read lock on the passed-in lock.
scoped_lock(reader_writer_lock &lock)
Construct with blocking attempt to acquire write lock on the passed-in lock.
atomic< scoped_lock * > writer_tail
The last node in the list of pending writers.
bool __TBB_EXPORTED_METHOD try_lock()
Tries to acquire the reader_writer_lock for write.
~scoped_lock()
Destructor, releases the write lock.

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.