def create(obj, priority=None):
if priority is None:
priority = internal.event.Event.Default_Pri
- return internal.event.PythonEvent(obj, priority)
+ return PythonEvent(obj, priority)
class Event(PythonEvent):
def __init__(self, priority=None):
#pragma SWIG nowarn=350,351
+%extend EventQueue {
+ void
+ schedule(Event *event, Tick when)
+ {
+ // Any python event that are scheduled must have their
+ // internal object's refcount incremented so that the object
+ // sticks around while it is in the event queue.
+ PythonEvent *pyevent = dynamic_cast<PythonEvent *>(event);
+ if (pyevent)
+ pyevent->incref();
+ $self->schedule(event, when);
+ }
+
+ void
+ deschedule(Event *event)
+ {
+ $self->deschedule(event);
+
+ // Now that we're removing the python object from the event
+ // queue, we need to decrement its reference count.
+ PythonEvent *pyevent = dynamic_cast<PythonEvent *>(event);
+ if (pyevent)
+ pyevent->decref();
+ }
+}
+
+%ignore EventQueue::schedule;
+%ignore EventQueue::deschedule;
+
%import "base/fast_alloc.hh"
%import "sim/serialize.hh"
{
if (object == NULL)
panic("Passed in invalid object");
-
- Py_INCREF(object);
-
- setFlags(AutoDelete);
}
PythonEvent::~PythonEvent()
{
- Py_DECREF(object);
}
void
async_event = true;
async_exception = true;
}
+
+ // Since the object has been removed from the event queue, its
+ // reference count must be decremented.
+ Py_DECREF(object);
}
CountedDrainEvent *
assert(event->getCount() == 0);
delete event;
}
-
-#if 0
-Event *
-create(PyObject *object, Event::Priority priority)
-{
- return new PythonEvent(object, priority);
-}
-
-void
-destroy(Event *event)
-{
- delete event;
-}
-#endif
PythonEvent(PyObject *obj, Event::Priority priority);
~PythonEvent();
+ void incref() { Py_INCREF(object); }
+ void decref() { Py_DECREF(object); }
+
virtual void process();
};
virtual const std::string name() const { return objName; }
// schedule the given event on this queue
- void schedule(Event *ev, Tick when);
- void deschedule(Event *ev);
- void reschedule(Event *ev, Tick when, bool always = false);
+ void schedule(Event *event, Tick when);
+ void deschedule(Event *event);
+ void reschedule(Event *event, Tick when, bool always = false);
Tick nextTick() const { return head->when(); }
Event *serviceOne();