From aa674a65f1dccc2850fe03d2456b80af94661c33 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sun, 18 Dec 2011 23:36:54 -0800 Subject: [PATCH] implement PointerWrap::DoLinkedList and use it to simplify saving CoreTiming events --- Source/Core/Common/Src/ChunkFile.h | 62 +++++++++++++++++++++++++++-- Source/Core/Core/Src/CoreTiming.cpp | 60 ++++++---------------------- 2 files changed, 71 insertions(+), 51 deletions(-) diff --git a/Source/Core/Common/Src/ChunkFile.h b/Source/Core/Common/Src/ChunkFile.h index 4ed781dcbd..b710f14ad3 100644 --- a/Source/Core/Common/Src/ChunkFile.h +++ b/Source/Core/Common/Src/ChunkFile.h @@ -179,10 +179,64 @@ public: DoVoid((void *)&x, sizeof(x)); } - template - void DoLinkedList(LinkedListItem **list_start) { - // TODO - PanicAlert("Do(linked list<>) does not yet work."); + template* (*TNew)(), void (*TFree)(LinkedListItem*), void (*TDo)(PointerWrap&, T*)> + void DoLinkedList(LinkedListItem*& list_start, LinkedListItem** list_end=0) + { + LinkedListItem* list_cur = list_start; + LinkedListItem* prev = 0; + + while (true) + { + u8 shouldExist = (list_cur ? 1 : 0); + Do(shouldExist); + if (shouldExist == 1) + { + LinkedListItem* cur = list_cur ? list_cur : TNew(); + TDo(*this, (T*)cur); + if (!list_cur) + { + if (mode == MODE_READ) + { + cur->next = 0; + list_cur = cur; + if (prev) + prev->next = cur; + else + list_start = cur; + } + else + { + TFree(cur); + continue; + } + } + } + else + { + if (mode == MODE_READ) + { + if (prev) + prev->next = 0; + if (list_end) + *list_end = prev; + if (list_cur) + { + if (list_start == list_cur) + list_start = 0; + do + { + LinkedListItem* next = list_cur->next; + TFree(list_cur); + list_cur = next; + } + while (list_cur); + } + } + break; + } + prev = list_cur; + list_cur = list_cur->next; + } } void DoMarker(const char* prevName, u32 arbitraryNumber=0x42) diff --git a/Source/Core/Core/Src/CoreTiming.cpp b/Source/Core/Core/Src/CoreTiming.cpp index 235593d679..ac3b969147 100644 --- a/Source/Core/Core/Src/CoreTiming.cpp +++ b/Source/Core/Core/Src/CoreTiming.cpp @@ -47,7 +47,7 @@ struct BaseEvent typedef LinkedListItem Event; -// STATE_TO_SAVE (how?) +// STATE_TO_SAVE Event *first; Event *tsFirst; Event *tsLast; @@ -153,6 +153,13 @@ void Shutdown() } } +void EventDoState(PointerWrap &p, BaseEvent* ev) +{ + p.Do(ev->time); + p.Do(ev->type); + p.Do(ev->userdata); +} + void DoState(PointerWrap &p) { std::lock_guard lk(externalEventSection); @@ -165,53 +172,12 @@ void DoState(PointerWrap &p) p.Do(fakeTBStartValue); p.Do(fakeTBStartTicks); p.DoMarker("CoreTimingData"); - // OK, here we're gonna need to specialize depending on the mode. - // Should do something generic to serialize linked lists. - switch (p.GetMode()) { - case PointerWrap::MODE_READ: - { - ClearPendingEvents(); - if (first) - PanicAlertT("Clear failed."); - int more_events = 0; - Event *prev = 0; - while (true) { - p.Do(more_events); - if (!more_events) - break; - Event *ev = GetNewEvent(); - if (!prev) - first = ev; - else - prev->next = ev; - p.Do(ev->time); - p.Do(ev->type); - p.Do(ev->userdata); - ev->next = 0; - prev = ev; - ev = ev->next; - } - } - break; - case PointerWrap::MODE_MEASURE: - case PointerWrap::MODE_VERIFY: - case PointerWrap::MODE_WRITE: - { - Event *ev = first; - int more_events = 1; - while (ev) { - p.Do(more_events); - p.Do(ev->time); - p.Do(ev->type); - p.Do(ev->userdata); - ev = ev->next; - } - more_events = 0; - p.Do(more_events); - break; - } - } + + p.DoLinkedList(first); p.DoMarker("CoreTimingEvents"); + + p.DoLinkedList(tsFirst, &tsLast); + p.DoMarker("CoreTimingTsEvents"); } u64 GetTicks()