KDBusAddons 5.109.0
Signals | Public Member Functions | List of all members
KDBusInterProcessLock

A class for serializing access to a resource that is shared between multiple processes. More...

#include <KDBusInterProcessLock>

Signals

void lockGranted (KDBusInterProcessLock *lock)
 This signal is emitted when the requested lock has been granted.
 

Public Member Functions

 KDBusInterProcessLock (const QString &resource)
 Creates a new inter process lock object.
 
 ~KDBusInterProcessLock () override
 Destroys the inter process lock object.
 
void lock ()
 Requests the lock.
 
QString resource () const
 Returns the identifier of the resource the lock is set on.
 
void unlock ()
 Releases the lock.
 
void waitForLockGranted ()
 Waits for the granting of a lock by starting an internal event loop.
 

Detailed Description

A class for serializing access to a resource that is shared between multiple processes.

This class can be used to serialize access to a resource between multiple processes. Instead of using lock files, which could become stale easily, the registration of dummy D-Bus services is used to allow only one process at a time to access the resource.

Example:

connect(lock, &KDBusInterProcessLock::lockGranted, this, &MyClass::doCriticalTask);
lock->lock();
...
... ::doCriticalTask(KDBusInterProcessLock *lock)
{
// change common resource
lock->unlock();
}
A class for serializing access to a resource that is shared between multiple processes.
Definition kdbusinterprocesslock.h:52
void lock()
Requests the lock.
void lockGranted(KDBusInterProcessLock *lock)
This signal is emitted when the requested lock has been granted.
void unlock()
Releases the lock.
Author
Tobias Koenig tokoe.nosp@m.@kde.nosp@m..org

Constructor & Destructor Documentation

◆ KDBusInterProcessLock()

KDBusInterProcessLock::KDBusInterProcessLock ( const QString &  resource)

Creates a new inter process lock object.

Parameters
resourceThe identifier of the resource that shall be locked. This identifier can be any string, however it must be unique for the resource and every client that wants to access the resource must know it.

◆ ~KDBusInterProcessLock()

KDBusInterProcessLock::~KDBusInterProcessLock ( )
override

Destroys the inter process lock object.

Member Function Documentation

◆ lock()

void KDBusInterProcessLock::lock ( )

Requests the lock.

The lock is granted as soon as the lockGranted() signal is emitted.

◆ lockGranted

void KDBusInterProcessLock::lockGranted ( KDBusInterProcessLock lock)
signal

This signal is emitted when the requested lock has been granted.

Parameters
lockThe lock that has been granted.

◆ resource()

QString KDBusInterProcessLock::resource ( ) const

Returns the identifier of the resource the lock is set on.

◆ unlock()

void KDBusInterProcessLock::unlock ( )

Releases the lock.

Note
This method should be called as soon as the critical area is left in your code path and the lock is no longer needed.

◆ waitForLockGranted()

void KDBusInterProcessLock::waitForLockGranted ( )

Waits for the granting of a lock by starting an internal event loop.