Diffstat (limited to 'include/sitecing/scoreboard.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | include/sitecing/scoreboard.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/include/sitecing/scoreboard.h b/include/sitecing/scoreboard.h new file mode 100644 index 0000000..788f881 --- a/dev/null +++ b/include/sitecing/scoreboard.h | |||
@@ -0,0 +1,102 @@ | |||
1 | #ifndef __SITECING_SCOREBOARD_H | ||
2 | #define __SITECING_SCOREBOARD_H | ||
3 | |||
4 | #include <sys/types.h> | ||
5 | |||
6 | /** | ||
7 | * @file | ||
8 | * @brief the scoreboard manager. | ||
9 | */ | ||
10 | |||
11 | /** | ||
12 | * @def MAX_SITECING_SCOREBOARD_SLOTS | ||
13 | * The maximum number of slots scoreboard can hold. | ||
14 | */ | ||
15 | #define MAX_SITECING_SCOREBOARD_SLOTS512 | ||
16 | |||
17 | namespace sitecing { | ||
18 | |||
19 | /** | ||
20 | * The scoreboard slot. | ||
21 | */ | ||
22 | struct scoreboard_slot { | ||
23 | /** | ||
24 | * The state enumeration. | ||
25 | */ | ||
26 | enum _state { | ||
27 | /** | ||
28 | * The slot is free. | ||
29 | */ | ||
30 | state_free = 0, | ||
31 | /** | ||
32 | * The slot is allocated. | ||
33 | */ | ||
34 | state_allocated, | ||
35 | /** | ||
36 | * The process is idle. | ||
37 | */ | ||
38 | state_idle, | ||
39 | /** | ||
40 | * The process is accepting connection. | ||
41 | */ | ||
42 | state_accept, | ||
43 | /** | ||
44 | * The process is processing request. | ||
45 | */ | ||
46 | state_processing | ||
47 | } state; | ||
48 | pid_t pid; | ||
49 | }; | ||
50 | |||
51 | /** | ||
52 | * The scoreboard manager. | ||
53 | */ | ||
54 | class scoreboard { | ||
55 | /** | ||
56 | * shared memory id. | ||
57 | */ | ||
58 | int shmid; | ||
59 | public: | ||
60 | /** | ||
61 | * Pointer to the scoreboard slots. | ||
62 | */ | ||
63 | scoreboard_slot *slots; | ||
64 | |||
65 | scoreboard(); | ||
66 | ~scoreboard(); | ||
67 | |||
68 | /** | ||
69 | * Allocate a scoreboard slot. | ||
70 | * @return the slot number. | ||
71 | */ | ||
72 | int allocate_slot(); | ||
73 | /** | ||
74 | * Free the slot allocated. | ||
75 | * @param slot the slot number. | ||
76 | */ | ||
77 | void free_slot(int slot); | ||
78 | |||
79 | /** | ||
80 | * Get the pointer to the slot. | ||
81 | * @param slot the slot number. | ||
82 | * @return the pointer. | ||
83 | */ | ||
84 | scoreboard_slot *get_slot(int slot); | ||
85 | /** | ||
86 | * Find the slot corresponding to the process ID. | ||
87 | * @param pid the process id. | ||
88 | * @return the slot number. | ||
89 | */ | ||
90 | int get_slot_by_pid(pid_t pid); | ||
91 | |||
92 | /** | ||
93 | * Count the slots in the particular state. | ||
94 | * @param state the state. | ||
95 | * @return the number of slots found. | ||
96 | */ | ||
97 | int count_slots(enum scoreboard_slot::_state state=scoreboard_slot::state_free); | ||
98 | }; | ||
99 | |||
100 | } | ||
101 | |||
102 | #endif /* __SITECING_SCOREBOARD_H */ | ||