blob: 788f881d0058b02ea186f2b6c200a078ee4d4fab (
plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#ifndef __SITECING_SCOREBOARD_H
#define __SITECING_SCOREBOARD_H
#include <sys/types.h>
/**
* @file
* @brief the scoreboard manager.
*/
/**
* @def MAX_SITECING_SCOREBOARD_SLOTS
* The maximum number of slots scoreboard can hold.
*/
#define MAX_SITECING_SCOREBOARD_SLOTS 512
namespace sitecing {
/**
* The scoreboard slot.
*/
struct scoreboard_slot {
/**
* The state enumeration.
*/
enum _state {
/**
* The slot is free.
*/
state_free = 0,
/**
* The slot is allocated.
*/
state_allocated,
/**
* The process is idle.
*/
state_idle,
/**
* The process is accepting connection.
*/
state_accept,
/**
* The process is processing request.
*/
state_processing
} state;
pid_t pid;
};
/**
* The scoreboard manager.
*/
class scoreboard {
/**
* shared memory id.
*/
int shmid;
public:
/**
* Pointer to the scoreboard slots.
*/
scoreboard_slot *slots;
scoreboard();
~scoreboard();
/**
* Allocate a scoreboard slot.
* @return the slot number.
*/
int allocate_slot();
/**
* Free the slot allocated.
* @param slot the slot number.
*/
void free_slot(int slot);
/**
* Get the pointer to the slot.
* @param slot the slot number.
* @return the pointer.
*/
scoreboard_slot *get_slot(int slot);
/**
* Find the slot corresponding to the process ID.
* @param pid the process id.
* @return the slot number.
*/
int get_slot_by_pid(pid_t pid);
/**
* Count the slots in the particular state.
* @param state the state.
* @return the number of slots found.
*/
int count_slots(enum scoreboard_slot::_state state=scoreboard_slot::state_free);
};
}
#endif /* __SITECING_SCOREBOARD_H */
|