Ignore:
Timestamp:
May 18, 2018, 2:09:21 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
2472a19
Parents:
f6f0cca3 (diff), c7d8100c (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 remote-tracking branch 'origin/master' into with_gc

File:
1 edited

Legend:

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

    rf6f0cca3 rff29f08  
    186186#endif
    187187
     188
     189//-----------------------------------------------------------------------------
     190// Doubly Linked List
     191//-----------------------------------------------------------------------------
     192#ifdef __cforall
     193        forall(dtype TYPE | sized(TYPE))
     194        #define T TYPE
     195        #define __getter_t * [T * & next, T * & prev] ( T & )
     196#else
     197        typedef void (*__generit_c_getter_t)();
     198        #define T void
     199        #define __getter_t __generit_c_getter_t
     200#endif
     201struct __dllist {
     202        T * head;
     203        __getter_t __get;
     204};
     205#undef T
     206#undef __getter_t
     207
     208#ifdef __cforall
     209#define __dllist_t(T) __dllist(T)
     210#else
     211#define __dllist_t(T) struct __dllist
     212#endif
     213
     214#ifdef __cforall
     215
     216        forall(dtype T | sized(T))
     217        static inline [void] ?{}( __dllist(T) & this, * [T * & next, T * & prev] ( T & ) __get ) {
     218                this.head{ NULL };
     219                this.__get = __get;
     220        }
     221
     222        #define _next .0
     223        #define _prev .1
     224        forall(dtype T | sized(T))
     225        static inline void push_front( __dllist(T) & this, T & node ) with( this ) {
     226                if ( head ) {
     227                        __get( node )_next = head;
     228                        __get( node )_prev = __get( *head )_prev;
     229                        // inserted node must be consistent before it is seen
     230                        // prevent code movement across barrier
     231                        asm( "" : : : "memory" );
     232                        __get( *head )_prev = &node;
     233                        T & prev = *__get( node )_prev;
     234                        __get( prev )_next = &node;
     235                }
     236                else {
     237                        __get( node )_next = &node;
     238                        __get( node )_prev = &node;
     239                }
     240
     241                // prevent code movement across barrier
     242                asm( "" : : : "memory" );
     243                head = &node;
     244        }
     245
     246        forall(dtype T | sized(T))
     247        static inline void remove( __dllist(T) & this, T & node ) with( this ) {
     248                if ( &node == head ) {
     249                        if ( __get( *head )_next == head ) {
     250                                head = NULL;
     251                        }
     252                        else {
     253                                head = __get( *head )_next;
     254                        }
     255                }
     256                __get( *__get( node )_next )_prev = __get( node )_prev;
     257                __get( *__get( node )_prev )_next = __get( node )_next;
     258                __get( node )_next = NULL;
     259                __get( node )_prev = NULL;
     260        }
     261        #undef _next
     262        #undef _prev
     263#endif
     264
    188265//-----------------------------------------------------------------------------
    189266// Tools
Note: See TracChangeset for help on using the changeset viewer.