| 1 | /* This header file contains datatypes and function prototypes for
|
|---|
| 2 | * collations.
|
|---|
| 3 | *
|
|---|
| 4 | */
|
|---|
| 5 | #ifndef _COLLATE_
|
|---|
| 6 | #define _COLLATE_
|
|---|
| 7 | #pragma CIVL ACSL
|
|---|
| 8 | #include <bundle.cvh>
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | /************************** Datatypes: **************************/
|
|---|
| 12 | /* _gcollator: An invisible shared collation object;
|
|---|
| 13 | * $gcollator: A handle to the shared collation object;
|
|---|
| 14 | *
|
|---|
| 15 | *
|
|---|
| 16 | * A global collation object sematically maintains a queue of collate
|
|---|
| 17 | * states.
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 | typedef struct _gcollator * $gcollator;
|
|---|
| 21 |
|
|---|
| 22 | /* _collator: An invisible local collation handle to a shared
|
|---|
| 23 | * _gcollator;
|
|---|
| 24 | * $collator: A local handle to a _collator object;
|
|---|
| 25 | *
|
|---|
| 26 | * A local collation hanlde is an object hold by a process. It is used
|
|---|
| 27 | * to access the global collation object through a set of
|
|---|
| 28 | * interfaces. Sematically how does the handle access the global
|
|---|
| 29 | * collation object is opaque from outside of the library.
|
|---|
| 30 | */
|
|---|
| 31 | typedef struct _collator * $collator;
|
|---|
| 32 |
|
|---|
| 33 | /* _gcollate_state: The object represents an element of the queue
|
|---|
| 34 | * maintained by a _gcollator.
|
|---|
| 35 | *
|
|---|
| 36 | * $gcollate_state: A reference to the _gcollate_state;
|
|---|
| 37 | *
|
|---|
| 38 | */
|
|---|
| 39 | typedef struct _gcollate_state * $gcollate_state;
|
|---|
| 40 |
|
|---|
| 41 | /*
|
|---|
| 42 | * $collate_state: A handle mainly wraps a $gcollate_state and some
|
|---|
| 43 | * other meta information, e.g. place.
|
|---|
| 44 | *
|
|---|
| 45 | * Semantically, this is the only object for a process to access a
|
|---|
| 46 | * collate state. The access is restircted by only using interfaces.
|
|---|
| 47 | */
|
|---|
| 48 | typedef struct _collate_state $collate_state;
|
|---|
| 49 |
|
|---|
| 50 | /********************* Function prototypes: *********************/
|
|---|
| 51 | /* API for creating a $gcollator: */
|
|---|
| 52 | $atomic_f $gcollator $gcollator_create($scope scope, int nprocs);
|
|---|
| 53 |
|
|---|
| 54 | /* API for destroying a $gcollator, all referred gcollate states will
|
|---|
| 55 | be destroyed: */
|
|---|
| 56 | $atomic_f void $gcollator_destroy($gcollator gc);
|
|---|
| 57 |
|
|---|
| 58 | /* API for creating a $collator: */
|
|---|
| 59 | $atomic_f $collator $collator_create($gcollator gcollator, $scope scope, int place);
|
|---|
| 60 | /* $collator can be destroyed by calling $free(..) */
|
|---|
| 61 |
|
|---|
| 62 | /* Take a snapshot on the current state. Returns the collate state
|
|---|
| 63 | * which contains the snapshot. This function allows processes commit
|
|---|
| 64 | * their snapshots collectively. The final collate state will be the
|
|---|
| 65 | * state consists of snapshots from all participant processes, one for
|
|---|
| 66 | * each. The collate state is always a valid program state as long as
|
|---|
| 67 | * it consists of at least one snapshot.
|
|---|
| 68 | *
|
|---|
| 69 | *
|
|---|
| 70 | * Pre-conditions:
|
|---|
| 71 | * scope must be reachable from the call stack of the calling
|
|---|
| 72 | * process.
|
|---|
| 73 | *
|
|---|
| 74 | * all participant processes P must be peers, i.e. for each
|
|---|
| 75 | * procecess p in P, p is spawned by another process p' and p' is
|
|---|
| 76 | * not in P.
|
|---|
| 77 | *
|
|---|
| 78 | *
|
|---|
| 79 | * Post-conditions:
|
|---|
| 80 | * There is a process set P which represents all processes that
|
|---|
| 81 | * already commit their snapshots to the collate state cp, cp has
|
|---|
| 82 | * size(P) live processes (a live process has non-empty call stack).
|
|---|
| 83 | * For each process p in P, its' snapshot in cp is a process state
|
|---|
| 84 | * whose pid is same as its' place in the collator. cp is always a
|
|---|
| 85 | * valid state for P.
|
|---|
| 86 | */
|
|---|
| 87 | /*@ pure;
|
|---|
| 88 | @ depends_on \nothing;
|
|---|
| 89 | @ executes_when \true;
|
|---|
| 90 | @*/
|
|---|
| 91 | $system void $collate_snapshot($collate_state cp, int nprocs, $scope scope);
|
|---|
| 92 |
|
|---|
| 93 | /* This function is a collective function. It collectively completes a
|
|---|
| 94 | * collate state.
|
|---|
| 95 | *
|
|---|
| 96 | * A collate state is a valid state consists of n processes, where n
|
|---|
| 97 | * is in between 1 and nprocs, when n participant processes called
|
|---|
| 98 | * this function.
|
|---|
| 99 | *
|
|---|
| 100 | * For one participant process, if it calls this function m times, it
|
|---|
| 101 | * will get m differen collate states. A collate state reserves the
|
|---|
| 102 | * current program state for the calling process until the collate
|
|---|
| 103 | * state is freed.
|
|---|
| 104 | */
|
|---|
| 105 | $atomic_f $collate_state $collate_arrives($collator c, $scope scope);
|
|---|
| 106 |
|
|---|
| 107 | /* Collectively free a collate state. The last process will be
|
|---|
| 108 | * responsible for dequeue the collate state at the head of the queue.
|
|---|
| 109 | *
|
|---|
| 110 | * A process is not allowed to access a freed collate state.
|
|---|
| 111 | *
|
|---|
| 112 | * If there is no arrived collate state by the process, it should
|
|---|
| 113 | * report an error.
|
|---|
| 114 | */
|
|---|
| 115 | /*@ pure;
|
|---|
| 116 | @ depends_on \nothing;
|
|---|
| 117 | @ executes_when \true;
|
|---|
| 118 | @*/
|
|---|
| 119 | $atomic_f void $collate_departs($collator c, $collate_state cs);
|
|---|
| 120 |
|
|---|
| 121 | /* Tests if a set of participants defined by a $range have all arrived
|
|---|
| 122 | * the specific $collate_entry referenced by cp.
|
|---|
| 123 | */
|
|---|
| 124 | /*@ pure;
|
|---|
| 125 | @ depends_on \access(&cp);
|
|---|
| 126 | @ executes_when \true;
|
|---|
| 127 | @*/
|
|---|
| 128 | $system $state_f _Bool $collate_arrived($collate_state cp, $range range);
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 | /* Equivalent to $arrived(cp, r') where r' represents the whole set of
|
|---|
| 132 | * participants in the specific $collate_entry referenced by cp.
|
|---|
| 133 | */
|
|---|
| 134 | /*@ pure;
|
|---|
| 135 | @ depends_on \access(&cp);
|
|---|
| 136 | @ executes_when \true;
|
|---|
| 137 | @*/
|
|---|
| 138 | $system $state_f _Bool $collate_complete($collate_state cp);
|
|---|
| 139 |
|
|---|
| 140 | /* An interface for checking attributes among a group of processes
|
|---|
| 141 | that all of the processes have the same value of the given
|
|---|
| 142 | attributes collectively. */
|
|---|
| 143 | /*@ pure;
|
|---|
| 144 | @ depends_on \access(&c);
|
|---|
| 145 | @ executes_when \true;
|
|---|
| 146 | @*/
|
|---|
| 147 | $atomic_f $bundle $collate_check($collator c, $bundle attribute);
|
|---|
| 148 |
|
|---|
| 149 | /* Marks the status of entering the collator to be true. */
|
|---|
| 150 | $atomic_f void $collator_enters($collator collator);
|
|---|
| 151 |
|
|---|
| 152 | /* Checks if the given processes in the range have all entered the collator. */
|
|---|
| 153 | $atomic_f _Bool $collator_has_entered($collator colaltor, $range range);
|
|---|
| 154 |
|
|---|
| 155 | /** returns the state reference. */
|
|---|
| 156 | /*@ depends_on \access(&state);
|
|---|
| 157 | @ executes_when \true; */
|
|---|
| 158 | $atomic_f $state_f $state * $collate_get_state($collate_state state);
|
|---|
| 159 |
|
|---|
| 160 | #endif
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|