MongoDB  2.7.0
Classes | Public Member Functions | List of all members
mongo::QLock Class Reference

"Quad Lock" we want to be able to do semi-granular locking now, and read/write style locking for that. More...

#include <qlock.h>

Inheritance diagram for mongo::QLock:

Public Member Functions

void lock_r ()
 
void lock_w ()
 
void lock_R ()
 
bool lock_R_try (int millis)
 
void lock_W ()
 
bool lock_W_try (int millis)
 
void unlock_r ()
 
void unlock_w ()
 
void unlock_R ()
 
void unlock_W ()
 
void W_to_R ()
 
void R_to_W ()
 
bool w_to_X ()
 
void X_to_w ()
 

Detailed Description

"Quad Lock" we want to be able to do semi-granular locking now, and read/write style locking for that.

if that is all we want we could just have a rwlock per lockable entity, and we are done. however at times we want to stop-the-world. in addition, sometimes we want to stop the world for writing only.

A hierarchy of locks could achieve this; instead here we've modeled it in one synchronization object our "QLock". Our possible locked states are:

w - i will write, and i will granularly lock after the qlock acquisition r - i will read, and i will granularly lock after the qlock acquisition W - i will write globally. stop the world. R - i will read globally. stop any writer.

For example there is a point during journal batch commits where we wish to block all writers but no readers.

Non-recursive.

r w R W X <== lock that was around r * * * - - w * * - - - * allowed R * - * - - - not allowed (blocks) W - - - - - ! See NOTE(!). X - ! - - - ^ lock we are requesting

NOTE(!): The "X" state can only be reached from the "w" state. A thread successfully transitions from "w" to "X" when w_to_X() returns true, and fails to transition to that state (remaining in "w") when that function returns false. For one thread to successfully transition, all threads in the "w" state must be blocked in w_to_X(). When all threads in the "w" state are blocked in w_to_X(), one thread will be released in the X state. The other threads remain blocked in w_to_X() until the thread in the X state calls X_to_w().


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