Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::interface5::reader_writer_lock::scoped_lock Class Reference

The scoped lock pattern for write locks. More...

#include <reader_writer_lock.h>

Inheritance diagram for tbb::interface5::reader_writer_lock::scoped_lock:
Collaboration diagram for tbb::interface5::reader_writer_lock::scoped_lock:

Public Member Functions

 scoped_lock (reader_writer_lock &lock)
 Construct with blocking attempt to acquire write lock on the passed-in lock. More...
 
 ~scoped_lock ()
 Destructor, releases the write lock. More...
 
voidoperator new (size_t s)
 
void operator delete (void *p)
 

Private Member Functions

 scoped_lock ()
 Construct scoped_lock that is not holding lock. More...
 
void __TBB_EXPORTED_METHOD internal_construct (reader_writer_lock &)
 
void __TBB_EXPORTED_METHOD internal_destroy ()
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy ()
 Allow default construction. More...
 

Private Attributes

reader_writer_lockmutex
 The pointer to the mutex to lock. More...
 
scoped_locknext
 The next queued competitor for the mutex. More...
 
atomic< status_tstatus
 Status flag of the thread associated with this node. More...
 

Friends

class reader_writer_lock
 

Detailed Description

The scoped lock pattern for write locks.

Scoped locks help avoid the common problem of forgetting to release the lock. This type also serves as the node for queuing locks.

Definition at line 85 of file reader_writer_lock.h.

Constructor & Destructor Documentation

◆ scoped_lock() [1/2]

tbb::interface5::reader_writer_lock::scoped_lock::scoped_lock ( reader_writer_lock lock)
inline

Construct with blocking attempt to acquire write lock on the passed-in lock.

Definition at line 90 of file reader_writer_lock.h.

90  {
92  }
void __TBB_EXPORTED_METHOD lock()
Acquires the reader_writer_lock for write.
void __TBB_EXPORTED_METHOD internal_construct(reader_writer_lock &)

References internal_construct(), and tbb::interface5::reader_writer_lock::lock().

Here is the call graph for this function:

◆ ~scoped_lock()

tbb::interface5::reader_writer_lock::scoped_lock::~scoped_lock ( )
inline

Destructor, releases the write lock.

Definition at line 95 of file reader_writer_lock.h.

95  {
97  }

References internal_destroy().

Here is the call graph for this function:

◆ scoped_lock() [2/2]

tbb::interface5::reader_writer_lock::scoped_lock::scoped_lock ( )
inlineprivate

Construct scoped_lock that is not holding lock.

Definition at line 306 of file reader_writer_lock.cpp.

306  : mutex(NULL), next(NULL) {
307  status = waiting;
308 }
reader_writer_lock * mutex
The pointer to the mutex to lock.
scoped_lock * next
The next queued competitor for the mutex.
atomic< status_t > status
Status flag of the thread associated with this node.

References status, and tbb::interface5::reader_writer_lock::waiting.

Member Function Documentation

◆ internal_construct()

void tbb::interface5::reader_writer_lock::scoped_lock::internal_construct ( reader_writer_lock lock)
private

Definition at line 293 of file reader_writer_lock.cpp.

293  {
294  mutex = &lock;
295  next = NULL;
296  status = waiting;
297  if (mutex->is_current_writer()) { // recursive lock attempt
298  // we don't support recursive writer locks; throw exception
300  }
301  else { // this thread holds no locks
302  (void) mutex->start_write(this);
303  }
304 }
void __TBB_EXPORTED_METHOD lock()
Acquires the reader_writer_lock for write.
reader_writer_lock * mutex
The pointer to the mutex to lock.
bool is_current_writer()
Checks if current thread holds write lock.
scoped_lock * next
The next queued competitor for the mutex.
atomic< status_t > status
Status flag of the thread associated with this node.
bool start_write(scoped_lock *)
Attempts to acquire write lock.
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()

References tbb::internal::eid_improper_lock, tbb::interface5::reader_writer_lock::lock(), next, status, tbb::internal::throw_exception(), void, and tbb::interface5::reader_writer_lock::waiting.

Referenced by scoped_lock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ internal_destroy()

void tbb::interface5::reader_writer_lock::scoped_lock::internal_destroy ( )
private

Definition at line 328 of file reader_writer_lock.cpp.

328  {
329  if (mutex) {
330  __TBB_ASSERT(mutex->is_current_writer(), "~scoped_lock() destroyed by thread different than thread that holds lock.");
331  mutex->end_write(this);
332  }
333  status = invalid;
334 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
reader_writer_lock * mutex
The pointer to the mutex to lock.
bool is_current_writer()
Checks if current thread holds write lock.
atomic< status_t > status
Status flag of the thread associated with this node.
void end_write(scoped_lock *)
Relinquishes write lock to next waiting writer or group of readers.

References __TBB_ASSERT, and tbb::interface5::reader_writer_lock::invalid.

Referenced by ~scoped_lock().

Here is the caller graph for this function:

◆ operator delete()

void tbb::interface5::reader_writer_lock::scoped_lock::operator delete ( void p)
inline

Definition at line 102 of file reader_writer_lock.h.

102  {
104  }
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
void const char const char int ITT_FORMAT __itt_group_sync p

References tbb::internal::deallocate_via_handler_v3(), and p.

Here is the call graph for this function:

◆ operator new()

void* tbb::interface5::reader_writer_lock::scoped_lock::operator new ( size_t  s)
inline

Definition at line 99 of file reader_writer_lock.h.

99  {
101  }
void const char const char int ITT_FORMAT __itt_group_sync s
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.

References tbb::internal::allocate_via_handler_v3(), and s.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ reader_writer_lock

friend class reader_writer_lock
friend

Definition at line 87 of file reader_writer_lock.h.

Member Data Documentation

◆ mutex

reader_writer_lock* tbb::interface5::reader_writer_lock::scoped_lock::mutex
private

The pointer to the mutex to lock.

Definition at line 108 of file reader_writer_lock.h.

◆ next

scoped_lock* tbb::interface5::reader_writer_lock::scoped_lock::next
private

The next queued competitor for the mutex.

Definition at line 110 of file reader_writer_lock.h.

Referenced by tbb::interface5::reader_writer_lock::end_write(), internal_construct(), and tbb::interface5::reader_writer_lock::start_write().

◆ status

atomic<status_t> tbb::interface5::reader_writer_lock::scoped_lock::status
private

The documentation for this class was generated from the following files:

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.