);
105 catch(exception&) {}
110 #if defined(NCBI_OS_UNIX) 117 # if defined(F_TLOCK) 118 if( lockf(fd, F_TLOCK, 0) < 0) {
121 # elif defined(F_SETLK) 122 structflock lockparam;
123lockparam.l_type = F_WRLCK;
125lockparam.l_start = 0;
127 while(fcntl(fd, F_SETLK, &lockparam) < 0) {
129 if(x_errno != EINTR) {
134 # error "No supported lock method. Please port this code." 168 "Attempt to lock already locked object "\
169 "in the same process");
175 #if defined(NCBI_OS_UNIX) 182 intfd = open(
m_SystemName.c_str(), O_CREAT | O_RDWR, perm);
206 unsigned longms_gran;
210ms_gran =
min(
ms/5, (
unsigned long)500);
221 if(x_errno != EACCES &&
222x_errno != EAGAIN ) {
227 unsigned longms_sleep = ms_gran;
228 if(ms_sleep >
ms) {
241 "The lock could not be acquired in the time "\
251 "Error creating lock");
256 #elif defined(NCBI_OS_MSWIN) 259errno_t errcode = ::GetLastError();
262 caseERROR_ACCESS_DENIED:
266 "The lock already exists");
268 caseERROR_INVALID_HANDLE:
271 "Error creating lock, system object with the same"\
272 "name already exists");
277 "Error creating lock");
282 if(errcode == ERROR_ALREADY_EXISTS) {
286res = WaitForSingleObject(handle, INFINITE);
295::CloseHandle(handle);
297 "The lock could not be acquired in the time "\
306::CloseHandle(handle);
308 "Error creating lock");
324 "Attempt to unlock not-yet-acquired lock");
333 if( it->second > 1 ) {
341 #if defined(NCBI_OS_UNIX) 343 # if defined(F_TLOCK) 344 intres = lockf(
m_Handle, F_ULOCK, 0);
345 # elif defined(F_SETLK) 346 structflock lockparam;
347lockparam.l_type = F_UNLCK;
349lockparam.l_start = 0;
351 intres = fcntl(
m_Handle, F_SETLK, &lockparam);
353 # error "No supported lock method. Please port this code." 357 "Cannot release the lock");
361 #elif defined(NCBI_OS_MSWIN) 362 if( !::ReleaseMutex(
m_Handle) ) {
364 "Cannot release the lock");
CInterProcessLockException â.
CTimeout â Timeout interval.
container_type::iterator iterator
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
TErrCode GetErrCode(void) const
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
static bool IsAbsolutePath(const string &path)
Check if a "path" is absolute for the current OS.
static mode_t MakeModeT(TMode user_mode, TMode group_mode, TMode other_mode, TSpecialModeBits special)
Construct mode_t value from permission modes.
@ fWrite
Write permission.
string m_SystemName
Adjusted name of the lock.
bool TryLock(void)
Try to acquire the lock.
void Unlock(void)
Release the lock.
~CInterProcessLock(void)
Call Unlock()
void Lock(const CTimeout &timeout=CTimeout(CTimeout::eInfinite), const CTimeout &granularity=CTimeout(CTimeout::eInfinite))
CInterProcessLock(const string &name)
void Remove(void)
Call Unlock() and removes lock object from the system.
string m_Name
Original name of the lock.
virtual const char * GetErrCodeString(void) const override
Translate from an error code value to its string representation.
@ eUnlockError
Cannot release the lock.
@ eLockError
Cannot acquire a lock (not eLockTimeout, eCreateError)
@ eLockTimeout
The lock could not be acquired in the time allotted.
@ eNotLocked
Attempt to unlock a not-yet-acquired lock.
@ eMultipleLocks
Attempt to lock already locked object in the same process.
@ eCreateError
Cannot create the lock object in the OS.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
unsigned long GetAsMilliSeconds(void) const
Get as number of milliseconds.
#define HANDLE
An abstraction for a file handle.
static CSafeStatic< TLocks > s_Locks
DEFINE_STATIC_FAST_MUTEX(s_ProcessLock)
static int s_UnixLock(int fd)
Try to acquire a lock for specified file descriptor.
const int kInvalidLockHandle
System specific invalid lock handle.
map< string, int > TLocks
Simple inter-process lock.
#define TRUE
bool replacment for C indicating true.
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static SLJIT_INLINE sljit_ins ms(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4