KLockFile

Search for usage in LXR

#include <KLockFile>

Public Types

enum  LockFlag { NoBlockFlag = 1, ForceFlag = 2 }
 
typedef QFlags< LockFlagLockFlags
 
enum  LockResult { LockOK = 0, LockFail, LockError, LockStale }
 

Public Member Functions

 KLockFile (const QString &file, const QString &componentName=QString())
 
 ~KLockFile ()
 
bool getLockInfo (int &pid, QString &hostname, QString &appname)
 
bool isLocked () const
 
LockResult lock (LockFlags flags=LockFlags())
 
void setStaleTime (int _staleTime)
 
int staleTime () const
 
void unlock ()
 

Detailed Description

The KLockFile class provides NFS safe lockfiles.

Author
Waldo Bastian basti[email protected][email protected][email protected]de.or[email protected]g
Deprecated:
since 5.0, please use QLockFile instead

Definition at line 37 of file klockfile.h.

Member Enumeration Documentation

◆ LockFlag

Enumerator
NoBlockFlag 

Return immediately, do not wait for the lock to become available.

ForceFlag 

Automatically remove a lock when a lock is detected that is stale for more than staleTime() seconds, or if the process that created it is not running anymore.

Definition at line 77 of file klockfile.h.

◆ LockResult

Possible return values of the lock function.

Enumerator
LockOK 

Lock was acquired successfully.

LockFail 

The lock could not be acquired because it is held by another process.

LockError 

The lock could not be acquired due to an error.

LockStale 

A stale lock has been detected.

Definition at line 55 of file klockfile.h.

Constructor & Destructor Documentation

◆ KLockFile()

KLockFile::KLockFile ( const QString file,
const QString componentName = QString() 
)
explicit

Constructor.

Deprecated:
since 5.0, use QLockFile(file), drop the component name.

Definition at line 114 of file klockfile_unix.cpp.

◆ ~KLockFile()

KLockFile::~KLockFile ( )

Destroys the object, releasing the lock if held.

Definition at line 120 of file klockfile_unix.cpp.

Member Function Documentation

◆ getLockInfo()

bool KLockFile::getLockInfo ( int &  pid,
QString hostname,
QString appname 
)

Returns the pid, hostname and appname of the process holding the lock after the lock functon has returned with LockStale.

Returns
false if the pid and hostname could not be determined
Deprecated:
since 5.0. Use QLockFile::getLockInfo(qint64 *pid, QString *hostname, QString *appname)

Definition at line 499 of file klockfile_unix.cpp.

◆ isLocked()

bool KLockFile::isLocked ( ) const

Returns whether the lock is held or not.

Definition at line 480 of file klockfile_unix.cpp.

◆ lock()

KLockFile::LockResult KLockFile::lock ( LockFlags  flags = LockFlags())

Attempt to acquire the lock.

Parameters
flagsA set of LockFlag values OR'ed together.
Deprecated:
since 5.0 KLockFile::lock() --> QLockFile::lock(). Possibly after setStaleLockTime(0), but only for the case of protecting a resource for a very long time. KLockFile::lock(NoBlockFlag) --> QLockFile::tryLock(). Possibly after setStaleLockTime(0), but only for the case of protecting a resource for a very long time. KLockFile::lock(ForceFlag) --> QLockFile::lock(). KLockFile::lock(NoBlockFlag|ForceFlag) --> QLockFile::tryLock(). Note that the return value is now simply a bool (success/failure).

Definition at line 390 of file klockfile_unix.cpp.

◆ setStaleTime()

void KLockFile::setStaleTime ( int  _staleTime)

Set the time in seconds after which a lock is considered stale.

Deprecated:
since 5.0.

WARNING: QLockFile::setStaleLockTime() is in ms, so multiply the argument by 1000.

Definition at line 133 of file klockfile_unix.cpp.

◆ staleTime()

int KLockFile::staleTime ( ) const

Return the time in seconds after which a lock is considered stale The default is 30.

Deprecated:
since 5.0. WARNING: QLockFile::staleLockTime() is in ms, so divide the result by 1000.

Definition at line 127 of file klockfile_unix.cpp.

◆ unlock()

void KLockFile::unlock ( )

Release the lock.

Definition at line 485 of file klockfile_unix.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:56:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.