Ignore:
Timestamp:
Jan 7, 2021, 3:27:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b4daf2, 64aeca0
Parents:
3c64c668 (diff), eef8dfb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into park_unpark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/containers.hfa

    r3c64c668 r58fe85a  
    1717#include "bits/align.hfa"
    1818#include "bits/defs.hfa"
    19 
     19#include <stdio.h>
    2020//-----------------------------------------------------------------------------
    2121// Array
     
    3636        #define __small_array_t(T) __small_array(T)
    3737#else
    38         #define __small_array_t(T) struct __small_array
     38        #define __small_array_t(T) __small_array
    3939#endif
    4040
     
    146146        static inline forall( dtype T | is_node(T) ) {
    147147                void ?{}( __queue(T) & this ) with( this ) {
    148                         head{ 1p };
    149                         tail{ &head };
    150                         verify(*tail == 1p);
     148                        (this.head){ 1p };
     149                        (this.tail){ &this.head };
     150                        verify(*this.tail == 1p);
    151151                }
    152152
    153153                void append( __queue(T) & this, T * val ) with( this ) {
    154                         verify(tail != 0p);
    155                         verify(*tail == 1p);
    156                         *tail = val;
    157                         tail = &get_next( *val );
    158                         *tail = 1p;
     154                        verify(this.tail != 0p);
     155                        verify(*this.tail == 1p);
     156                        *this.tail = val;
     157                        this.tail = &get_next( *val );
     158                        *this.tail = 1p;
     159                }
     160
     161                T * peek( __queue(T) & this ) {
     162                        verify(*this.tail == 1p);
     163                        T * front = this.head;
     164                        if( front != 1p ) {
     165                                verify(*this.tail == 1p);
     166                                return front;
     167                        }
     168                        verify(*this.tail == 1p);
     169                        return 0p;
    159170                }
    160171
    161172                T * pop_head( __queue(T) & this ) {
    162173                        verify(*this.tail == 1p);
    163                         T * head = this.head;
    164                         if( head != 1p ) {
    165                                 this.head = get_next( *head );
    166                                 if( get_next( *head ) == 1p ) {
     174                        T * _head = this.head;
     175                        if( _head != 1p ) {
     176                                this.head = get_next( *_head );
     177                                if( get_next( *_head ) == 1p ) {
    167178                                        this.tail = &this.head;
    168179                                }
    169                                 get_next( *head ) = 0p;
     180                                get_next( *_head ) = 0p;
    170181                                verify(*this.tail == 1p);
    171                                 return head;
     182                                verify( get_next(*_head) == 0p );
     183                                return _head;
    172184                        }
    173185                        verify(*this.tail == 1p);
     
    181193                        (*it) = get_next( *val );
    182194
    183                         if( tail == &get_next( *val ) ) {
    184                                 tail = it;
     195                        if( this.tail == &get_next( *val ) ) {
     196                                this.tail = it;
    185197                        }
    186198
    187199                        get_next( *val ) = 0p;
    188200
    189                         verify( (head == 1p) == (&head == tail) );
    190                         verify( *tail == 1p );
     201                        verify( (this.head == 1p) == (&this.head == this.tail) );
     202                        verify( *this.tail == 1p );
    191203                        return val;
    192204                }
    193205
    194206                int ?!=?( const __queue(T) & this, __attribute__((unused)) zero_t zero ) {
    195                         return this.head != 0;
     207                        return this.head != 1p;
    196208                }
    197209        }
     
    227239        forall(dtype T )
    228240        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
    229                 this.head{ 0p };
     241                (this.head){ 0p };
    230242                this.__get = __get;
    231243        }
     
    236248                void push_front( __dllist(T) & this, T & node ) with( this ) {
    237249                        verify(__get);
    238                         if ( head ) {
    239                                 __get( node ).next = head;
    240                                 __get( node ).prev = __get( *head ).prev;
     250                        if ( this.head ) {
     251                                __get( node ).next = this.head;
     252                                __get( node ).prev = __get( *this.head ).prev;
    241253                                // inserted node must be consistent before it is seen
    242254                                // prevent code movement across barrier
    243255                                asm( "" : : : "memory" );
    244                                 __get( *head ).prev = &node;
     256                                __get( *this.head ).prev = &node;
    245257                                T & _prev = *__get( node ).prev;
    246258                                __get( _prev ).next = &node;
     
    252264                        // prevent code movement across barrier
    253265                        asm( "" : : : "memory" );
    254                         head = &node;
     266                        this.head = &node;
    255267                }
    256268
    257269                void remove( __dllist(T) & this, T & node ) with( this ) {
    258270                        verify(__get);
    259                         if ( &node == head ) {
    260                                 if ( __get( *head ).next == head ) {
    261                                         head = 0p;
     271                        if ( &node == this.head ) {
     272                                if ( __get( *this.head ).next == this.head ) {
     273                                        this.head = 0p;
    262274                                } else {
    263                                         head = __get( *head ).next;
     275                                        this.head = __get( *this.head ).next;
    264276                                }
    265277                        }
     
    273285                        return this.head != 0;
    274286                }
     287
     288                void move_to_front( __dllist(T) & src, __dllist(T) & dst, T & node ) {
     289                        remove    (src, node);
     290                        push_front(dst, node);
     291                }
    275292        }
    276293        #undef next
Note: See TracChangeset for help on using the changeset viewer.