eventq: Clean up some flags

- Make the initialized flag always available, not just in debug mode.
- Make the Initialized flag actually use several bits so it is very
unlikely that something that's uninitialized accidentally looks
initialized.
- Add an initialized() function that tells you if the current event is
indeed  initialized.
- Clear the flags on delete so it can't be accidentally thought of as
initialized.
- Fix getFlags assert statement.  "How did this ever work?"
This commit is contained in:
Nathan Binkert 2010-04-02 15:28:22 -07:00
parent 2ee3edba8e
commit f32674d9bc
2 changed files with 22 additions and 23 deletions

View file

@ -60,6 +60,7 @@ Counter Event::instanceCounter = 0;
Event::~Event() Event::~Event()
{ {
assert(!scheduled()); assert(!scheduled());
flags = 0;
} }
const std::string const std::string

View file

@ -68,17 +68,22 @@ class Event : public Serializable, public FastAlloc
typedef short FlagsType; typedef short FlagsType;
typedef ::Flags<FlagsType> Flags; typedef ::Flags<FlagsType> Flags;
static const FlagsType PublicRead = 0x003f; static const FlagsType PublicRead = 0x003f; // public readable flags
static const FlagsType PublicWrite = 0x001d; static const FlagsType PublicWrite = 0x001d; // public writable flags
static const FlagsType Squashed = 0x0001; static const FlagsType Squashed = 0x0001; // has been squashed
static const FlagsType Scheduled = 0x0002; static const FlagsType Scheduled = 0x0002; // has been scheduled
static const FlagsType AutoDelete = 0x0004; static const FlagsType AutoDelete = 0x0004; // delete after dispatch
static const FlagsType AutoSerialize = 0x0008; static const FlagsType AutoSerialize = 0x0008; // must be serialized
static const FlagsType IsExitEvent = 0x0010; static const FlagsType IsExitEvent = 0x0010; // special exit event
static const FlagsType IsMainQueue = 0x0020; static const FlagsType IsMainQueue = 0x0020; // on main event queue
#ifdef EVENTQ_DEBUG static const FlagsType Initialized = 0x7a40; // somewhat random bits
static const FlagsType Initialized = 0xf000; static const FlagsType InitMask = 0xffc0; // mask for init bits
#endif
bool
initialized() const
{
return this && (flags & InitMask) == Initialized;
}
public: public:
typedef int8_t Priority; typedef int8_t Priority;
@ -146,7 +151,7 @@ class Event : public Serializable, public FastAlloc
Flags Flags
getFlags(Flags _flags) const getFlags(Flags _flags) const
{ {
assert(flags.noneSet(~PublicRead)); assert(_flags.noneSet(~PublicRead));
return flags.isSet(_flags); return flags.isSet(_flags);
} }
@ -242,14 +247,13 @@ class Event : public Serializable, public FastAlloc
* @param queue that the event gets scheduled on * @param queue that the event gets scheduled on
*/ */
Event(Priority p = Default_Pri) Event(Priority p = Default_Pri)
: nextBin(NULL), nextInBin(NULL), _priority(p) : nextBin(NULL), nextInBin(NULL), _priority(p), flags(Initialized)
{ {
#ifndef NDEBUG #ifndef NDEBUG
instance = ++instanceCounter; instance = ++instanceCounter;
queue = NULL; queue = NULL;
#endif #endif
#ifdef EVENTQ_DEBUG #ifdef EVENTQ_DEBUG
flags.set(Initialized);
whenCreated = curTick; whenCreated = curTick;
whenScheduled = 0; whenScheduled = 0;
#endif #endif
@ -478,9 +482,7 @@ EventQueue::schedule(Event *event, Tick when)
{ {
assert((UTick)when >= (UTick)curTick); assert((UTick)when >= (UTick)curTick);
assert(!event->scheduled()); assert(!event->scheduled());
#ifdef EVENTQ_DEBUG assert(event->initialized());
assert((event->flags & Event::Initialized) == Event::Initialized);
#endif
event->setWhen(when, this); event->setWhen(when, this);
insert(event); insert(event);
@ -498,9 +500,7 @@ inline void
EventQueue::deschedule(Event *event) EventQueue::deschedule(Event *event)
{ {
assert(event->scheduled()); assert(event->scheduled());
#ifdef EVENTQ_DEBUG assert(event->initialized());
assert((event->flags & Event::Initialized) == Event::Initialized);
#endif
remove(event); remove(event);
@ -519,9 +519,7 @@ EventQueue::reschedule(Event *event, Tick when, bool always)
{ {
assert(when >= curTick); assert(when >= curTick);
assert(always || event->scheduled()); assert(always || event->scheduled());
#ifdef EVENTQ_DEBUG assert(event->initialized());
assert((event->flags & Event::Initialized) == Event::Initialized);
#endif
if (event->scheduled()) if (event->scheduled())
remove(event); remove(event);