Motr  M0
FOM long lock API

Data Structures

struct  m0_long_lock_addb2
 
struct  m0_long_lock_link
 
struct  m0_long_lock
 
struct  m0_be_long_lock
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_FOP
 
#define M0_BE_LONG_LOCK_PAD   (264 + 88)
 
#define M0_FOM_LONG_LOCK_RETURN(rc)   ((rc) ? M0_FSO_AGAIN : M0_FSO_WAIT)
 

Enumerations

enum  m0_long_lock_state { M0_LONG_LOCK_UNLOCKED, M0_LONG_LOCK_RD_LOCKED, M0_LONG_LOCK_WR_LOCKED }
 
enum  m0_long_lock_type { M0_LONG_LOCK_READER, M0_LONG_LOCK_WRITER }
 

Functions

 M0_TL_DESCR_DEFINE (m0_lll, "list of lock-links in longlock", M0_INTERNAL, struct m0_long_lock_link, lll_lock_linkage, lll_magix, M0_FOM_LL_LINK_MAGIC, M0_FOM_LL_LINK_MAGIC)
 
 M0_TL_DEFINE (m0_lll, M0_INTERNAL, struct m0_long_lock_link)
 
 M0_BOB_DEFINE (M0_INTERNAL, &long_lock_bob, m0_long_lock)
 
 M0_BOB_DEFINE (M0_INTERNAL, &long_lock_link_bob, m0_long_lock_link)
 
M0_INTERNAL void m0_fom_ll_global_init (void)
 
M0_INTERNAL void m0_long_lock_link_init (struct m0_long_lock_link *link, struct m0_fom *fom, struct m0_long_lock_addb2 *addb2)
 
M0_INTERNAL void m0_long_lock_link_fini (struct m0_long_lock_link *link)
 
static void ll_addb2_reset (struct m0_long_lock_link *link)
 
static void ll_addb2_post (struct m0_long_lock_link *link)
 
static void ll_addb2_wait_start (struct m0_long_lock_link *link)
 
static void ll_addb2_wait_finish (struct m0_long_lock_link *link)
 
static bool link_invariant (const struct m0_long_lock_link *link)
 
static bool lock_invariant (const struct m0_long_lock *lock)
 
static bool can_lock (const struct m0_long_lock *lock, const struct m0_long_lock_link *link)
 
static void grant (struct m0_long_lock *lock, struct m0_long_lock_link *link)
 
static bool lock (struct m0_long_lock *lock, struct m0_long_lock_link *link, int next_phase)
 
M0_INTERNAL bool m0_long_write_lock (struct m0_long_lock *lk, struct m0_long_lock_link *link, int next_phase)
 
M0_INTERNAL bool m0_long_read_lock (struct m0_long_lock *lk, struct m0_long_lock_link *link, int next_phase)
 
M0_INTERNAL bool m0_long_lock (struct m0_long_lock *lock, bool write, struct m0_long_lock_link *link, int next_phase)
 
static void unlock (struct m0_long_lock *lock, struct m0_long_lock_link *link, bool check_ownership)
 
M0_INTERNAL void m0_long_write_unlock (struct m0_long_lock *lock, struct m0_long_lock_link *link)
 
M0_INTERNAL void m0_long_read_unlock (struct m0_long_lock *lock, struct m0_long_lock_link *link)
 
M0_INTERNAL void m0_long_unlock (struct m0_long_lock *lock, struct m0_long_lock_link *link)
 
M0_INTERNAL bool m0_long_is_read_locked (struct m0_long_lock *lock, const struct m0_fom *fom)
 
M0_INTERNAL bool m0_long_is_write_locked (struct m0_long_lock *lock, const struct m0_fom *fom)
 
M0_INTERNAL void m0_long_lock_init (struct m0_long_lock *lock)
 
M0_INTERNAL void m0_long_lock_fini (struct m0_long_lock *lock)
 
struct m0_be_long_lock M0_XCA_DOMAIN (be)
 
 M0_BASSERT (sizeof(struct m0_long_lock)<=sizeof(M0_FIELD_VALUE(struct m0_be_long_lock, bll_u.pad)))
 
 M0_BOB_DECLARE (M0_EXTERN, m0_long_lock)
 
 M0_BOB_DECLARE (M0_EXTERN, m0_long_lock_link)
 

Variables

static const struct m0_bob_type long_lock_bob
 
static struct m0_bob_type long_lock_link_bob
 

Detailed Description

See also
FOM long lock DLD

Macro Definition Documentation

◆ M0_BE_LONG_LOCK_PAD

#define M0_BE_LONG_LOCK_PAD   (264 + 88)

Definition at line 190 of file fom_long_lock.h.

◆ M0_FOM_LONG_LOCK_RETURN

#define M0_FOM_LONG_LOCK_RETURN (   rc)    ((rc) ? M0_FSO_AGAIN : M0_FSO_WAIT)

A macros to request a long lock from a fom phase transition function. The value of macros should be returned from the phase transition function. The fom transitions into next_phase when the lock is acquired:

  • M0_FSO_AGAIN when the lock is acquired immediately;
  • M0_FSO_WAIT when the lock will be acquired after a wait.

Definition at line 214 of file fom_long_lock.h.

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_FOP

Definition at line 29 of file fom_long_lock.c.

Enumeration Type Documentation

◆ m0_long_lock_state

Long lock states.

Enumerator
M0_LONG_LOCK_UNLOCKED 
M0_LONG_LOCK_RD_LOCKED 
M0_LONG_LOCK_WR_LOCKED 

Definition at line 132 of file fom_long_lock.h.

◆ m0_long_lock_type

Type of long lock link, requesting the lock

Enumerator
M0_LONG_LOCK_READER 
M0_LONG_LOCK_WRITER 

Definition at line 141 of file fom_long_lock.h.

Function Documentation

◆ can_lock()

static bool can_lock ( const struct m0_long_lock lock,
const struct m0_long_lock_link link 
)
static

True, iff "link" can acquire "lock", provided "link" is at the head of waiters queue.

Definition at line 173 of file fom_long_lock.c.

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

◆ grant()

static void grant ( struct m0_long_lock lock,
struct m0_long_lock_link link 
)
static

Definition at line 181 of file fom_long_lock.c.

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

◆ link_invariant()

static bool link_invariant ( const struct m0_long_lock_link link)
static

Definition at line 119 of file fom_long_lock.c.

Here is the caller graph for this function:

◆ ll_addb2_post()

static void ll_addb2_post ( struct m0_long_lock_link link)
static

Definition at line 90 of file fom_long_lock.c.

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

◆ ll_addb2_reset()

static void ll_addb2_reset ( struct m0_long_lock_link link)
static

Definition at line 84 of file fom_long_lock.c.

Here is the caller graph for this function:

◆ ll_addb2_wait_finish()

static void ll_addb2_wait_finish ( struct m0_long_lock_link link)
static

Definition at line 107 of file fom_long_lock.c.

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

◆ ll_addb2_wait_start()

static void ll_addb2_wait_start ( struct m0_long_lock_link link)
static

Definition at line 101 of file fom_long_lock.c.

Here is the caller graph for this function:

◆ lock()

static bool lock ( struct m0_long_lock lock,
struct m0_long_lock_link link,
int  next_phase 
)
static

Definition at line 192 of file fom_long_lock.c.

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

◆ lock_invariant()

static bool lock_invariant ( const struct m0_long_lock lock)
static

This invariant is established by m0_long_lock_init(). Every top-level long lock entry point assumes that this invariant holds right after the lock's mutex is taken and restores the invariant before releasing the mutex.

Definition at line 133 of file fom_long_lock.c.

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

◆ M0_BASSERT()

M0_BASSERT ( sizeof(struct m0_long_lock)<=sizeof(M0_FIELD_VALUE(struct m0_be_long_lock, bll_u.pad))  )

◆ M0_BOB_DECLARE() [1/2]

M0_BOB_DECLARE ( M0_EXTERN  ,
m0_long_lock   
)

◆ M0_BOB_DECLARE() [2/2]

M0_BOB_DECLARE ( M0_EXTERN  ,
m0_long_lock_link   
)

◆ M0_BOB_DEFINE() [1/2]

M0_BOB_DEFINE ( M0_INTERNAL  ,
long_lock_bob,
m0_long_lock   
)

◆ M0_BOB_DEFINE() [2/2]

M0_BOB_DEFINE ( M0_INTERNAL  ,
long_lock_link_bob,
m0_long_lock_link   
)

◆ m0_fom_ll_global_init()

M0_INTERNAL void m0_fom_ll_global_init ( void  )

Initializes bob-type for m0_long_lock and m0_long_lock_link. Should be called once, during system initialisation.

Definition at line 60 of file fom_long_lock.c.

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

◆ m0_long_is_read_locked()

M0_INTERNAL bool m0_long_is_read_locked ( struct m0_long_lock lock,
const struct m0_fom fom 
)
Returns
true iff the lock is taken as a read-lock by the given fom.

Definition at line 318 of file fom_long_lock.c.

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

◆ m0_long_is_write_locked()

M0_INTERNAL bool m0_long_is_write_locked ( struct m0_long_lock lock,
const struct m0_fom fom 
)
Returns
true iff the lock is taken as a write-lock by the given fom.

Definition at line 332 of file fom_long_lock.c.

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

◆ m0_long_lock()

M0_INTERNAL bool m0_long_lock ( struct m0_long_lock lock,
bool  write,
struct m0_long_lock_link link,
int  next_phase 
)

Takes write or read long term lock, depending on the value of the "write" parameter.

Definition at line 237 of file fom_long_lock.c.

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

◆ m0_long_lock_fini()

M0_INTERNAL void m0_long_lock_fini ( struct m0_long_lock lock)
Precondition
!m0_long_is_read_locked(lock, *)
!m0_long_is_write_locked(lock, *)

Definition at line 360 of file fom_long_lock.c.

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

◆ m0_long_lock_init()

M0_INTERNAL void m0_long_lock_init ( struct m0_long_lock lock)
Postcondition
lock->l_state == M0_LONG_LOCK_UNLOCKED
m0_mutex_is_not_locked(&lock->l_lock)

Definition at line 348 of file fom_long_lock.c.

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

◆ m0_long_lock_link_fini()

M0_INTERNAL void m0_long_lock_link_fini ( struct m0_long_lock_link link)

Finalize long lock link object.

Precondition
!m0_lll_tlink_is_in(link)

Definition at line 76 of file fom_long_lock.c.

Here is the caller graph for this function:

◆ m0_long_lock_link_init()

M0_INTERNAL void m0_long_lock_link_init ( struct m0_long_lock_link link,
struct m0_fom fom,
struct m0_long_lock_addb2 addb2 
)

Initialize long lock link object with given fom.

addb2 optional argument which is used to collect counters on lock wait/hold times by the link

Precondition
fom != NULL

Definition at line 66 of file fom_long_lock.c.

Here is the caller graph for this function:

◆ m0_long_read_lock()

M0_INTERNAL bool m0_long_read_lock ( struct m0_long_lock lock,
struct m0_long_lock_link link,
int  next_phase 
)

Obtains given lock for reading for given fom. Taking recursive read-lock is not permitted. If the lock is not obtained the invoking FOM should wait; it will eventually be awoken when the lock has been obtained, and will be transitioned to the next_phase state.

Parameters
link- Long lock link associated with the FOM which has to obtain the lock.
Precondition
link->lll_fom != NULL
!m0_long_is_read_locked(lock, link)
!m0_tlink_is_in(&link->lll_lock_linkage)
Postcondition
m0_fom_phase(fom) == next_phase
Returns
true iff the lock is taken.

Definition at line 229 of file fom_long_lock.c.

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

◆ m0_long_read_unlock()

M0_INTERNAL void m0_long_read_unlock ( struct m0_long_lock lock,
struct m0_long_lock_link link 
)

Unlocks given read-lock.

Parameters
link- Long lock link associated with the FOM which has to obtain the lock.
Precondition
m0_long_is_read_locked(lock, link);
m0_fom_group_is_locked(lock->lll_fom)
Postcondition
!m0_long_is_read_locked(lock, link);

Definition at line 306 of file fom_long_lock.c.

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

◆ m0_long_unlock()

M0_INTERNAL void m0_long_unlock ( struct m0_long_lock lock,
struct m0_long_lock_link link 
)

Unlocks read or write lock.

Definition at line 312 of file fom_long_lock.c.

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

◆ m0_long_write_lock()

M0_INTERNAL bool m0_long_write_lock ( struct m0_long_lock lock,
struct m0_long_lock_link link,
int  next_phase 
)

Obtains given lock for writing for given fom. Taking recursive write-lock is not permitted. If the lock is not obtained the invoking FOM should wait; it will eventually be awoken when the lock has been obtained, and will be transitioned to the next_phase state.

Parameters
link- Long lock link associated with the FOM which has to obtain the lock.
Precondition
link->lll_fom != NULL
!m0_long_is_write_locked(lock, fom)
!m0_tlink_is_in(&link->lll_lock_linkage)
Postcondition
m0_fom_phase(fom) == next_phase
Returns
true iff the lock is taken.

Definition at line 221 of file fom_long_lock.c.

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

◆ m0_long_write_unlock()

M0_INTERNAL void m0_long_write_unlock ( struct m0_long_lock lock,
struct m0_long_lock_link link 
)

Unlocks given write-lock.

Parameters
link- Long lock link associated with the FOM which has to obtain the lock.
Precondition
m0_long_is_write_locked(lock, link);
m0_fom_group_is_locked(lock->lll_fom)
Postcondition
!m0_long_is_write_locked(lock, link);

Definition at line 300 of file fom_long_lock.c.

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

◆ M0_TL_DEFINE()

M0_TL_DEFINE ( m0_lll  ,
M0_INTERNAL  ,
struct m0_long_lock_link   
)

◆ M0_TL_DESCR_DEFINE()

M0_TL_DESCR_DEFINE ( m0_lll  ,
"list of lock-links in longlock"  ,
M0_INTERNAL  ,
struct m0_long_lock_link  ,
lll_lock_linkage  ,
lll_magix  ,
M0_FOM_LL_LINK_MAGIC  ,
M0_FOM_LL_LINK_MAGIC   
)

Descriptor of typed list used in m0_long_lock with m0_long_lock_link::lll_lock_linkage.

◆ M0_XCA_DOMAIN()

struct m0_be_long_lock M0_XCA_DOMAIN ( be  )

◆ unlock()

static void unlock ( struct m0_long_lock lock,
struct m0_long_lock_link link,
bool  check_ownership 
)
static

Initially, here the following assertion was checked: M0_ASSERT(next->lll_fom->fo_transitions_saved + 1 == next->lll_fom->fo_transitions);

For the reason fom->fo_transitions counter is updated after control returns from fom_tick() without any locks taken, it can be so, that long lock is queued to be taken by one fom (thread) and the contorol is still inside fom_tick(), and other fom (thread) has already unlocked() -> granted() the long lock. In this case fom->fo_transitions is still not updated, so fom->fo_transitions_saved can be equal to fom->fo_transitions in this case. In other cases it has to be greater by 1.

Definition at line 245 of file fom_long_lock.c.

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

Variable Documentation

◆ long_lock_bob

const struct m0_bob_type long_lock_bob
static
Initial value:
= {
.bt_name = "LONG_LOCK_BOB",
.bt_magix = M0_FOM_LL_MAGIC,
.bt_magix_offset = offsetof(struct m0_long_lock, l_magix)
}
#define offsetof(typ, memb)
Definition: misc.h:29

Definition at line 49 of file fom_long_lock.c.

◆ long_lock_link_bob

struct m0_bob_type long_lock_link_bob
static

Definition at line 57 of file fom_long_lock.c.