00001
00002 #ifndef CANCEL_H
00003 #define CANCEL_H
00004
00006 class CancelNode {
00007 public:
00009 POSE_TimeType timestamp;
00011 eventID evID;
00013 CancelNode *next;
00015 CancelNode() : timestamp(POSE_UnsetTS), next(NULL) { }
00017 CancelNode(POSE_TimeType ts, eventID e) :timestamp (ts), evID (e), next(NULL){ }
00019 void dump() {
00020 #if USE_LONG_TIMESTAMPS
00021 CkPrintf("[timestamp=%lld ", timestamp); evID.dump(); CkPrintf("] ");
00022 #else
00023 CkPrintf("[timestamp=%d ", timestamp); evID.dump(); CkPrintf("] ");
00024 #endif
00025 }
00027 void pup(PUP::er &p) { p(timestamp); evID.pup(p); }
00028 };
00029
00031 class CancelList {
00033 int count;
00035
00036 POSE_TimeType earliest;
00038 CancelNode *cancellations;
00040 CancelNode *current;
00041 public:
00043 CancelList() :
00044 count (0), earliest(POSE_UnsetTS), cancellations(NULL), current(NULL)
00045 {}
00047
00049 void Insert(POSE_TimeType ts, eventID e) {
00050 CancelNode *newnode = new CancelNode(ts, e);
00051 count++;
00052
00053
00054 if ((ts < earliest) || (earliest < 0))
00055 earliest = ts;
00056 newnode->next = cancellations;
00057 cancellations = newnode;
00058 if (!current) current = newnode;
00059 }
00061
00063 CancelNode *GetItem() {
00064 CancelNode *result;
00065 if (!current)
00066 CkPrintf("ERROR: CancelList::GetItem: CancelList is empty\n");
00067 result = current;
00068 if (current->next) current = current->next;
00069 else current = cancellations;
00070 return result;
00071 }
00073 void RemoveItem(CancelNode *item);
00075 inline int IsEmpty() {
00076 CmiAssert(((count == 0) && (cancellations == NULL)) ||
00077 ((count > 0) && (cancellations != NULL)));
00078 return (count == 0);
00079 }
00081 inline POSE_TimeType getEarliest() { return earliest; }
00083 void dump();
00085 void pup(PUP::er &p);
00086 };
00087
00088 #endif