ucommon
process.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef COMMONCPP_PROCESS_H_
44 #define COMMONCPP_PROCESS_H_
45 
46 #ifndef COMMONCPP_CONFIG_H_
47 #include <commoncpp/config.h>
48 #endif
49 
50 #ifndef COMMONCPP_THREAD_H_
51 #include <commoncpp/thread.h>
52 #endif
53 
54 namespace ost {
55 
66 class __EXPORT Process
67 {
68 private:
69  static bool rtflag;
70 
71 public:
72 #ifndef _MSWINDOWS_
73  typedef void (*Trap)(int);
74 
80  static void detach(void);
81 
89  static void attach(const char *devname);
90 
98  static Trap setPosixSignal(int signo, Trap handler);
99 
107  static Trap setInterruptSignal(int signo, Trap handler);
108 #endif
109 
117  bool lock(bool future = true);
118 
122  void unlock(void);
123 
141  static int spawn(const char *exec, const char **argv, bool wait = true);
142 
150  static int join(int pid);
151 
159  static bool cancel(int pid, int sig = 0);
160 
167  static const char *getEnv(const char *name);
168 
176  static void setEnv(const char *name, const char *value, bool overwrite);
177 
183  static const char *getConfigDir(void);
184 
190  static const char *getHomeDir(void);
191 
197  static const char *getUser(void);
198 
204  static bool setUser(const char *id, bool grp = true);
205 
211  static bool setGroup(const char *id);
212 
218  static size_t getPageSize(void);
219 
223  static void setPriority(int pri);
224 
228  static void setScheduler(const char *policy);
229 
233  static void setRealtime(int pri = 0);
234 
238  static bool isScheduler(void);
239 
243  static inline bool isRealtime(void)
244  {return rtflag;}
245 };
246 
256 class __EXPORT Lockfile
257 {
258 private:
259 #ifdef _MSWINDOWS_
260  HANDLE _mutex;
261  bool _flagged;
262 #else
263  char *_path;
264 #endif
265 
266 public:
272  Lockfile(const char *name);
273 
277  Lockfile();
278 
283  {unlock();}
284 
293  bool lock(const char *name);
294 
298  void unlock(void);
299 
305  bool isLocked(void);
306 };
307 
308 } // namespace ost
309 
310 #endif
Common C++ thread class and sychronization objects.
Definition: address.h:58
A class for containing portable process related functions that help create portable code...
Definition: process.h:66
This class is used to create a "named" lock entity that can be used to control access to a resource b...
Definition: process.h:256
static bool isRealtime(void)
Return true if realtime scheduling.
Definition: process.h:243
void wait(barrier_t &barrier)
Convenience function to wait on a barrier.
Definition: thread.h:1925
void unlock(ExclusiveAccess &object)
Convenience function to unlock an exclusive object through it's protocol.
Definition: access.h:246
~Lockfile()
Destroy the current lock and release it.
Definition: process.h:282
void lock(ExclusiveAccess &object)
Convenience function to exclusively lock an object through it's protocol.
Definition: access.h:239