source: libcfa/src/concurrency/ready_subqueue.hfa@ eeb9f9f

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since eeb9f9f was f6fdfb14, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Removed old sub-queue

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#pragma once
2
3#define __CFA_NO_SCHED_STATS__
4
5#include "containers/queueLockFree.hfa"
6
7// Intrusives lanes which are used by the relaxed ready queue
8struct __attribute__((aligned(128))) __intrusive_lane_t {
9 struct $thread * prev;
10
11 // spin lock protecting the queue
12 volatile bool lock;
13
14 __thread_desc_link anchor;
15};
16
17// Get the head pointer (one before the first element) from the anchor
18static inline $thread * mock_head(const __intrusive_lane_t & this) {
19 $thread * rhead = ($thread *)(
20 (uintptr_t)( &this.anchor ) - __builtin_offsetof( $thread, link )
21 );
22 return rhead;
23}
24
25// Ctor
26void ?{}( __intrusive_lane_t & this ) {
27 this.lock = false;
28 this.prev = mock_head(this);
29 this.anchor.next = 0p;
30 this.anchor.ts = 0;
31
32 // We add a boat-load of assertions here because the anchor code is very fragile
33 /* paranoid */ verify( ((uintptr_t)( mock_head(this) ) + offsetof( $thread, link )) == (uintptr_t)(&this.anchor) );
34 /* paranoid */ verify( &mock_head(this)->link.next == &this.anchor.next );
35 /* paranoid */ verify( &mock_head(this)->link.ts == &this.anchor.ts );
36 /* paranoid */ verify( mock_head(this)->link.next == 0p );
37 /* paranoid */ verify( mock_head(this)->link.ts == 0 );
38 /* paranoid */ verify( mock_head(this) == this.prev );
39 /* paranoid */ verify( __alignof__(__intrusive_lane_t) == 128 );
40 /* paranoid */ verify( __alignof__(this) == 128 );
41 /* paranoid */ verifyf( ((intptr_t)(&this) % 128) == 0, "Expected address to be aligned %p %% 128 == %zd", &this, ((intptr_t)(&this) % 128) );
42}
43
44// Dtor is trivial
45void ^?{}( __intrusive_lane_t & this ) {
46 // Make sure the list is empty
47 /* paranoid */ verify( this.anchor.next == 0p );
48 /* paranoid */ verify( this.anchor.ts == 0 );
49 /* paranoid */ verify( mock_head(this) == this.prev );
50}
51
52// Push a thread onto this lane
53// returns true of lane was empty before push, false otherwise
54void push( __intrusive_lane_t & this, $thread * node ) {
55 /* paranoid */ verify( node->link.next == 0p );
56 /* paranoid */ verify( node->link.ts == 0 );
57 /* paranoid */ verify( this.prev->link.next == 0p );
58 /* paranoid */ verify( this.prev->link.ts == 0 );
59 if( this.anchor.next == 0p ) {
60 /* paranoid */ verify( this.anchor.next == 0p );
61 /* paranoid */ verify( this.anchor.ts == 0 );
62 /* paranoid */ verify( this.prev == mock_head( this ) );
63 } else {
64 /* paranoid */ verify( this.anchor.next != 0p );
65 /* paranoid */ verify( this.anchor.ts != 0 );
66 /* paranoid */ verify( this.prev != mock_head( this ) );
67 }
68
69 // Get the relevant nodes locally
70 this.prev->link.next = node;
71 this.prev->link.ts = rdtscl();
72 this.prev = node;
73}
74
75// Pop a thread from this lane (must be non-empty)
76// returns popped
77// returns true of lane was empty before push, false otherwise
78$thread * pop( __intrusive_lane_t & this ) {
79 /* paranoid */ verify( this.anchor.next != 0p );
80 /* paranoid */ verify( this.anchor.ts != 0 );
81
82 // Get the relevant nodes locally
83 $thread * node = this.anchor.next;
84 this.anchor.next = node->link.next;
85 this.anchor.ts = node->link.ts;
86 bool is_empty = this.anchor.ts == 0;
87 node->link.next = 0p;
88 node->link.ts = 0;
89
90 // Update head time stamp
91 if(is_empty) this.prev = mock_head( this );
92
93 /* paranoid */ verify( node->link.next == 0p );
94 /* paranoid */ verify( node->link.ts == 0 );
95 return node;
96}
97
98// Check whether or not list is empty
99static inline bool is_empty(__intrusive_lane_t & this) {
100 return this.anchor.ts == 0;
101}
102
103// Return the timestamp
104static inline unsigned long long ts(__intrusive_lane_t & this) {
105 // Cannot verify here since it may not be locked
106 return this.anchor.ts;
107}
108
109// Aligned timestamps which are used by the relaxed ready queue
110struct __attribute__((aligned(128))) __timestamp_t {
111 volatile unsigned long long tv;
112};
113
114void ?{}(__timestamp_t & this) { this.tv = 0; }
115void ^?{}(__timestamp_t & this) {}
Note: See TracBrowser for help on using the repository browser.