VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ipc.h
Go to the documentation of this file.
1 /*
2  * ipc.h
3  *
4  * Copyright 2007 - 2016 Brenton Ross
5  *
6  * This file is part of VICI.
7  *
8  * VICI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * VICI is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 #ifndef CFI_IPC_H
28 #define CFI_IPC_H
29 
30 #include <sys/types.h>
31 #include <sys/ipc.h>
32 #include <sys/sem.h>
33 #include "stringy.h"
34 
36 namespace VICI
37 {
38 
40 
45 namespace cfi
46 {
47 
48 // -----------------------------------------------------------------
49 
51 
63 class Semaphore
64 {
65 private:
66  int semid;
67  static const Path & getKeyFile();
68  static bool useIPC;
69  static struct sembuf Pexclusive[1];
70  static struct sembuf Vexclusive[1];
71  static struct sembuf Presource[1];
72  static struct sembuf Vresource[1];
73  static const int NSEMS = 2;
74 
75  // as specified in the man page for semctl
76  union semun {
77  int val; /* Value for SETVAL */
78  struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
79  unsigned short *array; /* Array for GETALL, SETALL */
80  struct seminfo *__buf; /* Buffer for IPC_INFO
81  (Linux-specific) */
82  };
83 
84 
85 public:
87 
90  Semaphore( char id ); // id is a single character that identifies this usage.
91 
93  ~Semaphore();
94 
96  void acquire();
97 
99  void release();
100 };
101 
102 // -----------------------------------------------------------------
103 
105 
112 {
113  Semaphore &sem;
114 public:
116 
119  explicit SemaphoreLock( Semaphore & s);
120 
122  ~SemaphoreLock();
123 };
124 
125 } // namespace cfi
126 } // namespace VICI
127 
128 #endif /* LOCK_H_ */
129 
130 // -------------------------------- end ---------------------------------
131 
void release()
release exclusive lock
Definition: ipc.cpp:230
Useful string functions.
~Semaphore()
Destructor.
Definition: ipc.cpp:179
Mutual exclusion lock.
Definition: ipc.h:111
~SemaphoreLock()
Destructor which releases the lock.
Definition: ipc.cpp:263
Semaphore(char id)
Constructor.
Definition: ipc.cpp:50
Manipulate path strings.
Definition: stringy.h:74
void acquire()
wait until available
Definition: ipc.cpp:206
SemaphoreLock(Semaphore &s)
Constructor which acquires a lock on the supplied semaphore.
Definition: ipc.cpp:255
A semaphore for managing exclusive access to resources across multiple processes. ...
Definition: ipc.h:63