Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document last changes
[simgrid.git] / src / nws_portability / Include / osutil.h
1 /* $Id$ */
2
3
4 #ifndef OSUTIL_H
5 #define OSUTIL_H
6
7
8 /*
9 ** This package defines functions for working with operating system facilities.
10 */
11
12
13 #include <sys/types.h>  /* mode_t size_t */
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /*
20 ** Returns a best-guess estimate of the number of CPUs on the system.
21 */
22 int
23 CPUCount(void);
24
25
26 /*
27 ** Returns the current time in number of seconds since midnight 1/1/1970, GMT.
28 */
29 double
30 CurrentTime(void);
31
32
33 /*
34 ** Returns the environment value for the variable #name#.  This value is
35 ** determined in one of three ways: if an environment variable of that name is
36 ** set, its value is used; otherwise, if a file named #rcName# in one of the
37 ** colon-delimited set of directories #rcDirs# contains a line of the form
38 ** #name#=value, then that value is used; otherwise #defaultValue# is used.
39 ** For convenience, a directory of "~" in #rcDirs# is expanded to the contents
40 ** of the HOME environment variable.
41 */
42 const char *
43 GetEnvironmentValue(const char *name,
44                     const char *rcDirs,
45                     const char *rcName,
46                     const char *defaultValue);
47
48
49 /*
50 ** Attempts to determine the login id of the user running the binary.  Returns
51 ** 1 and copies the name into the #length#-long array name if successful, else
52 ** returns 0.
53 */
54 int
55 GetUserName(char *name,
56             size_t length);
57
58
59 /*
60  * Wrapper around the system signal() for the SIGALRM signal.
61  * new_hanlder is the handler to be installed and old_handler (if not
62  * NULL) will contain the handler to be substituted.  
63  * Return 1 upon * success and 0 otherwise.
64  *
65  */
66 typedef void(* handler)(int sig);
67 int
68 SignalAlarm(    handler new_handler,
69                 handler *old_handler);
70
71 /*
72 ** Prevents the O/S from raising the signal #sig# until a subsequent call to
73 ** ReleaseSignal() is made.
74 */
75 void
76 HoldSignal(int sig);
77
78
79 /*
80 ** Creates the directory specified by #path# with mode #mode#.  If
81 ** #makeEntirePath# is non-zero, any missing subpaths in #path# will also be
82 ** created.  Returns 1 if successful, else 0.
83 */
84 int
85 MakeDirectory(const char *path,
86               mode_t mode,
87               int makeEntirePath);
88
89
90 /*
91 ** Returns the number of microseconds that have elapsed since midnight, local
92 ** time.
93 */
94 long int
95 MicroTime(void);
96
97
98 /*
99 ** Allows the O/S to raise the signal #sig#.
100 */
101 void
102 ReleaseSignal(int sig);
103
104
105 /*
106 ** Starts a timer that will raise a SIGALRM in #numberOfSecs# seconds.
107 */
108 void
109 SetRealTimer(unsigned int numberOfSecs);
110 #define RESETREALTIMER SetRealTimer(0)
111
112 /**
113  * Locks are handled in a peculiar way: #lock# is a void * passed in by
114  * the module. If #lock# is NULL, GetNWSLock() will assign to it a mutex
115  * and then it will lock it. It's up to the module to keep track of the
116  * different locks.
117  * Returns 1 if succesfull 0 otherwise.
118  */
119 int
120 GetNWSLock(void **lock);
121
122 /**
123  * release the NWS general lock. Returns 1 if succesful, 0 otherwise.
124  */
125 int
126 ReleaseNWSLock(void **lock);
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif