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