00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_FLINT_LOCK_H
00022 #define XAPIAN_INCLUDED_FLINT_LOCK_H
00023
00024 #include <string>
00025
00026 #if defined __CYGWIN__ || defined __WIN32__
00027 # include "safewindows.h"
00028 #elif defined __EMX__
00029 # define INCL_DOS
00030 # define INCL_DOSERRORS
00031 # include <os2.h>
00032 #else
00033 # include <sys/types.h>
00034 #endif
00035
00036 class FlintLock {
00037 std::string filename;
00038 #if defined __CYGWIN__ || defined __WIN32__
00039 HANDLE hFile;
00040 #elif defined __EMX__
00041 HFILE hFile;
00042 #else
00043 int fd;
00044 pid_t pid;
00045 #endif
00046
00047 public:
00048 typedef enum {
00049 SUCCESS,
00050 INUSE,
00051 UNSUPPORTED,
00052 UNKNOWN
00053 } reason;
00054 #if defined __CYGWIN__ || defined __WIN32__
00055 FlintLock(const std::string &filename_)
00056 : filename(filename_), hFile(INVALID_HANDLE_VALUE) { }
00057 operator bool() { return hFile != INVALID_HANDLE_VALUE; }
00058 #elif defined __EMX__
00059 FlintLock(const std::string &filename_)
00060 : filename(filename_), hFile(NULLHANDLE) { }
00061 operator bool() { return hFile != NULLHANDLE; }
00062 #else
00063 FlintLock(const std::string &filename_) : filename(filename_), fd(-1) { }
00064 operator bool() { return fd != -1; }
00065 #endif
00066
00067 ~FlintLock() { release(); }
00068
00069 reason lock(bool exclusive);
00070 void release();
00071 };
00072
00073 #endif // XAPIAN_INCLUDED_FLINT_LOCK_H