Asterisk - The Open Source Telephony Project  21.4.1
Macros | Enumerations | Functions
Named mutex and read-write locks

Macros

#define ast_named_lock_get(lock_type, keyspace, key)
 Geta named lock handle. More...
 
#define ast_named_lock_put(lock)   ao2_cleanup(lock)
 Put a named lock handle away. More...
 

Enumerations

enum  ast_named_lock_type { AST_NAMED_LOCK_TYPE_MUTEX = AO2_ALLOC_OPT_LOCK_MUTEX, AST_NAMED_LOCK_TYPE_RWLOCK = AO2_ALLOC_OPT_LOCK_RWLOCK }
 Which type of lock to request. More...
 

Functions

struct ast_named_lock__ast_named_lock_get (const char *filename, int lineno, const char *func, enum ast_named_lock_type lock_type, const char *keyspace, const char *key)
 

Detailed Description

Named mutex and read-write locks

Since
13.9.0

Locking some objects like sorcery objects can be tricky because the underlying ao2 object may not be the same for all callers. For instance, two threads that call ast_sorcery_retrieve_by_id on the same aor name might actually get 2 different ao2 objects if the underlying wizard had to rehydrate the aor from a database. Locking one ao2 object doesn't have any effect on the other even if those objects had locks in the first placeNamed locks allow access control by name. Now an aor named "1000" can be locked and any other thread attempting to lock the aor named "1000" will wait regardless of whether the underlying ao2 object is the same or not.To use a named lock: Call ast_named_lock_get with the appropriate keyspace and key. Use the standard ao2 lock/unlock functions as needed. Call ao2_cleanup when you're finished with it.

Macro Definition Documentation

#define ast_named_lock_get (   lock_type,
  keyspace,
  key 
)
Value:
__ast_named_lock_get(__FILE__, __LINE__, __PRETTY_FUNCTION__, lock_type, \
keyspace, key)

Geta named lock handle.

Since
13.9.0
Parameters
lock_typeOne of ast_named_lock_type
keyspace
key
Return values
Apointer to an ast_named_lock structure
NULLon error
Note
keyspace and key can be anything. For sorcery objects, keyspace could be the object type and key could be the object id.

Definition at line 83 of file named_locks.h.

#define ast_named_lock_put (   lock)    ao2_cleanup(lock)

Put a named lock handle away.

Since
13.9.0
Parameters
lockThe pointer to the ast_named_lock structure returned by ast_named_lock_get

Definition at line 93 of file named_locks.h.

Enumeration Type Documentation

Which type of lock to request.

Enumerator
AST_NAMED_LOCK_TYPE_MUTEX 

Request a named mutex.

AST_NAMED_LOCK_TYPE_RWLOCK 

Request a named read/write lock.

Definition at line 57 of file named_locks.h.