00001 // Copyright 2009-2010 Sandia Corporation. Under the terms 00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. 00003 // Government retains certain rights in this software. 00004 // 00005 // Copyright (c) 2009-2010, Sandia Corporation 00006 // All rights reserved. 00007 // 00008 // This file is part of the SST software package. For license 00009 // information, see the LICENSE file in the top level directory of the 00010 // distribution. 00011 00012 #ifndef __EVENTQUEUE_H 00013 /*----------------------------------------------------------+----------------\ 00014 | eventqueue.h | Chad D. Kersey | 00015 +-----------------------------------------------------------+----------------+ 00016 | Event Queue for managing callbacks in Psst. | 00017 \---------------------------------------------------------------------------*/ 00018 #define __EVENTQUEUE_H 00019 00020 #include "models/model.h" 00021 #include <map> 00022 #include <utility> 00023 00024 class EventQueue { 00025 public: 00026 uint64_t current_cycle; 00027 struct EventType { 00028 EventType(Models::CallbackHandler* model): m(model) {} 00029 Models::CallbackHandler *m; 00030 }; 00031 EventQueue(): current_cycle(0), eq() {} 00032 void add(Models::CallbackHandler* m, uint64_t cycle); // Add an event. 00033 uint64_t cycles(); // Get cycles until next event. 00034 uint64_t advance(); // Advance to next event, return number of cycles 00035 // passed. 00036 private: 00037 template <class T> struct Compare { 00038 bool operator()(const T& l, const T& r) { return l < r; } 00039 }; 00040 std::multimap<uint64_t, EventType, Compare<uint64_t> > eq; 00041 }; 00042 00043 #endif 00044