ATLAS Offline Software
Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
Athena::DBLock Class Reference

Common database lock. More...

#include <DBLock.h>

Collaboration diagram for Athena::DBLock:

Public Member Functions

 DBLock ()
 Constructor. More...
 
 DBLock (const DBLock &)=default
 
 DBLock (DBLock &&)=default
 
DBLockoperator= (const DBLock &)=default
 
DBLockoperator= (DBLock &&)=default
 
 ~DBLock ()
 Destructor. More...
 

Private Types

using lock_t = std::unique_lock< std::recursive_mutex >
 Shared pointer to underlying lock. More...
 

Private Attributes

std::shared_ptr< lock_tm_lockPtr
 

Static Private Attributes

static std::recursive_mutex m_mutex
 Global mutex to protect database access. More...
 

Detailed Description

Common database lock.

Athena has multiple packages that access the database independently, for example IOVDbSvc (via COOL) and RDBAccessSvc. These are all locked internally, but they don't know about each other. Further, some of the underlying database code which they can both use, such as frontier, is not thread-safe. Thus, we can get crashes if, say, IOVDbSvc and RDBAccessSvc are executing in different threads.

To solve this without introducing a depedency between these packages, we introduce this package containing only this lock class. Any Athena package that needs exclusive access to the database layer can then acquire the lock here.

The DBLock object copyable; it holds the underlying lock via a shared_ptr. Further, the underlying mutex is recursive.

Beware of potential deadlocks if this is used in conjunction with another lock. Best to always acquire the locks in the same order.

Definition at line 45 of file DBLock.h.

Member Typedef Documentation

◆ lock_t

using Athena::DBLock::lock_t = std::unique_lock<std::recursive_mutex>
private

Shared pointer to underlying lock.

This allows these objects to be copyable.

Definition at line 62 of file DBLock.h.

Constructor & Destructor Documentation

◆ DBLock() [1/3]

Athena::DBLock::DBLock ( )

Constructor.

Definition at line 25 of file DBLock.cxx.

26  : m_lockPtr (std::make_shared<lock_t> (m_mutex))
27 {
28 }

◆ DBLock() [2/3]

Athena::DBLock::DBLock ( const DBLock )
default

◆ DBLock() [3/3]

Athena::DBLock::DBLock ( DBLock &&  )
default

◆ ~DBLock()

Athena::DBLock::~DBLock ( )

Destructor.

Definition at line 34 of file DBLock.cxx.

35 {
36 }

Member Function Documentation

◆ operator=() [1/2]

DBLock& Athena::DBLock::operator= ( const DBLock )
default

◆ operator=() [2/2]

DBLock& Athena::DBLock::operator= ( DBLock &&  )
default

Member Data Documentation

◆ m_lockPtr

std::shared_ptr<lock_t> Athena::DBLock::m_lockPtr
private

Definition at line 63 of file DBLock.h.

◆ m_mutex

std::recursive_mutex Athena::DBLock::m_mutex
staticprivate

Global mutex to protect database access.

Definition at line 58 of file DBLock.h.


The documentation for this class was generated from the following files:
Athena::DBLock::m_lockPtr
std::shared_ptr< lock_t > m_lockPtr
Definition: DBLock.h:63
Athena::DBLock::m_mutex
static std::recursive_mutex m_mutex
Global mutex to protect database access.
Definition: DBLock.h:58