Ignore:
Timestamp:
Aug 27, 2018, 4:40:34 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
b7c89aa
Parents:
f9feab8 (diff), 305581d (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 cleanup-dtors

File:
1 moved

Legend:

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

    rf9feab8 r90152a4  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // bits/containers.h -- Intrusive generic containers.h
     7// bits/containers.hfa -- Intrusive generic containers.hfa
    88//
    99// Author           : Thierry Delisle
     
    1515#pragma once
    1616
    17 #include "bits/align.h"
    18 #include "bits/defs.h"
     17#include "bits/align.hfa"
     18#include "bits/defs.hfa"
    1919
    2020//-----------------------------------------------------------------------------
     
    140140
    141141#ifdef __cforall
     142
    142143        forall(dtype T | is_node(T))
    143         static inline void ?{}( __queue(T) & this ) {
    144                 (this.head){ NULL };
    145                 (this.tail){ &this.head };
    146         }
    147 
    148         forall(dtype T | is_node(T) | sized(T))
    149         static inline void append( __queue(T) & this, T * val ) {
    150                 verify(this.tail != NULL);
    151                 *this.tail = val;
    152                 this.tail = &get_next( *val );
     144        static inline void ?{}( __queue(T) & this ) with( this ) {
     145                head{ NULL };
     146                tail{ &head };
     147        }
     148
     149        forall(dtype T | is_node(T) | sized(T))
     150        static inline void append( __queue(T) & this, T * val ) with( this ) {
     151                verify(tail != NULL);
     152                *tail = val;
     153                tail = &get_next( *val );
    153154        }
    154155
     
    167168
    168169        forall(dtype T | is_node(T) | sized(T))
    169         static inline T * remove( __queue(T) & this, T ** it ) {
     170        static inline T * remove( __queue(T) & this, T ** it ) with( this ) {
    170171                T * val = *it;
    171172                verify( val );
     
    173174                (*it) = get_next( *val );
    174175
    175                 if( this.tail == &get_next( *val ) ) {
    176                         this.tail = it;
     176                if( tail == &get_next( *val ) ) {
     177                        tail = it;
    177178                }
    178179
    179180                get_next( *val ) = NULL;
    180181
    181                 verify( (this.head == NULL) == (&this.head == this.tail) );
    182                 verify( *this.tail == NULL );
     182                verify( (head == NULL) == (&head == tail) );
     183                verify( *tail == NULL );
    183184                return val;
    184185        }
    185 #endif
     186
     187        forall(dtype T | is_node(T))
     188        static inline bool ?!=?( __queue(T) & this, zero_t zero ) {
     189                return this.head != 0;
     190        }
     191#endif
     192
     193
     194//-----------------------------------------------------------------------------
     195// Doubly Linked List
     196//-----------------------------------------------------------------------------
     197#ifdef __cforall
     198        forall(dtype TYPE | sized(TYPE))
     199        #define T TYPE
     200        #define __getter_t * [T * & next, T * & prev] ( T & )
     201#else
     202        typedef void (*__generit_c_getter_t)();
     203        #define T void
     204        #define __getter_t __generit_c_getter_t
     205#endif
     206struct __dllist {
     207        T * head;
     208        __getter_t __get;
     209};
     210#undef T
     211#undef __getter_t
     212
     213#ifdef __cforall
     214#define __dllist_t(T) __dllist(T)
     215#else
     216#define __dllist_t(T) struct __dllist
     217#endif
     218
     219#ifdef __cforall
     220
     221        forall(dtype T | sized(T))
     222        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
     223                this.head{ NULL };
     224                this.__get = __get;
     225        }
     226
     227        #define next 0
     228        #define prev 1
     229        forall(dtype T | sized(T))
     230        static inline void push_front( __dllist(T) & this, T & node ) with( this ) {
     231                verify(__get);
     232                if ( head ) {
     233                        __get( node ).next = head;
     234                        __get( node ).prev = __get( *head ).prev;
     235                        // inserted node must be consistent before it is seen
     236                        // prevent code movement across barrier
     237                        asm( "" : : : "memory" );
     238                        __get( *head ).prev = &node;
     239                        T & _prev = *__get( node ).prev;
     240                        __get( _prev ).next = &node;
     241                }
     242                else {
     243                        __get( node ).next = &node;
     244                        __get( node ).prev = &node;
     245                }
     246
     247                // prevent code movement across barrier
     248                asm( "" : : : "memory" );
     249                head = &node;
     250        }
     251
     252        forall(dtype T | sized(T))
     253        static inline void remove( __dllist(T) & this, T & node ) with( this ) {
     254                verify(__get);
     255                if ( &node == head ) {
     256                        if ( __get( *head ).next == head ) {
     257                                head = NULL;
     258                        }
     259                        else {
     260                                head = __get( *head ).next;
     261                        }
     262                }
     263                __get( *__get( node ).next ).prev = __get( node ).prev;
     264                __get( *__get( node ).prev ).next = __get( node ).next;
     265                __get( node ).next = NULL;
     266                __get( node ).prev = NULL;
     267        }
     268
     269        forall(dtype T | sized(T))
     270        static inline bool ?!=?( __dllist(T) & this, zero_t zero ) {
     271                return this.head != 0;
     272        }
     273        #undef next
     274        #undef prev
     275#endif
     276
     277//-----------------------------------------------------------------------------
     278// Tools
     279//-----------------------------------------------------------------------------
     280#ifdef __cforall
     281
     282#endif
Note: See TracChangeset for help on using the changeset viewer.