Ignore:
Timestamp:
Apr 1, 2021, 9:02:57 PM (3 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:
7ee3c87
Parents:
c426b03
Message:

ready queue can now toggle between

  • lock-based queue
  • mpsc_queue a.k.a. nemesis queue

slightly messy implementation, some clean up needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/ready_queue.cfa

    rc426b03 r7a2972b9  
    1818
    1919// #define USE_SNZI
     20// #define USE_MPSC
    2021
    2122#include "bits/defs.hfa"
     
    284285                #endif
    285286
     287        #if defined(USE_MPSC)
     288                // mpsc always succeeds
     289        } while( false );
     290        #else
    286291                // If we can't lock it retry
    287292        } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
     293        #endif
    288294
    289295        // Actually push it
     
    305311        #endif
    306312
    307         // Unlock and return
    308         __atomic_unlock( &lanes.data[i].lock );
     313        #if !defined(USE_MPSC)
     314                // Unlock and return
     315                __atomic_unlock( &lanes.data[i].lock );
     316        #endif
    309317
    310318        // Mark the current index in the tls rng instance as having an item
     
    493501
    494502static void check( __ready_queue_t & q ) with (q) {
    495         #if defined(__CFA_WITH_VERIFY__)
     503        #if defined(__CFA_WITH_VERIFY__) && !defined(USE_MPSC)
    496504                {
    497505                        for( idx ; lanes.count ) {
     
    504512                                assert(tail(sl)->link.prev->link.next == tail(sl) );
    505513
    506                                 if(sl.before.link.ts == 0l) {
     514                                if(is_empty(sl)) {
    507515                                        assert(tail(sl)->link.prev == head(sl));
    508516                                        assert(head(sl)->link.next == tail(sl));
     
    519527// fixes the list so that the pointers back to anchors aren't left dangling
    520528static inline void fix(__intrusive_lane_t & ll) {
    521         // if the list is not empty then follow he pointer and fix its reverse
    522         if(!is_empty(ll)) {
    523                 head(ll)->link.next->link.prev = head(ll);
    524                 tail(ll)->link.prev->link.next = tail(ll);
    525         }
    526         // Otherwise just reset the list
    527         else {
    528                 verify(tail(ll)->link.next == 0p);
    529                 tail(ll)->link.prev = head(ll);
    530                 head(ll)->link.next = tail(ll);
    531                 verify(head(ll)->link.prev == 0p);
    532         }
     529        #if !defined(USE_MPSC)
     530                // if the list is not empty then follow he pointer and fix its reverse
     531                if(!is_empty(ll)) {
     532                        head(ll)->link.next->link.prev = head(ll);
     533                        tail(ll)->link.prev->link.next = tail(ll);
     534                }
     535                // Otherwise just reset the list
     536                else {
     537                        verify(tail(ll)->link.next == 0p);
     538                        tail(ll)->link.prev = head(ll);
     539                        head(ll)->link.next = tail(ll);
     540                        verify(head(ll)->link.prev == 0p);
     541                }
     542        #endif
    533543}
    534544
Note: See TracChangeset for help on using the changeset viewer.