* example, be useful when performing IO across thread event
* queues when timing is not crucial (e.g., during fast
* forwarding).
+ *
+ * ScopedMigration does nothing if both eqs are the same
*/
class ScopedMigration
{
public:
- ScopedMigration(EventQueue *_new_eq)
- : new_eq(*_new_eq), old_eq(*curEventQueue())
+ ScopedMigration(EventQueue *_new_eq, bool _doMigrate = true)
+ :new_eq(*_new_eq), old_eq(*curEventQueue()),
+ doMigrate((&new_eq != &old_eq)&&_doMigrate)
{
- old_eq.unlock();
- new_eq.lock();
- curEventQueue(&new_eq);
+ if (doMigrate){
+ old_eq.unlock();
+ new_eq.lock();
+ curEventQueue(&new_eq);
+ }
}
~ScopedMigration()
{
- new_eq.unlock();
- old_eq.lock();
- curEventQueue(&old_eq);
+ if (doMigrate){
+ new_eq.unlock();
+ old_eq.lock();
+ curEventQueue(&old_eq);
+ }
}
private:
EventQueue &new_eq;
EventQueue &old_eq;
+ bool doMigrate;
};
/**
const char *description() const { return "EventWrapped"; }
};
+class EventFunctionWrapper : public Event
+{
+ private:
+ std::function<void(void)> callback;
+ std::string _name;
+
+ public:
+ EventFunctionWrapper(const std::function<void(void)> &callback,
+ const std::string &name,
+ bool del = false,
+ Priority p = Default_Pri)
+ : Event(p), callback(callback), _name(name)
+ {
+ if (del)
+ setFlags(AutoDelete);
+ }
+
+ void process() { callback(); }
+
+ const std::string
+ name() const
+ {
+ return _name + ".wrapped_function_event";
+ }
+
+ const char *description() const { return "EventFunctionWrapped"; }
+};
+
#endif // __SIM_EVENTQ_HH__