From ce1f37aae46ea95020d7b865f7a80e8abdfad0d8 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Sat, 29 Jan 2005 21:21:05 +0000 Subject: initial commit into repository --- (limited to 'include/sitecing/scoreboard.h') 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 + +/** + * @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 */ -- cgit v0.9.0.2