summaryrefslogtreecommitdiffabout
path: root/include/sitecing/scoreboard.h
Side-by-side diff
Diffstat (limited to 'include/sitecing/scoreboard.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/scoreboard.h102
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 @@
+#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 */