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