diff options
author | Nathan Binkert <binkertn@umich.edu> | 2003-10-20 21:38:32 -0400 |
---|---|---|
committer | Nathan Binkert <binkertn@umich.edu> | 2003-10-20 21:38:32 -0400 |
commit | df488c0e70eb827d895c12aba85d5de168505b02 (patch) | |
tree | 8ffc2c6d88420cbd403272ddfb496020b26ecdd0 | |
parent | e0b065ff7c10dada97f562f13d7676253d48e793 (diff) | |
download | gem5-df488c0e70eb827d895c12aba85d5de168505b02.tar.xz |
Clean up callbacks
base/callback.hh:
Don't remove a callback when it is processed.
Document the callback class
--HG--
extra : convert_revision : 9d15500434fe0e5d623c624aac86976708adf0eb
-rw-r--r-- | base/callback.hh | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/base/callback.hh b/base/callback.hh index a1d23b5ed..eee629cf5 100644 --- a/base/callback.hh +++ b/base/callback.hh @@ -31,26 +31,76 @@ #include <list> -class Callback { +/** + * Generic callback class. This base class provides a virutal process + * function that gets called when the callback queue is processed. + */ +class Callback +{ public: + /** + * virtualize the destructor to make sure that the correct one + * gets called. + */ virtual ~Callback() {} + + /** + * virtual process function that is invoked when the callback + * queue is executed. + */ virtual void process() = 0; }; class CallbackQueue { protected: - std::list<Callback *> callbacks; + /** + * Simple typedef for the data structure that stores all of the + * callbacks. + */ + typedef std::list<Callback *> queue; + + /** + * List of all callbacks. To be called in fifo order. + */ + queue callbacks; public: - void add(Callback *callback) { callbacks.push_back(callback); } + /** + * Add a callback to the end of the queue + * @param callback the callback to be added to the queue + */ + void add(Callback *callback) + { + callbacks.push_back(callback); + } + + /** + * Find out if there are any callbacks in the queue + */ bool empty() const { return callbacks.empty(); } - void processOne() { - Callback *c = callbacks.front(); - callbacks.pop_front(); - c->process(); + + /** + * process all callbacks + */ + void process() + { + queue::iterator i = callbacks.begin(); + queue::iterator end = callbacks.end(); + + while (i != end) { + (*i)->process(); + ++i; + } + } + + /** + * clear the callback queue + */ + void clear() + { + callbacks.clear(); } - void processAll() { while (!empty()) processOne(); } }; #endif // __CALLBACK_HH__ |