1 #ifndef __SNAPINTERFACE_H
2 #define __SNAPINTERFACE_H
11 #include "libthreads.h"
12 typedef std::basic_string< char, std::char_traits< char >, MyAlloc< char > > MyString;
13 namespace snapshot_utils{
15 SnapshotTree defines the interfaces and ideal points that require snapshotting.
16 The algorithm is: When a step happens we create a new Tree node and define that node as the current scope.
17 when it is time to set a backtracking point, for each backtracking point we record its parent
18 finally when set current scope is called, we see if this state is a parent
19 where possible the goal is speed so we use an integer comparison to make all comparison operations required for
20 finding a given node O 1
22 typedef std::map< thrd_t, int, std::less< thrd_t >, MyAlloc< std::pair< const thrd_t, int > > > ThreadStepMap_t;
23 MyString SerializeThreadSteps( const ThreadStepMap_t & theMap );
25 struct snapshotTreeComp{
27 bool operator()( const std::pair< const snapshotTree*, snapshot_id > & lhs, const std::pair< const snapshotTree*, snapshot_id > & rhs );
30 typedef std::map< snapshotTree *, snapshot_id, snapshotTreeComp, MyAlloc< std::pair< const snapshotTree *, snapshot_id > > > SnapshotToStateMap_t;
31 typedef std::set< snapshotTree*, std::less< snapshotTree * >, MyAlloc< snapshotTree > > BackTrackingParents_t;
32 typedef std::vector< snapshotTree *, MyAlloc< snapshotTree * > > SnapshotChildren_t;
33 typedef std::map< MyString, snapshotTree *, std::less< MyString >, MyAlloc< std::pair< const MyString, snapshotTree * > > > SnapshotEdgeMap_t;
34 void SnapshotGlobalSegments();
36 friend struct snapshotTreeComp;
39 explicit snapshotTree( );
41 static snapshotTree * ReturnCurrentScope();
42 std::pair< MyString, bool > TakeStep( thrd_t which, thrd_t whoseNext );
44 unsigned int mTimeStamp;
45 ThreadStepMap_t mThreadStepsTaken;
46 thrd_t mNextStepTaker;
47 snapshotTree * mpParent;
48 SnapshotChildren_t mChildren;
49 void AddThreadStep( ThreadStepMap_t & theMap, thrd_t theThread );
50 static snapshotTree * msCurrentScope;
51 static BackTrackingParents_t msRecordedParents;
52 static SnapshotToStateMap_t msSnapshottedStates;
53 static SnapshotEdgeMap_t msSnapshotEdgesMap; //this might not actually needed, if this is blowing up memory we have to traverse and find as opposed to looking up....
54 static unsigned int msTimeCounter;
55 void EnsureRelevantRegionsSnapshotted();
57 void BacktrackingPointSet();
58 bool operator<( const snapshotTree & rhs ) const;
59 snapshot_id ReturnEarliestSnapshotID( MyString key );
60 snapshot_id SnapshotNow();