39#include "blocxx/BLOCXX_config.h"
51 #ifdef BLOCXX_HAVE_UNISTD_H
65doLock(HANDLE hFile,
bool doWait, DWORD lockType)
67 if (hFile == INVALID_HANDLE_VALUE)
72 DWORD flags = lockType;
75 flags |= LOCKFILE_FAIL_IMMEDIATELY;
79 memset(&ov, 0,
sizeof(ov));
80 if (!LockFileEx(hFile, flags, 0, 0xffffffff,
96 DuplicateHandle(GetCurrentProcess(), x.m_hdl, GetCurrentProcess(),
97 &m_hdl , 0, FALSE, DUPLICATE_SAME_ACCESS);
102File::getLock(ELockType type)
104 return doLock(m_hdl,
true, type == E_WRITE_LOCK ?
105 LOCKFILE_EXCLUSIVE_LOCK : 0);
109File::tryLock(ELockType type)
111 return doLock(m_hdl,
false, type == E_WRITE_LOCK ?
112 LOCKFILE_EXCLUSIVE_LOCK : 0);
118 if (m_hdl == INVALID_HANDLE_VALUE)
124 memset(&ov, 0,
sizeof(ov));
125 if (!UnlockFileEx(m_hdl, 0, 0xffffffff, 0xffffffff, &ov))
146doLock(
int hdl,
int cmd,
short int type)
149 ::memset (&lck,
'\0',
sizeof (lck));
154 return ::fcntl(hdl, cmd, &lck);
175 return doLock(
m_hdl, F_SETLK, F_UNLCK);
185 Logger lgr(
"blocxx.common");
187 Format(
"Closing file handle %1 failed: %2",
#define BLOCXX_LOG_ERROR(logger, message)
Log message to logger with the Error level.
#define BLOCXX_INVALID_FILEHANDLE
The purpose of the File class is to provide an abstraction layer over the platform dependant function...
int unlock()
Release a lock on the file.
int tryLock(ELockType type=E_WRITE_LOCK)
Acquire a kernel lock on the file.
int close()
Close the underlying file object.
int getLock(ELockType type=E_WRITE_LOCK)
Acquire a kernel lock on the file.
@ E_WRITE_LOCK
Flag to place an write / exclusive lock.
File()
Create a NULL File object.