-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess.h
48 lines (34 loc) · 1.41 KB
/
Process.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Process.h */
#ifndef PROCESS_H_INCLUDED
#define PROCESS_H_INCLUDED
#include "_core.h"
/* We allow 4 ints for a process bitmap - this limits
how many processes there can be. */
#define PROCESS_BITMAP_INTS 4
#define INT_BITS (sizeof(int)*8)
#define MAX_PROCESSES (INT_BITS*PROCESS_BITMAP_INTS)
/* A bitmap of processes, and macros for operations on it */
typedef struct {
int i[PROCESS_BITMAP_INTS];
} ProcessBitmap;
#define ProcessBitmap_SET(bmp, ndx) \
(bmp).i[(ndx)/INT_BITS] |= (1 << (ndx)%INT_BITS)
#define ProcessBitmap_IS_SET(bmp, ndx) \
(((bmp).i[(ndx)/INT_BITS] & (1 << (ndx)%INT_BITS)) != 0)
#define ProcessBitmap_CLEAR(bmp, ndx) \
(bmp).i[(ndx)/INT_BITS] &= ~(1 << (ndx)%INT_BITS)
/* Update these macros in accordance with PROCESS_BITMAP_INTS */
#define ProcessBitmap_IS_ZERO(bmp) \
((bmp).i[0] == 0 && (bmp).i[1] == 0 && (bmp).i[2] == 0 && (bmp).i[3] == 0)
#define ProcessBitmap_CLEAR_ALL(bmp) \
{(bmp).i[0] = 0; (bmp).i[1] = 0; (bmp).i[2] = 0; (bmp).i[3] = 0; }
#define ProcessBitmap_IS_ALL_SET(bmp) \
((bmp).i[0] == (~0) && (bmp).i[1] == (~0) \
&& (bmp).i[2] == (~0) && (bmp).i[3] == (~0))
/* Initializes this process. Should be called on startup and after a fork(). */
int Process_Init(void);
/* Called by a process when it terminates (normally). */
void Process_Cleanup(void);
/* Cleans up after a child process that has terminated abnormally. */
void Process_CleanupChild(int pid);
#endif