root / tags / 1.0.8 / xapian-core / backends / flint / flint_lock.h

Revision 9989, 2.2 kB (checked in by olly, 12 months ago)

backends/flint/flint_lock.cc,backends/flint/flint_lock.h,
bin/xapian-check.cc: Apply tweaked version of patch for OS/2 support
by Yuri Dario.
AUTHORS: Add Yuri Dario.
PLATFORMS: Mention OS/2.

Line 
1/* flint_lock.h: database locking for flint backend.
2 *
3 * Copyright (C) 2005,2006,2007 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
18 * USA
19 */
20
21#ifndef XAPIAN_INCLUDED_FLINT_LOCK_H
22#define XAPIAN_INCLUDED_FLINT_LOCK_H
23
24#include <string>
25
26#if defined __CYGWIN__ || defined __WIN32__
27# include "safewindows.h"
28#elif defined __EMX__
29# define INCL_DOS
30# define INCL_DOSERRORS
31# include <os2.h>
32#else
33# include <sys/types.h>
34#endif
35
36class FlintLock {
37    std::string filename;
38#if defined __CYGWIN__ || defined __WIN32__
39    HANDLE hFile;
40#elif defined __EMX__
41    HFILE hFile;
42#else
43    int fd;
44    pid_t pid;
45#endif
46
47  public:
48    typedef enum {
49        SUCCESS, // We got the lock!
50        INUSE, // Already locked by someone else.
51        UNSUPPORTED, // Locking probably not supported (e.g. NFS without lockd).
52        UNKNOWN // The attempt failed for some unspecified reason.
53    } reason;
54#if defined __CYGWIN__ || defined __WIN32__
55    FlintLock(const std::string &filename_)
56        : filename(filename_), hFile(INVALID_HANDLE_VALUE) { }
57    operator bool() { return hFile != INVALID_HANDLE_VALUE; }
58#elif defined __EMX__
59    FlintLock(const std::string &filename_)
60        : filename(filename_), hFile(NULLHANDLE) { }
61    operator bool() { return hFile != NULLHANDLE; }
62#else
63    FlintLock(const std::string &filename_) : filename(filename_), fd(-1) { }
64    operator bool() { return fd != -1; }
65#endif
66    // Release any lock held when we're destroyed.
67    ~FlintLock() { release(); }
68
69    reason lock(bool exclusive);
70    void release();
71};
72
73#endif // XAPIAN_INCLUDED_FLINT_LOCK_H
Note: See TracBrowser for help on using the browser.