Changes in / [e2f601f:8cd5434]
- Files:
-
- 3 added
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/Makefile.am
re2f601f r8cd5434 59 59 concurrency/iofwd.hfa \ 60 60 containers/list.hfa \ 61 containers/list2.hfa \ 61 62 containers/queueLockFree.hfa \ 62 63 containers/stackLockFree.hfa \ -
libcfa/src/concurrency/alarm.hfa
re2f601f r8cd5434 49 49 Duration period; // if > 0 => period of alarm 50 50 51 inline dlink(alarm_node_t);51 DLISTED_MGD_IMPL_IN(alarm_node_t) 52 52 53 53 union { … … 60 60 enum alarm_type type; // true if this is not a user defined alarm 61 61 }; 62 P9_EMBEDDED( alarm_node_t, dlink(alarm_node_t))62 DLISTED_MGD_IMPL_OUT(alarm_node_t) 63 63 64 64 void ?{}( alarm_node_t & this, $thread * thrd, Time alarm, Duration period ); … … 67 67 void ^?{}( alarm_node_t & this ); 68 68 69 typedef dlist(alarm_node_t ) alarm_list_t;69 typedef dlist(alarm_node_t, alarm_node_t) alarm_list_t; 70 70 71 71 void insert( alarm_list_t * this, alarm_node_t * n ); -
libcfa/src/concurrency/kernel.cfa
re2f601f r8cd5434 903 903 } 904 904 905 static void crawl_list( cluster * cltr, dlist(processor ) & list, unsigned count ) {905 static void crawl_list( cluster * cltr, dlist(processor, processor) & list, unsigned count ) { 906 906 /* paranoid */ verify( cltr->stats ); 907 907 -
libcfa/src/concurrency/kernel.hfa
re2f601f r8cd5434 107 107 108 108 // Link lists fields 109 inline dlink(processor);109 DLISTED_MGD_IMPL_IN(processor) 110 110 111 111 // special init fields … … 129 129 #endif 130 130 }; 131 P9_EMBEDDED( processor, dlink(processor) )132 131 133 132 void ?{}(processor & this, const char name[], struct cluster & cltr); … … 137 136 static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; } 138 137 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster}; } 138 139 DLISTED_MGD_IMPL_OUT(processor) 139 140 140 141 //----------------------------------------------------------------------------- … … 191 192 192 193 // List of idle processors 193 dlist(processor ) idles;194 dlist(processor, processor) idles; 194 195 195 196 // List of active processors 196 dlist(processor ) actives;197 dlist(processor, processor) actives; 197 198 }; 198 199 -
libcfa/src/concurrency/ready_queue.cfa
re2f601f r8cd5434 552 552 } 553 553 554 static void assign_list(unsigned & value, dlist(processor ) & list, unsigned count) {554 static void assign_list(unsigned & value, dlist(processor, processor) & list, unsigned count) { 555 555 processor * it = &list`first; 556 556 for(unsigned i = 0; i < count; i++) { -
libcfa/src/containers/list.hfa
re2f601f r8cd5434 18 18 #include <assert.h> 19 19 20 forall( Decorator &, T & ) 21 struct tytagref { 22 inline T &; 20 #define __DLISTED_MGD_COMMON(ELEM, NODE, LINKS_FLD) \ 21 static inline ELEM& $tempcv_n2e(NODE &node) { \ 22 return node; \ 23 } \ 24 \ 25 static inline NODE& $tempcv_e2n(ELEM &node) { \ 26 return ( NODE & ) node; \ 27 } \ 28 \ 29 static inline ELEM & ?`prev(NODE &node) { \ 30 $dlinks(ELEM) & ls = node.LINKS_FLD; \ 31 $mgd_link(ELEM) * l = &ls.prev; \ 32 ELEM * e = l->elem; \ 33 return *e; \ 34 } \ 35 \ 36 static inline ELEM & ?`next(NODE &node) { \ 37 $dlinks(ELEM) & ls = node.LINKS_FLD; \ 38 $mgd_link(ELEM) * l = &ls.next; \ 39 ELEM * e = l->elem; \ 40 return *e; \ 41 } \ 42 \ 43 static inline $mgd_link(ELEM) & $prev_link(NODE &node) { \ 44 $dlinks(ELEM) & ls = node.LINKS_FLD; \ 45 $mgd_link(ELEM) * l = &ls.prev; \ 46 return *l; \ 47 } \ 48 \ 49 static inline $mgd_link(ELEM) & $next_link(NODE &node) { \ 50 $dlinks(ELEM) & ls = node.LINKS_FLD; \ 51 $mgd_link(ELEM) * l = &ls.next; \ 52 return *l; \ 53 } 54 55 #define __DLISTED_MGD_JUSTEXPL(STRUCT, IN_THELIST, STRUCT_IN_THELIST) \ 56 struct STRUCT_IN_THELIST { \ 57 inline STRUCT; \ 58 }; \ 59 \ 60 void ?{}(STRUCT_IN_THELIST &) = void; \ 61 \ 62 static inline STRUCT_IN_THELIST& ?`IN_THELIST(STRUCT &this) { \ 63 return (STRUCT_IN_THELIST&)this; \ 64 } 65 66 #define __DLISTED_MGD_JUSTIMPL(STRUCT) 67 68 forall( tE & ) { 69 struct $mgd_link { 70 tE *elem; 71 void *terminator; 72 _Bool is_terminator; 73 // will collapse to single pointer with tag bit 74 }; 75 static inline void ?{}( $mgd_link(tE) &this, tE* elem ) { 76 (this.elem){ elem }; 77 (this.terminator){ 0p }; 78 (this.is_terminator){ 0 }; 79 } 80 static inline void ?{}( $mgd_link(tE) &this, void * terminator ) { 81 (this.elem){ 0p }; 82 (this.terminator){ terminator }; 83 (this.is_terminator){ 1 }; 84 } 85 static inline void ?=?( $mgd_link(tE) &this, tE* elem ) { 86 this.elem = elem ; 87 this.terminator = 0p; 88 this.is_terminator = 0; 89 } 90 static inline void ?=?( $mgd_link(tE) &this, void * terminator ) { 91 this.elem = 0p; 92 this.terminator = terminator; 93 this.is_terminator = 1; 94 } 95 struct $dlinks { 96 // containing item is not listed 97 // iff 98 // links have (elem == 0p && terminator == 0p) 99 $mgd_link(tE) next; 100 $mgd_link(tE) prev; 101 }; 102 static inline void ?{}( $dlinks(tE) &this ) { 103 (this.next){ (tE *)0p }; 104 (this.prev){ (tE *)0p }; 105 } 106 } 107 108 #define DLISTED_MGD_EXPL_IN(STRUCT, LIST_SUF) \ 109 $dlinks(STRUCT) $links_ ## LIST_SUF; 110 111 #define DLISTED_MGD_EXPL_OUT(STRUCT, LIST_SUF) \ 112 __DLISTED_MGD_JUSTEXPL(STRUCT, in_##LIST_SUF, STRUCT ## _in_ ## LIST_SUF) \ 113 __DLISTED_MGD_COMMON(STRUCT, STRUCT##_in_##LIST_SUF, $links_ ## LIST_SUF) 114 115 #define DLISTED_MGD_IMPL_IN(STRUCT) \ 116 $dlinks(STRUCT) $links; 117 118 #define DLISTED_MGD_IMPL_OUT(STRUCT) \ 119 __DLISTED_MGD_JUSTIMPL(STRUCT) \ 120 __DLISTED_MGD_COMMON(STRUCT, STRUCT, $links) 121 122 trait $dlistable(Tnode &, Telem &) { 123 $mgd_link(Telem) & $prev_link(Tnode &); 124 $mgd_link(Telem) & $next_link(Tnode &); 125 Telem& $tempcv_n2e(Tnode &); 126 Tnode& $tempcv_e2n(Telem &); 127 128 Telem& ?`next(Tnode &); 129 Telem& ?`prev(Tnode &); 23 130 }; 24 131 25 trait embedded( tOuter &, tMid &, tInner & ) { 26 tytagref( tMid, tInner ) ?`inner( tOuter & ); 27 }; 28 29 // embedded is reflexive, with no info (void) as the type tag 30 forall (T &) 31 static inline tytagref(void, T) ?`inner ( T & this ) { tytagref( void, T ) ret = {this}; return ret; } 32 33 // use this on every case of plan-9 inheritance, to make embedded a closure of plan-9 inheritance 34 #define P9_EMBEDDED( derived, immedBase ) \ 35 forall( Tbase &, TdiscardPath & | { tytagref( TdiscardPath, Tbase ) ?`inner( immedBase & ); } ) \ 36 static inline tytagref(immedBase, Tbase) ?`inner( derived & this ) { \ 37 immedBase & ib = this; \ 38 Tbase & b = ib`inner; \ 39 tytagref(immedBase, Tbase) result = { b }; \ 40 return result; \ 41 } 42 43 #define EMBEDDED_VIA( OUTER, MID, INNER ) \ 44 (struct { tytagref(MID, INNER) ( * ?`inner ) ( OUTER & ); }){ ?`inner } 45 46 #define DLINK_VIA( TE, TLINK ) \ 47 EMBEDDED_VIA( TE, TLINK, dlink(TE) ) 48 49 50 // The origin is the position encountered at the start of iteration, 51 // signifying, "need to advance to the first element," and at the end 52 // of iteration, signifying, "no more elements." Normal comsumption of 53 // an iterator runs ?`moveNext as the first step, and uses the return 54 // of ?`moveNext as a guard, before dereferencing the iterator. So 55 // normal consumption of an iterator does not dereference an iterator 56 // in origin position. The value of a pointer (underlying a refence) 57 // that is exposed publicly as an iteraor, and also a pointer stored 58 // internally in a link field, is tagged, to indicate "is the origin" 59 // (internally, is the list-head sentinel node), or untagged, to indicate 60 // "is a regular node." Intent is to help a user who dereferences an 61 // iterator in origin position (which would be an API-use error on their 62 // part), by failing fast. 63 64 #if defined( __x86_64 ) 65 // Preferred case: tag in the most-significant bit. Dereference 66 // has been shown to segfault consistently. Maintenance should 67 // list more architectures as "ok" here, to let them use the 68 // preferred case, when valid. 69 #define ORIGIN_TAG_BITNO ( 8 * sizeof( size_t ) - 1 ) 70 #else 71 // Fallback case: tag in the least-significant bit. Dereference 72 // will often give an alignment error, but may not, e.g. if 73 // accessing a char-typed member. 32-bit x86 uses the most- 74 // significant bit for real room on the heap. 75 #define ORIGIN_TAG_BITNO 0 76 #endif 77 #define ORIGIN_TAG_MASK (((size_t)1) << ORIGIN_TAG_BITNO) 78 79 #define ORIGIN_TAG_SET(p) ((p) | ORIGIN_TAG_MASK) 80 #define ORIGIN_TAG_CLEAR(p) ((p) & ~ORIGIN_TAG_MASK) 81 #define ORIGIN_TAG_QUERY(p) ((p) & ORIGIN_TAG_MASK) 82 83 84 forall( tE & ) { 85 86 struct dlink{ 87 tE *next; 88 tE *prev; 89 }; 90 91 static inline void ?{}( dlink(tE) & this ) { 92 this.next = 0p; 93 this.prev = 0p; 94 } 95 96 forall( tLinks & = dlink(tE) ) 97 struct dlist { 98 inline dlink(tE); 99 }; 100 101 forall( tLinks & | embedded( tE, tLinks, dlink(tE) ) ) { 102 static inline tE * $get_list_origin_addr( dlist(tE, tLinks) & lst ) { 103 dlink(tE) & link_from_null = ( * (tE *) 0p )`inner; 104 ptrdiff_t link_offset = (ptrdiff_t) & link_from_null; 105 size_t origin_addr = ((size_t) & lst) - link_offset; 106 size_t preResult = ORIGIN_TAG_SET( origin_addr ); 107 return (tE *)preResult; 108 } 109 110 static inline void ?{}( dlist(tE, tLinks) & this ) { 111 tE * listOrigin = $get_list_origin_addr( this ); 112 ( ( dlink(tE) & ) this ){ listOrigin, listOrigin } ; 113 } 114 } 115 116 } 117 118 119 forall( tE &, tLinks & | embedded( tE, tLinks, dlink(tE) ) ) { 120 121 static inline void insert_after(tE & list_pos, tE &to_insert) { 132 forall (Tnode &, Telem & | $dlistable(Tnode, Telem)) { 133 134 // implemented as a sentinel item in an underlying cicrular list 135 // theList.$links.next is first 136 // theList.$links.prev is last 137 // note this allocation preserves prev-next composition as an identity 138 struct dlist { 139 $dlinks(Telem) $links; 140 }; 141 142 // an empty dlist 143 // links refer to self, making a tight circle 144 static inline void ?{}( dlist(Tnode, Telem) & this ) { 145 $mgd_link(Telem) selfRef = (void *) &this; 146 ( this.$links ) { selfRef, selfRef }; 147 } 148 149 static inline Telem & ?`first( dlist(Tnode, Telem) &l ) { 150 return * l.$links.next.elem; 151 } 152 153 static inline Telem & ?`last( dlist(Tnode, Telem) &l ) { 154 return * l.$links.prev.elem; 155 } 156 157 #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__)) 158 static bool $validate_fwd( dlist(Tnode, Telem) & this ) { 159 Tnode * it = & $tempcv_e2n( this`first ); 160 if (!it) return (& this`last == 0p); 161 162 while( $next_link(*it).elem ) { 163 it = & $tempcv_e2n( * $next_link(*it).elem ); 164 } 165 166 return ( it == & $tempcv_e2n( this`last ) ) && 167 ( $next_link(*it).is_terminator ) && 168 ( ((dlist(Tnode, Telem)*)$next_link(*it).terminator) == &this ); 169 } 170 static bool $validate_rev( dlist(Tnode, Telem) & this ) { 171 Tnode * it = & $tempcv_e2n( this`last ); 172 if (!it) return (& this`first == 0p); 173 174 while( $prev_link(*it).elem ) { 175 it = & $tempcv_e2n( * $prev_link(*it).elem ); 176 } 177 178 return ( it == & $tempcv_e2n( this`first ) ) && 179 ( $prev_link(*it).is_terminator ) && 180 ( ((dlist(Tnode, Telem)*)$prev_link(*it).terminator) == &this ); 181 } 182 static bool validate( dlist(Tnode, Telem) & this ) { 183 return $validate_fwd(this) && $validate_rev(this); 184 } 185 #endif 186 187 static inline void insert_after(Tnode &list_pos, Telem &to_insert) { 122 188 verify (&list_pos != 0p); 123 189 verify (&to_insert != 0p); 124 dlink(tE) & linkToInsert = to_insert`inner; 125 verify(linkToInsert.prev == 0p); 126 verify(linkToInsert.next == 0p); 127 tE & list_pos_raw = list_pos; 128 tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw ); 129 dlink(tE) & list_pos_links = list_pos_elem`inner; 130 asm( "" : : : "memory" ); 131 tE & after_raw = * list_pos_links.next; 132 tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw ); 133 linkToInsert.prev = & list_pos_raw; 134 linkToInsert.next = & after_raw; 135 dlink(tE) & afterLinks = after_elem`inner; 136 afterLinks.prev = &to_insert; 137 list_pos_links.next = &to_insert; 138 asm( "" : : : "memory" ); 139 } 140 141 static inline void insert_before(tE & list_pos, tE &to_insert) { 190 Tnode &singleton_to_insert = $tempcv_e2n(to_insert); 191 verify($prev_link(singleton_to_insert).elem == 0p); 192 verify($next_link(singleton_to_insert).elem == 0p); 193 $prev_link(singleton_to_insert) = & $tempcv_n2e(list_pos); 194 $next_link(singleton_to_insert) = $next_link(list_pos); 195 if ($next_link(list_pos).is_terminator) { 196 dlist(Tnode, Telem) *list = ( dlist(Tnode, Telem) * ) $next_link(list_pos).terminator; 197 $dlinks(Telem) *list_links = & list->$links; 198 $mgd_link(Telem) *list_last = & list_links->prev; 199 *list_last = &to_insert; 200 } else { 201 Telem *list_pos_next = $next_link(list_pos).elem; 202 if (list_pos_next) { 203 Tnode & lpn_inlist = $tempcv_e2n(*list_pos_next); 204 $prev_link(lpn_inlist) = &to_insert; 205 } 206 } 207 $next_link(list_pos) = &to_insert; 208 } 209 210 static inline void insert_before(Tnode &list_pos, Telem &to_insert) { 142 211 verify (&list_pos != 0p); 143 212 verify (&to_insert != 0p); 144 dlink(tE) & linkToInsert = to_insert`inner; 145 verify(linkToInsert.next == 0p); 146 verify(linkToInsert.prev == 0p); 147 tE & list_pos_raw = list_pos; 148 tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw ); 149 dlink(tE) & list_pos_links = list_pos_elem`inner; 150 asm( "" : : : "memory" ); 151 tE & before_raw = * (list_pos_links).prev; 152 tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw ); 153 linkToInsert.next = & list_pos_raw; 154 linkToInsert.prev = & before_raw; 155 dlink(tE) & beforeLinks = before_elem`inner; 156 beforeLinks.next = &to_insert; 157 (list_pos_links).prev = &to_insert; 158 asm( "" : : : "memory" ); 159 } 160 161 static inline tE & remove(tE & list_pos) { 162 verify (&list_pos != 0p); 163 tE & list_pos_elem = list_pos; 164 verify( ! ORIGIN_TAG_QUERY((size_t) & list_pos_elem) ); 165 dlink(tE) & list_pos_links = list_pos_elem`inner; 166 tE & before_raw = * list_pos_links.prev; 167 tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw ); 168 dlink(tE) & before_links = before_elem`inner; 169 tE & after_raw = * list_pos_links.next; 170 tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw ); 171 dlink(tE) & after_links = after_elem`inner; 172 before_links.next = &after_raw; 173 after_links.prev = &before_raw; 174 asm( "" : : : "memory" ); 175 list_pos_links.prev = 0p; 176 list_pos_links.next = 0p; 177 asm( "" : : : "memory" ); 178 return list_pos_elem; 179 } 180 181 static inline tE & ?`first( dlist(tE, tLinks) &lst ) { 182 tE * firstPtr = lst.next; 183 if (ORIGIN_TAG_QUERY((size_t)firstPtr)) firstPtr = 0p; 184 return *firstPtr; 185 } 186 static inline tE & ?`last ( dlist(tE, tLinks) &lst ) { 187 tE * lastPtr = lst.prev; 188 if (ORIGIN_TAG_QUERY((size_t)lastPtr)) lastPtr = 0p; 189 return *lastPtr; 190 } 191 192 static inline bool ?`isEmpty( dlist(tE, tLinks) & lst ) { 193 tE * firstPtr = lst.next; 194 if (ORIGIN_TAG_QUERY((size_t)firstPtr)) firstPtr = 0p; 195 return firstPtr == 0p; 196 } 197 198 static inline tE & ?`elems( dlist(tE, tLinks) & lst ) { 199 tE * origin = $get_list_origin_addr( lst ); 200 return *origin; 201 } 202 203 static inline bool ?`moveNext( tE && refx ) { 204 tE && ref_inner = refx; 205 tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner ); 206 &ref_inner = oldReferent`inner.next; 207 return &ref_inner != 0p && 208 ! ORIGIN_TAG_QUERY( (size_t) & ref_inner ); 209 } 210 211 static inline bool ?`movePrev( tE && refx ) { 212 tE && ref_inner = refx; 213 tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner ); 214 &ref_inner = oldReferent`inner.prev; 215 return &ref_inner != 0p && 216 ! ORIGIN_TAG_QUERY( (size_t) & ref_inner ); 217 } 218 219 static inline bool ?`hasNext( tE & e ) { 220 return e`moveNext; 221 } 222 223 static inline bool ?`hasPrev( tE & e ) { 224 return e`movePrev; 225 } 226 227 static inline tE & ?`next( tE & e ) { 228 if( e`moveNext ) return e; 229 return * 0p; 230 } 231 232 static inline tE & ?`prev( tE & e ) { 233 if( e`movePrev ) return e; 234 return * 0p; 235 } 236 237 static inline void insert_first( dlist(tE, tLinks) &lst, tE & e ) { 238 insert_after(lst`elems, e); 239 } 240 241 static inline void insert_last( dlist(tE, tLinks) &lst, tE & e ) { 242 insert_before(lst`elems, e); 243 } 244 245 static inline tE & try_pop_front( dlist(tE, tLinks) &lst ) { 246 tE & first_inlist = lst`first; 247 tE & first_item = first_inlist; 248 if (&first_item) remove(first_inlist); 249 return first_item; 250 } 251 252 static inline tE & try_pop_back( dlist(tE, tLinks) &lst ) { 253 tE & last_inlist = lst`last; 254 tE & last_item = last_inlist; 255 if (&last_item) remove(last_inlist); 256 return last_item; 257 } 258 259 260 #if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__)) 261 static bool $validate_fwd( dlist(tE, tLinks) & this ) { 262 if ( ! & this`first ) return ( (& this`last) == 0p); 263 264 tE & lagElem = *0p; 265 266 while ( tE & it = this`elems; it`moveNext ) { 267 if (& lagElem == 0p && &it != & this`first ) return false; 268 & lagElem = & it; 269 } 270 271 if (& lagElem != & this`last) return false; 272 273 // TODO: verify that it is back at this`elems; 274 return true; 275 } 276 static bool $validate_rev( dlist(tE, tLinks) & this ) { 277 if ( ! & this`last ) return ( (& this`first) == 0p); 278 279 tE & lagElem = *0p; 280 281 while ( tE & it = this`elems; it`movePrev ) { 282 if (& lagElem == 0p && &it != & this`last ) return false; 283 & lagElem = & it; 284 } 285 286 if (& lagElem != & this`first) return false; 287 288 // TODO: verify that it is back at this`elems; 289 return true; 290 } 291 static bool validate( dlist(tE, tLinks) & this ) { 292 return $validate_fwd(this) && $validate_rev(this); 293 } 294 #endif 213 Tnode &singleton_to_insert = $tempcv_e2n(to_insert); 214 verify($prev_link(singleton_to_insert).elem == 0p); 215 verify($next_link(singleton_to_insert).elem == 0p); 216 $next_link(singleton_to_insert) = & $tempcv_n2e(list_pos); 217 $prev_link(singleton_to_insert) = $prev_link(list_pos); 218 if ($prev_link(list_pos).is_terminator) { 219 dlist(Tnode, Telem) *list = ( dlist(Tnode, Telem) * ) $prev_link(list_pos).terminator; 220 $dlinks(Telem) *list_links = & list->$links; 221 $mgd_link(Telem) *list_first = & list_links->next; 222 *list_first = &to_insert; 223 } else { 224 Telem *list_pos_prev = $prev_link(list_pos).elem; 225 if (list_pos_prev) { 226 Tnode & lpp_inlist = $tempcv_e2n(*list_pos_prev); 227 $next_link(lpp_inlist) = &to_insert; 228 } 229 } 230 $prev_link(list_pos) = &to_insert; 231 } 232 233 static inline void insert_first(dlist(Tnode, Telem) &list, Telem &to_insert) { 234 verify (&list != 0p); 235 verify (&to_insert != 0p); 236 Tnode &singleton_to_insert = $tempcv_e2n(to_insert); 237 verify($prev_link(singleton_to_insert).elem == 0p); 238 verify($next_link(singleton_to_insert).elem == 0p); 239 240 $prev_link(singleton_to_insert) = (void*) &list; 241 $next_link(singleton_to_insert) = list.$links.next; 242 243 $dlinks(Telem) *listLinks = & list.$links; 244 if (listLinks->next.is_terminator) { 245 $mgd_link(Telem) * listPrevReference = & listLinks->prev; 246 *listPrevReference = &to_insert; 247 } else { 248 Tnode & next_inlist = $tempcv_e2n(*list.$links.next.elem); 249 $prev_link(next_inlist) = &to_insert; 250 } 251 $mgd_link(Telem) * listNextReference = & listLinks->next; 252 *listNextReference = &to_insert; 253 } 254 255 static inline void insert_last(dlist(Tnode, Telem) &list, Telem &to_insert) { 256 verify (&list != 0p); 257 verify (&to_insert != 0p); 258 Tnode &singleton_to_insert = $tempcv_e2n(to_insert); 259 verify($next_link(singleton_to_insert).elem == 0p); 260 verify($prev_link(singleton_to_insert).elem == 0p); 261 262 $next_link(singleton_to_insert) = (void*) &list; 263 $prev_link(singleton_to_insert) = list.$links.prev; 264 265 $dlinks(Telem) *listLinks = & list.$links; 266 if (listLinks->prev.is_terminator) { 267 $mgd_link(Telem) * listNextReference = & listLinks->next; 268 *listNextReference = &to_insert; 269 } else { 270 Tnode & prev_inlist = $tempcv_e2n(*list.$links.prev.elem); 271 $next_link(prev_inlist) = &to_insert; 272 } 273 $mgd_link(Telem) * listPrevReference = & listLinks->prev; 274 *listPrevReference = &to_insert; 275 } 276 277 static inline void remove(Tnode &list_pos) { 278 verify( &list_pos != 0p ); 279 280 $mgd_link(Telem) &incoming_from_prev = *0p; 281 $mgd_link(Telem) &incoming_from_next = *0p; 282 283 if ( $prev_link(list_pos).is_terminator ) { 284 dlist(Tnode, Telem) * tgt_before = ( dlist(Tnode, Telem) * ) $prev_link(list_pos).terminator; 285 $dlinks(Telem) * links_before = & tgt_before->$links; 286 &incoming_from_prev = & links_before->next; 287 } else if ($prev_link(list_pos).elem) { 288 Telem * tgt_before = $prev_link(list_pos).elem; 289 Tnode & list_pos_before = $tempcv_e2n(*tgt_before); 290 &incoming_from_prev = & $next_link(list_pos_before); 291 } 292 293 if ( $next_link(list_pos).is_terminator ) { 294 dlist(Tnode, Telem) * tgt_after = ( dlist(Tnode, Telem) * ) $next_link(list_pos).terminator; 295 $dlinks(Telem) * links_after = & tgt_after->$links; 296 &incoming_from_next = & links_after->prev; 297 } else if ($next_link(list_pos).elem) { 298 Telem * tgt_after = $next_link(list_pos).elem; 299 Tnode & list_pos_after = $tempcv_e2n(*tgt_after ); 300 &incoming_from_next = & $prev_link(list_pos_after ); 301 } 302 303 if (& incoming_from_prev) { 304 incoming_from_prev = $next_link(list_pos); 305 } 306 if (& incoming_from_next) { 307 incoming_from_next = $prev_link(list_pos); 308 } 309 310 $next_link(list_pos) = (Telem*) 0p; 311 $prev_link(list_pos) = (Telem*) 0p; 312 } 313 314 static inline bool ?`is_empty(dlist(Tnode, Telem) &list) { 315 verify( &list != 0p ); 316 $dlinks(Telem) *listLinks = & list.$links; 317 if (listLinks->next.is_terminator) { 318 verify(listLinks->prev.is_terminator); 319 verify(listLinks->next.terminator); 320 verify(listLinks->prev.terminator); 321 return true; 322 } else { 323 verify(!listLinks->prev.is_terminator); 324 verify(listLinks->next.elem); 325 verify(listLinks->prev.elem); 326 return false; 327 } 328 } 329 330 static inline Telem & pop_first(dlist(Tnode, Telem) &list) { 331 verify( &list != 0p ); 332 verify( !list`is_empty ); 333 $dlinks(Telem) *listLinks = & list.$links; 334 Telem & first = *listLinks->next.elem; 335 Tnode & list_pos_first = $tempcv_e2n( first ); 336 remove(list_pos_first); 337 return first; 338 } 339 340 static inline Telem & pop_last(dlist(Tnode, Telem) &list) { 341 verify( &list != 0p ); 342 verify( !list`is_empty ); 343 $dlinks(Telem) *listLinks = & list.$links; 344 Telem & last = *listLinks->prev.elem; 345 Tnode & list_pos_last = $tempcv_e2n( last ); 346 remove(list_pos_last); 347 return last; 348 } 295 349 296 350 } -
libcfa/src/executor.cfa
re2f601f r8cd5434 7 7 #include <containers/list.hfa> 8 8 9 forall( T & , TLink& = dlink(T) | embedded(T, TLink, dlink(T)) ) {9 forall( T & | $dlistable(T, T) ) { 10 10 monitor Buffer { // unbounded buffer 11 dlist( T, T Link ) queue;// unbounded list of work requests11 dlist( T, T ) queue; // unbounded list of work requests 12 12 condition delay; 13 13 }; // Buffer 14 14 15 void insert( Buffer(T , TLink) & mutex buf, T * elem ) with(buf) {16 dlist( T, T Link ) * qptr = &queue;// workaround https://cforall.uwaterloo.ca/trac/ticket/16615 void insert( Buffer(T) & mutex buf, T * elem ) with(buf) { 16 dlist( T, T ) * qptr = &queue; // workaround https://cforall.uwaterloo.ca/trac/ticket/166 17 17 insert_last( *qptr, *elem ); // insert element into buffer 18 18 signal( delay ); // restart 19 19 } // insert 20 20 21 T * remove( Buffer(T , TLink) & mutex buf ) with(buf) {22 dlist( T, T Link ) * qptr = &queue;// workaround https://cforall.uwaterloo.ca/trac/ticket/16623 // if ( (*qptr)`is Empty ) wait( delay );// no request to process ? => wait24 if ( (*qptr)`is Empty ) return 0p;// no request to process ? => wait25 return & try_pop_front( *qptr );21 T * remove( Buffer(T) & mutex buf ) with(buf) { 22 dlist( T, T ) * qptr = &queue; // workaround https://cforall.uwaterloo.ca/trac/ticket/166 23 // if ( (*qptr)`is_empty ) wait( delay ); // no request to process ? => wait 24 if ( (*qptr)`is_empty ) return 0p; // no request to process ? => wait 25 return &pop_first( *qptr ); 26 26 } // remove 27 27 } // forall … … 29 29 struct WRequest { // client request, no return 30 30 void (* action)( void ); 31 inline dlink(WRequest);31 DLISTED_MGD_IMPL_IN(WRequest) 32 32 }; // WRequest 33 P9_EMBEDDED(WRequest, dlink(WRequest))33 DLISTED_MGD_IMPL_OUT(WRequest) 34 34 35 35 void ?{}( WRequest & req ) with(req) { action = 0; } -
src/Concurrency/Keywords.cc
re2f601f r8cd5434 432 432 new ObjectDecl( 433 433 Virtual::concurrentDefaultVTableName(), 434 noStorageClasses,434 Type::Const, 435 435 LinkageSpec::Cforall, 436 436 /* bitfieldWidth */ nullptr, … … 504 504 new ObjectDecl( 505 505 Virtual::concurrentDefaultVTableName(), 506 Type:: StorageClasses( Type::Extern ),506 Type::Const, 507 507 LinkageSpec::Cforall, 508 508 /* bitfieldWidth */ nullptr, -
tests/list/.expect/dlist-insert-remove.txt
re2f601f r8cd5434 1 ~~~~~~~~~~~~~~~~~ Headless List Tests - insert_after ~~~~~~~~~~~~~~~~ 2 3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 Test 1-i: Modifying Freds on MINE 5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 ==== fred by MINE before 7 3.14 8 - 9 3.14 10 - 11 0.5 12 - 13 0.5 14 - 15 ==== fred by YOURS before 16 3.14 17 - 18 3.14 19 - 20 0.5 21 - 22 0.5 23 - 24 ==== fred by MINE after 25 3.14 26 0.5 27 - 28 3.14 29 - 30 0.5 31 - 32 0.5 33 3.14 34 - 35 ==== fred by YOURS after 36 3.14 37 - 38 3.14 39 - 40 0.5 41 - 42 0.5 43 - 44 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45 Test 2-i. Modifying Freds on YOURS 46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 47 ==== fred by MINE before 48 3.14 49 - 50 3.14 51 - 52 0.5 53 - 54 0.5 55 - 56 ==== fred by YOURS before 57 3.14 58 - 59 3.14 60 - 61 0.5 62 - 63 0.5 64 - 65 ==== fred by MINE after 66 3.14 67 - 68 3.14 69 - 70 0.5 71 - 72 0.5 73 - 74 ==== fred by YOURS after 75 3.14 76 0.5 77 - 78 3.14 79 - 80 0.5 81 - 82 0.5 83 3.14 84 - 85 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 86 Test 3-i. Modifying Maries 87 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 88 ==== mary before 89 3.14 90 - 91 3.14 92 - 93 0.5 94 - 95 0.5 96 - 97 ==== mary after 98 3.14 99 0.5 100 - 101 3.14 102 - 103 0.5 104 - 105 0.5 106 3.14 107 - 108 109 ~~~~~~~~~~~~~~~~ Headless List Tests - insert_before ~~~~~~~~~~~~~~~~ 110 111 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 112 Test 1-ii: Modifying Freds on MINE 113 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 114 ==== fred by MINE before 115 3.14 116 - 117 3.14 118 - 119 0.5 120 - 121 0.5 122 - 123 ==== fred by YOURS before 124 3.14 125 - 126 3.14 127 - 128 0.5 129 - 130 0.5 131 - 132 ==== fred by MINE after 133 3.14 134 0.5 135 - 136 3.14 137 - 138 0.5 139 - 140 0.5 141 3.14 142 - 143 ==== fred by YOURS after 144 3.14 145 - 146 3.14 147 - 148 0.5 149 - 150 0.5 151 - 152 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153 Test 2-ii. Modifying Freds on YOURS 154 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155 ==== fred by MINE before 156 3.14 157 - 158 3.14 159 - 160 0.5 161 - 162 0.5 163 - 164 ==== fred by YOURS before 165 3.14 166 - 167 3.14 168 - 169 0.5 170 - 171 0.5 172 - 173 ==== fred by MINE after 174 3.14 175 - 176 3.14 177 - 178 0.5 179 - 180 0.5 181 - 182 ==== fred by YOURS after 183 3.14 184 0.5 185 - 186 3.14 187 - 188 0.5 189 - 190 0.5 191 3.14 192 - 193 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 194 Test 3-ii. Modifying Maries 195 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 196 ==== mary before 197 3.14 198 - 199 3.14 200 - 201 0.5 202 - 203 0.5 204 - 205 ==== mary after 206 3.14 207 0.5 208 - 209 3.14 210 - 211 0.5 212 - 213 0.5 214 3.14 215 - 1 216 2 217 ~~~~~~~~~~~~~~~~~ Headed List Tests - insert_first ~~~~~~~~~~~~~~~~~~ … … 342 557 - 343 558 559 ~~~~~~~~~~ Element removal tests on Headless List: mid ~~~~~~~~~~ 560 561 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 562 Test 10-i. Modifying Freds on MINE 563 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 564 ==== fred by MINE before 565 1.7 566 2.7 567 3.7 568 - 569 1.7 570 - 571 3.7 572 - 573 3.7 574 2.7 575 1.7 576 - 577 ==== fred by YOURS before 578 1.7 579 2.7 580 3.7 581 - 582 1.7 583 - 584 3.7 585 - 586 3.7 587 2.7 588 1.7 589 - 590 ==== fred by MINE after 591 1.7 592 3.7 593 - 594 1.7 595 - 596 3.7 597 - 598 3.7 599 1.7 600 - 601 ==== fred by YOURS after 602 1.7 603 2.7 604 3.7 605 - 606 1.7 607 - 608 3.7 609 - 610 3.7 611 2.7 612 1.7 613 - 614 ==== fred by MINE after 615 2.7 616 - 617 2.7 618 - 619 - 620 - 621 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 622 Test 11-i. Modifying Freds on YOURS 623 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 624 ==== fred by MINE before 625 1.7 626 2.7 627 3.7 628 - 629 1.7 630 - 631 3.7 632 - 633 3.7 634 2.7 635 1.7 636 - 637 ==== fred by YOURS before 638 1.7 639 2.7 640 3.7 641 - 642 1.7 643 - 644 3.7 645 - 646 3.7 647 2.7 648 1.7 649 - 650 ==== fred by MINE after 651 1.7 652 2.7 653 3.7 654 - 655 1.7 656 - 657 3.7 658 - 659 3.7 660 2.7 661 1.7 662 - 663 ==== fred by YOURS after 664 1.7 665 3.7 666 - 667 1.7 668 - 669 3.7 670 - 671 3.7 672 1.7 673 - 674 ==== fred by YOURS after 675 2.7 676 - 677 2.7 678 - 679 - 680 - 681 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 682 Test 12-i. Modifying Maries 683 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 684 ==== mary before 685 1.7 686 2.7 687 3.7 688 - 689 1.7 690 - 691 3.7 692 - 693 3.7 694 2.7 695 1.7 696 - 697 ==== mary after 698 1.7 699 3.7 700 - 701 1.7 702 - 703 3.7 704 - 705 3.7 706 1.7 707 - 708 ==== mary after 709 2.7 710 - 711 2.7 712 - 713 - 714 - 715 716 ~~~~~~~~~~ Element removal tests on Headless List: at first ~~~~~~~~~~ 717 718 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 719 Test 10-ii. Modifying Freds on MINE 720 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 721 ==== fred by MINE before 722 1.7 723 2.7 724 3.7 725 - 726 1.7 727 - 728 3.7 729 - 730 3.7 731 2.7 732 1.7 733 - 734 ==== fred by YOURS before 735 1.7 736 2.7 737 3.7 738 - 739 1.7 740 - 741 3.7 742 - 743 3.7 744 2.7 745 1.7 746 - 747 ==== fred by MINE after 748 2.7 749 3.7 750 - 751 2.7 752 - 753 3.7 754 - 755 3.7 756 2.7 757 - 758 ==== fred by YOURS after 759 1.7 760 2.7 761 3.7 762 - 763 1.7 764 - 765 3.7 766 - 767 3.7 768 2.7 769 1.7 770 - 771 ==== fred by MINE after 772 1.7 773 - 774 1.7 775 - 776 - 777 - 778 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 779 Test 11-ii. Modifying Freds on YOURS 780 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 781 ==== fred by MINE before 782 1.7 783 2.7 784 3.7 785 - 786 1.7 787 - 788 3.7 789 - 790 3.7 791 2.7 792 1.7 793 - 794 ==== fred by YOURS before 795 1.7 796 2.7 797 3.7 798 - 799 1.7 800 - 801 3.7 802 - 803 3.7 804 2.7 805 1.7 806 - 807 ==== fred by MINE after 808 1.7 809 2.7 810 3.7 811 - 812 1.7 813 - 814 3.7 815 - 816 3.7 817 2.7 818 1.7 819 - 820 ==== fred by YOURS after 821 2.7 822 3.7 823 - 824 2.7 825 - 826 3.7 827 - 828 3.7 829 2.7 830 - 831 ==== fred by YOURS after 832 1.7 833 - 834 1.7 835 - 836 - 837 - 838 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 839 Test 12-ii. Modifying Maries 840 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 841 ==== mary before 842 1.7 843 2.7 844 3.7 845 - 846 1.7 847 - 848 3.7 849 - 850 3.7 851 2.7 852 1.7 853 - 854 ==== mary after 855 2.7 856 3.7 857 - 858 2.7 859 - 860 3.7 861 - 862 3.7 863 2.7 864 - 865 ==== mary after 866 1.7 867 - 868 1.7 869 - 870 - 871 - 872 873 ~~~~~~~~~~ Element removal tests on Headless List: at last ~~~~~~~~~~ 874 875 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 876 Test 10-iii. Modifying Freds on MINE 877 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 878 ==== fred by MINE before 879 1.7 880 2.7 881 3.7 882 - 883 1.7 884 - 885 3.7 886 - 887 3.7 888 2.7 889 1.7 890 - 891 ==== fred by YOURS before 892 1.7 893 2.7 894 3.7 895 - 896 1.7 897 - 898 3.7 899 - 900 3.7 901 2.7 902 1.7 903 - 904 ==== fred by MINE after 905 1.7 906 2.7 907 - 908 1.7 909 - 910 2.7 911 - 912 2.7 913 1.7 914 - 915 ==== fred by YOURS after 916 1.7 917 2.7 918 3.7 919 - 920 1.7 921 - 922 3.7 923 - 924 3.7 925 2.7 926 1.7 927 - 928 ==== fred by MINE after 929 3.7 930 - 931 3.7 932 - 933 - 934 - 935 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 936 Test 11-iii. Modifying Freds on YOURS 937 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 938 ==== fred by MINE before 939 1.7 940 2.7 941 3.7 942 - 943 1.7 944 - 945 3.7 946 - 947 3.7 948 2.7 949 1.7 950 - 951 ==== fred by YOURS before 952 1.7 953 2.7 954 3.7 955 - 956 1.7 957 - 958 3.7 959 - 960 3.7 961 2.7 962 1.7 963 - 964 ==== fred by MINE after 965 1.7 966 2.7 967 3.7 968 - 969 1.7 970 - 971 3.7 972 - 973 3.7 974 2.7 975 1.7 976 - 977 ==== fred by YOURS after 978 1.7 979 2.7 980 - 981 1.7 982 - 983 2.7 984 - 985 2.7 986 1.7 987 - 988 ==== fred by YOURS after 989 3.7 990 - 991 3.7 992 - 993 - 994 - 995 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 996 Test 12-iii. Modifying Maries 997 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 998 ==== mary before 999 1.7 1000 2.7 1001 3.7 1002 - 1003 1.7 1004 - 1005 3.7 1006 - 1007 3.7 1008 2.7 1009 1.7 1010 - 1011 ==== mary after 1012 1.7 1013 2.7 1014 - 1015 1.7 1016 - 1017 2.7 1018 - 1019 2.7 1020 1.7 1021 - 1022 ==== mary after 1023 3.7 1024 - 1025 3.7 1026 - 1027 - 1028 - 1029 344 1030 ~~~~~~~~~~ Element removal tests on Headed List: at first ~~~~~~~~~~ 345 1031 … … 1092 1778 - 1093 1779 - 1094 1095 ~~~~~~~~~~~~~~~~~~~ Ease-of-access cases ~~~~~~~~~~~~~~~~~~1096 1097 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1098 Test 18-i. Modifying Freds on MINE1099 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1100 Not implmented1101 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1102 Test 18-ii. Modifying Freds on YOURS1103 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1104 Not implmented1105 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1106 Test 18-iii. Modifying Maries1107 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1108 accessor_cases done1109 try_pop cases done1110 origin_mutation cases done -
tests/list/dlist-insert-remove.cfa
re2f601f r8cd5434 19 19 struct fred { 20 20 float adatum; 21 inline struct mine { inline dlink(fred); };22 inline struct yours { inline dlink(fred); };21 DLISTED_MGD_EXPL_IN(fred, mine) 22 DLISTED_MGD_EXPL_IN(fred, yours) 23 23 }; 24 P9_EMBEDDED(fred, fred.mine) 25 P9_EMBEDDED(fred, fred.yours) 26 P9_EMBEDDED(fred.mine, dlink(fred)) 27 P9_EMBEDDED(fred.yours, dlink(fred)) 28 24 25 DLISTED_MGD_EXPL_OUT(fred, mine) 26 DLISTED_MGD_EXPL_OUT(fred, yours) 29 27 30 28 void ?{}(fred &this, float adatum) { … … 35 33 struct mary { 36 34 float anotherdatum; 37 inline dlink(mary);35 DLISTED_MGD_IMPL_IN(mary) 38 36 }; 39 37 40 P9_EMBEDDED(mary, dlink(mary))38 DLISTED_MGD_IMPL_OUT(mary) 41 39 42 40 void ?{}(mary &this, float anotherdatum) { … … 55 53 //////////////////////////////////////////////////////////// 56 54 57 void printMyFredsFwd(fred & f) { 58 with( DLINK_VIA( fred, fred.mine ) ) 59 do { 55 void printMyFredsFwd(fred &f) { 56 while (&f != 0p) { 60 57 sout | f.adatum; 61 } while (f`moveNext);62 }63 64 void printMyFredsRev(fred & f) { 65 with( DLINK_VIA( fred, fred.mine ) ) 66 do{58 &f = &f`in_mine`next; 59 } 60 } 61 62 void printMyFredsRev(fred &f) { 63 while (&f != 0p) { 67 64 sout | f.adatum; 68 } while (f`movePrev);69 }70 65 &f = &f`in_mine`prev; 66 } 67 } 71 68 72 69 void printMyFreddies(fred &f1, fred &f2, int isBefore) { … … 76 73 sout | "==== fred by MINE after "; 77 74 } 78 if (&f1) { 79 printMyFredsFwd(f1); sout | '-'; 80 printMyFredsRev(f1); sout | '-'; 81 } else { 82 sout | '-'; sout | '-'; 75 printMyFredsFwd(f1); sout | '-'; 76 printMyFredsRev(f1); sout | '-'; 77 printMyFredsFwd(f2); sout | '-'; 78 printMyFredsRev(f2); sout | '-'; 79 } 80 81 void printYourFredsFwd(fred &f) { 82 while (&f != 0p) { 83 sout | f.adatum; 84 &f = &f`in_yours`next; 83 85 } 84 if (&f2) { 85 printMyFredsFwd(f2); sout | '-'; 86 printMyFredsRev(f2); sout | '-'; 87 } else { 88 sout | '-'; sout | '-'; 86 } 87 88 void printYourFredsRev(fred &f) { 89 while (&f != 0p) { 90 sout | f.adatum; 91 &f = &f`in_yours`prev; 89 92 } 90 }91 92 void printYourFredsFwd(fred & f) {93 with( DLINK_VIA( fred, fred.yours ) )94 do {95 sout | f.adatum;96 } while (f`moveNext);97 }98 99 void printYourFredsRev(fred & f) {100 with( DLINK_VIA( fred, fred.yours ) )101 do {102 sout | f.adatum;103 } while (f`movePrev);104 93 } 105 94 … … 110 99 sout | "==== fred by YOURS after "; 111 100 } 112 if (&f1) { 113 printYourFredsFwd(f1); sout | '-'; 114 printYourFredsRev(f1); sout | '-'; 115 } else { 116 sout | '-'; sout | '-'; 101 printYourFredsFwd(f1); sout | '-'; 102 printYourFredsRev(f1); sout | '-'; 103 printYourFredsFwd(f2); sout | '-'; 104 printYourFredsRev(f2); sout | '-'; 105 } 106 107 void printMariesFwd(mary &m) { 108 while (&m != 0p) { 109 sout | m.anotherdatum; 110 &m = &m`next; 117 111 } 118 if (&f2) { 119 printYourFredsFwd(f2); sout | '-'; 120 printYourFredsRev(f2); sout | '-'; 121 } else { 122 sout | '-'; sout | '-'; 112 } 113 114 void printMariesRev(mary &m) { 115 while (&m != 0p) { 116 sout | m.anotherdatum; 117 &m = &m`prev; 123 118 } 124 }125 126 void printMariesFwd(mary &m) {127 do {128 sout | m.anotherdatum;129 } while (m`moveNext);130 }131 132 void printMariesRev(mary &m) {133 do {134 sout | m.anotherdatum;135 } while (m`movePrev);136 119 } 137 120 … … 142 125 sout | "==== mary after "; 143 126 } 144 if (&m1) { 145 printMariesFwd(m1); sout | '-'; 146 printMariesRev(m1); sout | '-'; 147 } else { 148 sout | '-'; sout | '-'; 149 } 150 if (&m2) { 151 printMariesFwd(m2); sout | '-'; 152 printMariesRev(m2); sout | '-'; 153 } else { 154 sout | '-'; sout | '-'; 155 } 127 printMariesFwd(m1); sout | '-'; 128 printMariesRev(m1); sout | '-'; 129 printMariesFwd(m2); sout | '-'; 130 printMariesRev(m2); sout | '-'; 156 131 } 157 132 … … 178 153 // - from list position #2 moving backward (d) 179 154 // The expected-output comments are in form a;b;c;d where a::=num,num,num 180 #if 0 155 181 156 void test__insertafter_singleton_on_singleton__fred_mine () { 182 157 fred f1 = {3.14}; … … 186 161 printYourFreddies(f1, f2, 1); // 3.14; 3.14; 0.5; 0.5 187 162 188 diref(fred, fred.mine) f1_mine = f1`from; 189 insert_after(f1_mine, f2); 163 insert_after(f1`in_mine, f2); 190 164 191 165 printMyFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) … … 200 174 printYourFreddies(f1, f2, 1); // 3.14; 3.14; 0.5; 0.5 201 175 202 diref(fred, fred.yours) f1_yours = f1`from; 203 insert_after(f1_yours, f2); 176 insert_after(f1`in_yours, f2); 204 177 205 178 printMyFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) … … 235 208 printYourFreddies(f1, f2, 1); // 3.14; 3.14; 0.5; 0.5 236 209 237 diref(fred, fred.mine) f2_mine = f2`from; 238 insert_before(f2_mine, f1); 210 insert_before(f2`in_mine, f1); 239 211 240 212 printMyFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) … … 249 221 printYourFreddies(f1, f2, 1); // 3.14; 3.14; 0.5; 0.5 250 222 251 diref(fred, fred.yours) f2_yours = f2`from; 252 insert_before(f2_yours, f1); 223 insert_before(f2`in_yours, f1); 253 224 254 225 printMyFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) … … 266 237 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 267 238 } 268 #endif 239 269 240 //////////////////////////////////////////////////////////// 270 241 // … … 279 250 // All three tests exercise the case of creating an empty container and 280 251 // adding two items to it. 252 281 253 void test__insertfirst_two_on_empty__fred_mine() { 282 254 … … 284 256 fred f2 = {0.5}; 285 257 286 dlist(fred , fred.mine) lf;258 dlist(fred_in_mine, fred) lf; 287 259 288 260 verify(validate(lf)); … … 305 277 fred f2 = {0.5}; 306 278 307 dlist(fred , fred.yours) lf;279 dlist(fred_in_yours, fred) lf; 308 280 309 281 verify(validate(lf)); … … 320 292 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 321 293 } 294 322 295 void test__insertfirst_two_on_empty__mary() { 323 296 … … 325 298 mary m2 = {0.5}; 326 299 327 dlist(mary ) lm;300 dlist(mary, mary) lm; 328 301 329 302 verify(validate(lm)); … … 352 325 fred f2 = {0.5}; 353 326 354 dlist(fred , fred.mine) lf;327 dlist(fred_in_mine, fred) lf; 355 328 356 329 verify(validate(lf)); … … 373 346 fred f2 = {0.5}; 374 347 375 dlist(fred , fred.yours) lf;348 dlist(fred_in_yours, fred) lf; 376 349 377 350 verify(validate(lf)); … … 394 367 mary m2 = {0.5}; 395 368 396 dlist(mary ) lm;369 dlist(mary, mary) lm; 397 370 398 371 verify(validate(lm)); … … 421 394 fred f2 = {0.5}; 422 395 423 dlist(fred , fred.mine) lf;424 425 assert( & lf`first == 0p);426 assert( & lf`last == 0p);396 dlist(fred_in_mine, fred) lf; 397 398 assert(& lf`first == 0p); 399 assert(& lf`last == 0p); 427 400 428 401 insert_first(lf, f1); 429 402 430 assert( & lf`first == & f1);431 assert( & lf`last == & f1);403 assert(& lf`first == & f1); 404 assert(& lf`last == & f1); 432 405 433 406 verify(validate(lf)); 434 407 435 with ( DLINK_VIA(fred, fred.mine) ) insert_after(f1, f2);408 insert_after(f1`in_mine, f2); 436 409 437 410 verify(validate(lf)); … … 440 413 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 441 414 442 assert( & lf`first == & f1);443 assert( & lf`last == & f2);415 assert(& lf`first == & f1); 416 assert(& lf`last == & f2); 444 417 } 445 418 … … 449 422 fred f2 = {0.5}; 450 423 451 dlist(fred , fred.yours) lf;452 453 assert( & lf`first == 0p);454 assert( & lf`last == 0p);424 dlist(fred_in_yours, fred) lf; 425 426 assert(& lf`first == 0p); 427 assert(& lf`last == 0p); 455 428 456 429 insert_first(lf, f1); 457 430 458 assert( & lf`first == & f1);459 assert( & lf`last == & f1);431 assert(& lf`first == & f1); 432 assert(& lf`last == & f1); 460 433 461 434 verify(validate(lf)); 462 435 463 with ( DLINK_VIA(fred, fred.yours) ) insert_after(f1, f2);436 insert_after(f1`in_yours, f2); 464 437 465 438 verify(validate(lf)); … … 468 441 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 469 442 470 assert( & lf`first == & f1);471 assert( & lf`last == & f2);443 assert(& lf`first == & f1); 444 assert(& lf`last == & f2); 472 445 } 473 446 … … 477 450 mary m2 = {0.5}; 478 451 479 dlist(mary ) lm;480 481 assert( & lm`first == 0p);482 assert( & lm`last == 0p);452 dlist(mary, mary) lm; 453 454 assert(& lm`first == 0p); 455 assert(& lm`last == 0p); 483 456 484 457 insert_first(lm, m1); 485 458 486 assert( & lm`first == & m1);487 assert( & lm`last == & m1);459 assert(& lm`first == & m1); 460 assert(& lm`last == & m1); 488 461 489 462 verify(validate(lm)); … … 495 468 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 496 469 497 assert( & lm`first == & m1);498 assert( & lm`last == & m2);470 assert(& lm`first == & m1); 471 assert(& lm`last == & m2); 499 472 } 500 473 … … 514 487 fred f2 = {0.5}; 515 488 516 dlist(fred , fred.mine) lf;517 518 assert( & lf`first == 0p);519 assert( & lf`last == 0p);489 dlist(fred_in_mine, fred) lf; 490 491 assert(& lf`first == 0p); 492 assert(& lf`last == 0p); 520 493 521 494 insert_last(lf, f2); 522 495 523 assert( & lf`first == & f2);524 assert( & lf`last == & f2);496 assert(& lf`first == & f2); 497 assert(& lf`last == & f2); 525 498 526 499 verify(validate(lf)); 527 500 528 with ( DLINK_VIA(fred, fred.mine) ) insert_before(f2, f1);501 insert_before(f2`in_mine, f1); 529 502 530 503 verify(validate(lf)); … … 533 506 printYourFreddies(f1, f2, 0); // 3.14; 3.14; 0.5; 0.5 (unmodified) 534 507 535 assert( & lf`first == & f1);536 assert( & lf`last == & f2);508 assert(& lf`first == & f1); 509 assert(& lf`last == & f2); 537 510 } 538 511 … … 542 515 fred f2 = {0.5}; 543 516 544 dlist(fred , fred.yours) lf;545 546 assert( & lf`first == 0p);547 assert( & lf`last == 0p);517 dlist(fred_in_yours, fred) lf; 518 519 assert(& lf`first == 0p); 520 assert(& lf`last == 0p); 548 521 549 522 insert_last(lf, f2); 550 523 551 assert( & lf`first == & f2);552 assert( & lf`last == & f2);524 assert(& lf`first == & f2); 525 assert(& lf`last == & f2); 553 526 554 527 verify(validate(lf)); 555 528 556 with ( DLINK_VIA(fred, fred.yours) )insert_before(f2, f1);529 insert_before(f2`in_yours, f1); 557 530 558 531 verify(validate(lf)); … … 561 534 printYourFreddies(f1, f2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 562 535 563 assert( & lf`first == & f1);564 assert( & lf`last == & f2);536 assert(& lf`first == & f1); 537 assert(& lf`last == & f2); 565 538 } 566 539 … … 570 543 mary m2 = {0.5}; 571 544 572 dlist(mary ) lm;573 574 assert( & lm`first == 0p);575 assert( & lm`last == 0p);545 dlist(mary, mary) lm; 546 547 assert(& lm`first == 0p); 548 assert(& lm`last == 0p); 576 549 577 550 insert_last(lm, m2); 578 551 579 assert( & lm`first == & m2);580 assert( & lm`last == & m2);552 assert(& lm`first == & m2); 553 assert(& lm`last == & m2); 581 554 582 555 verify(validate(lm)); … … 588 561 printMariatheotokos(m1, m2, 0); // 3.14, 0.5; 3.14; 0.5; 0.5, 3.14 (modified) 589 562 590 assert( & lm`first == & m1 ); 591 assert( & lm`last == & m2 ); 592 } 593 #if 0 563 assert(& lm`first == & m1); 564 assert(& lm`last == & m2); 565 } 594 566 595 567 //////////////////////////////////////////////////////////// … … 874 846 // 875 847 //////////////////////////////////////////////////////////// 876 #endif 848 877 849 void test__remove_at_head__fred_mine() { 878 850 … … 881 853 fred f3 = {3.7}; 882 854 883 dlist(fred , fred.mine) flm;855 dlist(fred_in_mine, fred) flm; 884 856 insert_last(flm, f1); 885 857 insert_last(flm, f2); 886 858 insert_last(flm, f3); 887 859 888 dlist(fred , fred.yours) fly;860 dlist(fred_in_yours, fred) fly; 889 861 insert_last(fly, f1); 890 862 insert_last(fly, f2); … … 897 869 verify(validate(flm)); 898 870 899 with( DLINK_VIA(fred, fred.mine) ) remove(f1);871 remove(f1`in_mine); 900 872 901 873 verify(validate(fly)); … … 909 881 910 882 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 911 // assert(f1.$links_mine.next.is_terminator == false); 912 // assert(f1.$links_mine.prev.is_terminator == false); 913 } 914 883 assert(f1.$links_mine.next.is_terminator == false); 884 assert(f1.$links_mine.prev.is_terminator == false); 885 } 915 886 916 887 void test__remove_at_head__fred_yours() { … … 920 891 fred f3 = {3.7}; 921 892 922 dlist(fred , fred.mine) flm;893 dlist(fred_in_mine, fred) flm; 923 894 insert_last(flm, f1); 924 895 insert_last(flm, f2); 925 896 insert_last(flm, f3); 926 897 927 dlist(fred , fred.yours) fly;898 dlist(fred_in_yours, fred) fly; 928 899 insert_last(fly, f1); 929 900 insert_last(fly, f2); … … 936 907 verify(validate(flm)); 937 908 938 with( DLINK_VIA(fred, fred.yours) ) remove(f1);909 remove(f1`in_yours); 939 910 940 911 verify(validate(fly)); … … 948 919 949 920 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 950 //assert(f1.$links_yours.next.is_terminator == false);951 //assert(f1.$links_yours.prev.is_terminator == false);921 assert(f1.$links_yours.next.is_terminator == false); 922 assert(f1.$links_yours.prev.is_terminator == false); 952 923 } 953 924 … … 958 929 mary m3 = {3.7}; 959 930 960 dlist(mary ) ml;931 dlist(mary, mary) ml; 961 932 insert_last(ml, m1); 962 933 insert_last(ml, m2); … … 977 948 978 949 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 979 //assert(m1.$links.next.is_terminator == false);980 //assert(m1.$links.prev.is_terminator == false);950 assert(m1.$links.next.is_terminator == false); 951 assert(m1.$links.prev.is_terminator == false); 981 952 } 982 953 … … 997 968 fred f3 = {3.7}; 998 969 999 dlist(fred , fred.mine) flm;970 dlist(fred_in_mine, fred) flm; 1000 971 insert_last(flm, f1); 1001 972 insert_last(flm, f2); 1002 973 insert_last(flm, f3); 1003 974 1004 dlist(fred , fred.yours) fly;975 dlist(fred_in_yours, fred) fly; 1005 976 insert_last(fly, f1); 1006 977 insert_last(fly, f2); … … 1013 984 verify(validate(flm)); 1014 985 1015 with( DLINK_VIA(fred, fred.mine) ) remove(f3);986 remove(f3`in_mine); 1016 987 1017 988 verify(validate(fly)); … … 1025 996 1026 997 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1027 //assert(f3.$links_mine.next.is_terminator == false);1028 //assert(f3.$links_mine.prev.is_terminator == false);998 assert(f3.$links_mine.next.is_terminator == false); 999 assert(f3.$links_mine.prev.is_terminator == false); 1029 1000 } 1030 1001 … … 1035 1006 fred f3 = {3.7}; 1036 1007 1037 dlist(fred , fred.mine) flm;1008 dlist(fred_in_mine, fred) flm; 1038 1009 insert_last(flm, f1); 1039 1010 insert_last(flm, f2); 1040 1011 insert_last(flm, f3); 1041 1012 1042 dlist(fred , fred.yours) fly;1013 dlist(fred_in_yours, fred) fly; 1043 1014 insert_last(fly, f1); 1044 1015 insert_last(fly, f2); … … 1051 1022 verify(validate(flm)); 1052 1023 1053 with( DLINK_VIA(fred, fred.yours) ) remove(f3);1024 remove(f3`in_yours); 1054 1025 1055 1026 verify(validate(fly)); … … 1063 1034 1064 1035 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1065 //assert(f3.$links_yours.next.is_terminator == false);1066 //assert(f3.$links_yours.prev.is_terminator == false);1036 assert(f3.$links_yours.next.is_terminator == false); 1037 assert(f3.$links_yours.prev.is_terminator == false); 1067 1038 } 1068 1039 … … 1073 1044 mary m3 = {3.7}; 1074 1045 1075 dlist(mary ) ml;1046 dlist(mary, mary) ml; 1076 1047 insert_last(ml, m1); 1077 1048 insert_last(ml, m2); … … 1092 1063 1093 1064 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1094 //assert(m3.$links.next.is_terminator == false);1095 //assert(m3.$links.prev.is_terminator == false);1065 assert(m3.$links.next.is_terminator == false); 1066 assert(m3.$links.prev.is_terminator == false); 1096 1067 } 1097 1068 … … 1110 1081 fred f = {0.7}; 1111 1082 1112 dlist(fred , fred.mine) flm;1083 dlist(fred_in_mine, fred) flm; 1113 1084 insert_last(flm, f); 1114 1085 1115 dlist(fred , fred.yours) fly;1086 dlist(fred_in_yours, fred) fly; 1116 1087 insert_last(fly, f); 1117 1088 … … 1122 1093 verify(validate(flm)); 1123 1094 1124 with( DLINK_VIA(fred, fred.mine) ) remove(f);1125 1126 verify(validate(fly)); 1127 verify(validate(flm)); 1128 1129 assert( & flm`first == 0p);1130 assert( & flm`last == 0p);1095 remove(f`in_mine); 1096 1097 verify(validate(fly)); 1098 verify(validate(flm)); 1099 1100 assert(& flm`first == 0p); 1101 assert(& flm`last == 0p); 1131 1102 1132 1103 printYourFreddies(fly`first, fly`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1136 1107 1137 1108 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1138 //assert(f.$links_mine.next.is_terminator == false);1139 //assert(f.$links_mine.prev.is_terminator == false);1109 assert(f.$links_mine.next.is_terminator == false); 1110 assert(f.$links_mine.prev.is_terminator == false); 1140 1111 1141 1112 insert_last(flm, f); … … 1149 1120 fred f = {0.7}; 1150 1121 1151 dlist(fred , fred.mine) flm;1122 dlist(fred_in_mine, fred) flm; 1152 1123 insert_last(flm, f); 1153 1124 1154 dlist(fred , fred.yours) fly;1125 dlist(fred_in_yours, fred) fly; 1155 1126 insert_last(fly, f); 1156 1127 … … 1161 1132 verify(validate(flm)); 1162 1133 1163 with( DLINK_VIA(fred, fred.yours) ) remove(f);1164 1165 verify(validate(fly)); 1166 verify(validate(flm)); 1167 1168 assert( & fly`first == 0p);1169 assert( & fly`last == 0p);1134 remove(f`in_yours); 1135 1136 verify(validate(fly)); 1137 verify(validate(flm)); 1138 1139 assert(& fly`first == 0p); 1140 assert(& fly`last == 0p); 1170 1141 1171 1142 printYourFreddies(flm`first, flm`last, 0); // 0.7; 0.7; 0.7; 0.7 (unmodified) … … 1175 1146 1176 1147 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1177 //assert(f.$links_yours.next.is_terminator == false);1178 //assert(f.$links_yours.prev.is_terminator == false);1148 assert(f.$links_yours.next.is_terminator == false); 1149 assert(f.$links_yours.prev.is_terminator == false); 1179 1150 1180 1151 insert_last(fly, f); … … 1188 1159 mary m = {0.7}; 1189 1160 1190 dlist(mary ) ml;1161 dlist(mary, mary) ml; 1191 1162 insert_last(ml, m); 1192 1163 … … 1199 1170 verify(validate(ml)); 1200 1171 1201 assert( & ml`first == 0p);1202 assert( & ml`last == 0p);1172 assert(& ml`first == 0p); 1173 assert(& ml`last == 0p); 1203 1174 1204 1175 // observe f is solo in mine (now unlisted); in yours, it was just traversed … … 1206 1177 1207 1178 // TODO: decide on appropriate ovservable outcome (is_listed?) and its itended semantics 1208 //assert(m.$links.next.is_terminator == false);1209 //assert(m.$links.prev.is_terminator == false);1179 assert(m.$links.next.is_terminator == false); 1180 assert(m.$links.prev.is_terminator == false); 1210 1181 1211 1182 insert_last(ml, m); … … 1232 1203 fred f3 = {3.7}; 1233 1204 1234 dlist(fred , fred.mine) flm;1205 dlist(fred_in_mine, fred) flm; 1235 1206 insert_last(flm, f1); 1236 1207 insert_last(flm, f2); 1237 1208 insert_last(flm, f3); 1238 1209 1239 dlist(fred , fred.yours) fly;1210 dlist(fred_in_yours, fred) fly; 1240 1211 insert_last(fly, f1); 1241 1212 insert_last(fly, f2); … … 1248 1219 verify(validate(flm)); 1249 1220 1250 fred & popped = try_pop_front(flm);1221 fred & popped = pop_first(flm); 1251 1222 1252 1223 verify(validate(fly)); … … 1268 1239 fred f3 = {3.7}; 1269 1240 1270 dlist(fred , fred.mine) flm;1241 dlist(fred_in_mine, fred) flm; 1271 1242 insert_last(flm, f1); 1272 1243 insert_last(flm, f2); 1273 1244 insert_last(flm, f3); 1274 1245 1275 dlist(fred , fred.yours) fly;1246 dlist(fred_in_yours, fred) fly; 1276 1247 insert_last(fly, f1); 1277 1248 insert_last(fly, f2); … … 1284 1255 verify(validate(flm)); 1285 1256 1286 fred & popped = try_pop_front(fly);1257 fred & popped = pop_first(fly); 1287 1258 1288 1259 verify(validate(fly)); … … 1304 1275 mary m3 = {3.7}; 1305 1276 1306 dlist(mary ) ml;1277 dlist(mary, mary) ml; 1307 1278 insert_last(ml, m1); 1308 1279 insert_last(ml, m2); … … 1313 1284 verify(validate(ml)); 1314 1285 1315 mary & popped = try_pop_front(ml);1286 mary & popped = pop_first(ml); 1316 1287 1317 1288 verify(validate(ml)); … … 1331 1302 fred f3 = {3.7}; 1332 1303 1333 dlist(fred , fred.mine) flm;1304 dlist(fred_in_mine, fred) flm; 1334 1305 insert_last(flm, f1); 1335 1306 insert_last(flm, f2); 1336 1307 insert_last(flm, f3); 1337 1308 1338 dlist(fred , fred.yours) fly;1309 dlist(fred_in_yours, fred) fly; 1339 1310 insert_last(fly, f1); 1340 1311 insert_last(fly, f2); … … 1347 1318 verify(validate(flm)); 1348 1319 1349 fred & popped = try_pop_back(flm);1320 fred & popped = pop_last(flm); 1350 1321 1351 1322 verify(validate(fly)); … … 1367 1338 fred f3 = {3.7}; 1368 1339 1369 dlist(fred , fred.mine) flm;1340 dlist(fred_in_mine, fred) flm; 1370 1341 insert_last(flm, f1); 1371 1342 insert_last(flm, f2); 1372 1343 insert_last(flm, f3); 1373 1344 1374 dlist(fred , fred.yours) fly;1345 dlist(fred_in_yours, fred) fly; 1375 1346 insert_last(fly, f1); 1376 1347 insert_last(fly, f2); … … 1383 1354 verify(validate(flm)); 1384 1355 1385 fred & popped = try_pop_back(fly);1356 fred & popped = pop_last(fly); 1386 1357 1387 1358 verify(validate(fly)); … … 1403 1374 mary m3 = {3.7}; 1404 1375 1405 dlist(mary ) ml;1376 dlist(mary, mary) ml; 1406 1377 insert_last(ml, m1); 1407 1378 insert_last(ml, m2); … … 1412 1383 verify(validate(ml)); 1413 1384 1414 mary & popped = try_pop_back(ml);1385 mary & popped = pop_last(ml); 1415 1386 1416 1387 verify(validate(ml)); … … 1426 1397 //////////////////////////////////////////////////////////// 1427 1398 // 1428 // Section 4g1429 //1430 // Test cases of `isEmpty, `hasPrev, `hasNext,1431 // try_pop_front, try_pop_back, modifications via `elems1432 //1433 // Example of call-side user code1434 //1435 ////////////////////////////////////////////////////////////1436 1437 void test__accessor_cases__mary() {1438 1439 mary m1 = {1.7};1440 mary m2 = {2.7};1441 mary m3 = {3.7};1442 1443 dlist(mary) ml; assert( ml`isEmpty);1444 1445 insert_last(ml, m1); assert(!ml`isEmpty);1446 insert_last(ml, m2); assert(!ml`isEmpty);1447 insert_last(ml, m3); assert(!ml`isEmpty);1448 1449 mary & m1prev = m1`prev;1450 mary & m1next = m1`next;1451 mary & m2prev = m2`prev;1452 mary & m2next = m2`next;1453 mary & m3prev = m3`prev;1454 mary & m3next = m3`next;1455 1456 assert (&m1prev == 0p);1457 assert (&m1next == &m2);1458 assert (&m2prev == &m1);1459 assert (&m2next == &m3);1460 assert (&m3prev == &m2);1461 assert (&m3next == 0p);1462 1463 assert(!m1`hasPrev);1464 assert( m1`hasNext);1465 assert( m2`hasPrev);1466 assert( m2`hasNext);1467 assert( m3`hasPrev);1468 assert(!m3`hasNext);1469 1470 printf("accessor_cases done\n");1471 }1472 1473 void test__try_pop__mary() {1474 1475 mary m1 = {1.7};1476 mary m2 = {2.7};1477 mary m3 = {3.7};1478 1479 dlist(mary) ml;1480 1481 mary &m1r = *0p;1482 mary &m2r = *0p;1483 mary &m3r = *0p;1484 mary &mxr = *0p;1485 1486 // queue, back to front1487 1488 assert( ml`isEmpty);1489 1490 insert_last(ml, m1);1491 insert_last(ml, m2);1492 insert_last(ml, m3);1493 1494 &m1r = & try_pop_front(ml); assert(!ml`isEmpty);1495 &m2r = & try_pop_front(ml); assert(!ml`isEmpty);1496 &m3r = & try_pop_front(ml); assert( ml`isEmpty);1497 &mxr = & try_pop_front(ml); assert( ml`isEmpty);1498 1499 assert( &m1r == &m1 );1500 assert( &m2r == &m2 );1501 assert( &m3r == &m3 );1502 assert( &mxr == 0p );1503 1504 &m1r = 0p;1505 &m2r = 0p;1506 &m3r = 0p;1507 1508 // queue, front to back1509 1510 assert( ml`isEmpty);1511 1512 insert_first(ml, m1);1513 insert_first(ml, m2);1514 insert_first(ml, m3);1515 1516 &m1r = & try_pop_back(ml); assert(!ml`isEmpty);1517 &m2r = & try_pop_back(ml); assert(!ml`isEmpty);1518 &m3r = & try_pop_back(ml); assert( ml`isEmpty);1519 &mxr = & try_pop_back(ml); assert( ml`isEmpty);1520 1521 assert( &m1r == &m1 );1522 assert( &m2r == &m2 );1523 assert( &m3r == &m3 );1524 assert( &mxr == 0p );1525 1526 &m1r = 0p;1527 &m2r = 0p;1528 &m3r = 0p;1529 1530 // stack at front1531 1532 assert( ml`isEmpty);1533 1534 insert_first(ml, m1);1535 insert_first(ml, m2);1536 insert_first(ml, m3);1537 1538 &m3r = & try_pop_front(ml); assert(!ml`isEmpty);1539 &m2r = & try_pop_front(ml); assert(!ml`isEmpty);1540 &m1r = & try_pop_front(ml); assert( ml`isEmpty);1541 &mxr = & try_pop_front(ml); assert( ml`isEmpty);1542 1543 assert( &m1r == &m1 );1544 assert( &m2r == &m2 );1545 assert( &m3r == &m3 );1546 assert( &mxr == 0p );1547 1548 &m1r = 0p;1549 &m2r = 0p;1550 &m3r = 0p;1551 1552 // stack at back1553 1554 assert( ml`isEmpty);1555 1556 insert_last(ml, m1);1557 insert_last(ml, m2);1558 insert_last(ml, m3);1559 1560 &m3r = & try_pop_back(ml); assert(!ml`isEmpty);1561 &m2r = & try_pop_back(ml); assert(!ml`isEmpty);1562 &m1r = & try_pop_back(ml); assert( ml`isEmpty);1563 &mxr = & try_pop_back(ml); assert( ml`isEmpty);1564 1565 assert( &m1r == &m1 );1566 assert( &m2r == &m2 );1567 assert( &m3r == &m3 );1568 assert( &mxr == 0p );1569 1570 &m1r = 0p;1571 &m2r = 0p;1572 &m3r = 0p;1573 1574 printf("try_pop cases done\n");1575 }1576 1577 void test__origin_mutation__mary() {1578 1579 mary m1 = {1.7};1580 1581 dlist(mary) ml;1582 mary & mlorigin = ml`elems;1583 1584 // insert before the origin1585 1586 insert_before( ml`elems, m1 );1587 assert( ! ml`isEmpty );1588 1589 mary & mlfirst = ml`first;1590 mary & mllast = ml`last;1591 1592 assert( &m1 == & mlfirst );1593 assert( &m1 == & mllast );1594 1595 // moveNext after last goes back to origin, &vv1596 1597 bool canMoveNext = mllast`moveNext;1598 bool canMovePrev = mlfirst`movePrev;1599 1600 assert( ! canMoveNext );1601 assert( ! canMovePrev );1602 1603 assert( &mlorigin == & mlfirst );1604 assert( &mlorigin == & mllast );1605 1606 printf("origin_mutation cases done\n");1607 }1608 1609 ////////////////////////////////////////////////////////////1610 //1611 1399 // Section 5 1612 1400 // … … 1616 1404 1617 1405 int main() { 1618 #if 0 1406 1619 1407 sout | "~~~~~~~~~~~~~~~~~ Headless List Tests - insert_after ~~~~~~~~~~~~~~~~"; 1620 1408 sout | ""; … … 1653 1441 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; 1654 1442 test__insertbefore_singleton_on_singleton__mary(); 1655 #endif 1443 1656 1444 sout | ""; 1657 1445 sout | "~~~~~~~~~~~~~~~~~ Headed List Tests - insert_first ~~~~~~~~~~~~~~~~~~"; … … 1729 1517 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; 1730 1518 test__insertbefore_before_first__mary(); 1731 #if 01732 1519 1733 1520 sout | ""; … … 1787 1574 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; 1788 1575 test__remove_at_last__mary(); 1789 #endif 1576 1790 1577 sout | ""; 1791 1578 sout | "~~~~~~~~~~ Element removal tests on Headed List: at first ~~~~~~~~~~"; … … 1883 1670 test__pop_last__maries(); 1884 1671 1885 sout | "";1886 sout | "~~~~~~~~~~~~~~~~~~~ Ease-of-access cases ~~~~~~~~~~~~~~~~~~";1887 sout | "";1888 1889 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1890 sout | "Test 18-i. Modifying Freds on MINE";1891 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1892 sout | "Not implmented";1893 1894 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1895 sout | "Test 18-ii. Modifying Freds on YOURS";1896 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1897 sout | "Not implmented";1898 1899 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1900 sout | "Test 18-iii. Modifying Maries";1901 sout | "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";1902 1903 test__accessor_cases__mary();1904 test__try_pop__mary();1905 test__origin_mutation__mary();1906 1907 1672 return 0; 1908 1673 } -
tests/zombies/linked-list-perf/experiment.koad
re2f601f r8cd5434 49 49 #elif defined IMPL_CFA_MIKE_OLD 50 50 51 #include "mike-old.hfa"51 #include <containers/list.hfa> 52 52 struct S { 53 53 int f[64]; // FIXME: make "is volatile" consistent; given bug #TBD … … 67 67 #elif defined IMPL_CFA_MIKE_NEW 68 68 69 #include <containers/list .hfa>69 #include <containers/list2.hfa> 70 70 struct S { 71 71 int f[64]; // FIXME: make "is volatile" consistent; given bug #TBD
Note: See TracChangeset
for help on using the changeset viewer.