DirectoryLock.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2012 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 /* Util/genutil/DirectoryLock.h */
10 
11 #ifndef __DirectoryLock_h
12 #define __DirectoryLock_h
13 
14 #include "ThreadContext.h"
15 #include <string>
16 
19 {
20 
21  public:
22 
24  DirectoryLock (const char* path = 0);
25 
26  // set the directory in which system calls will be made
27  void set_directory (const std::string&);
28  // get the directory in which system calls will be made
29  std::string get_directory () const;
30 
31  // get the name of the file used to lock the directory
32  std::string get_lockfile () const;
33 
34  // lock the working directory
35  void lock ();
36  // unlock the working directory
37  void unlock ();
38  // clean the working directory
39  void clean ();
40 
42  class Push;
43 
44 protected:
45 
46  std::string path;
47  std::string lockfile;
48 
49 private:
50 
51  int lock_fd;
52  bool have_lock;
53  ThreadContext* context;
54 
55  void open_lockfile ();
56 
57 };
58 
71 {
72  std::string current;
73  DirectoryLock& lock;
74 
75  // disable copy constructor and assignment operator
76  Push (const Push&);
77  const Push& operator= (const Push&);
78 
79 public:
80 
82  Push (DirectoryLock& lock);
83 
85  ~Push ();
86 
87 };
88 
89 #endif
90 
~Push()
Unlocks the target working directory and restores.
Definition: DirectoryLock.C:150
Working directory in which only one process may operate at one time.
Definition: DirectoryLock.h:18
DirectoryLock(const char *path=0)
Default constructor.
Definition: DirectoryLock.C:25
A convenient exception handling class.
Definition: Error.h:54
ThreadContext class.
Definition: ThreadContext.h:15
Definition: DirectoryLock.h:70

Generated using doxygen 1.8.17