source: tests/concurrency/migrate.cfa@ 6cb3e5d

Last change on this file since 6cb3e5d was 10b5970, checked in by Michael Brooks <mlbrooks@…>, 8 months ago

Fix many test-suite- and libcfa-caused unused variable warnings.

In scope are easy fixes among tests whose sole warnings were unused variable. Reduces the wflags lax list by 40%.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <fstream.hfa>
2#include <kernel.hfa>
3#include <thread.hfa>
4
5#include <stdatomic.h>
6#include <assert.h>
7
8struct cluster_wrapper {
9 cluster self;
10 const uint64_t canary;
11 struct {
12 volatile uint64_t want;
13 volatile uint64_t have;
14 } checksum;
15};
16
17void ?{}( cluster_wrapper & this ) {
18 (this.self){};
19 (*(uint64_t *)&this.canary) = 0xDEAD2BADDEAD2BAD;
20 this.checksum.want = 0;
21 this.checksum.have = 0;
22}
23
24void ^?{}( cluster_wrapper & this ) {
25 assert(this.canary == 0xDEAD2BADDEAD2BAD);
26}
27
28static cluster_wrapper * the_clusters;
29static unsigned cluster_cnt;
30
31thread MyThread {
32
33};
34
35void ?{}( MyThread & this ) {}
36
37void checkcl( MyThread & this, cluster * cl) {
38 if(((thread&)this).curr_cluster != cl) {
39 abort | "Thread has unexpected cluster";
40 }
41}
42
43void main( MyThread & this ) {
44 waitfor( migrate : this ) {
45 assert( ((thread&)this).curr_cluster == active_cluster() );
46 assert( ((thread&)this).curr_cluster == active_processor()->cltr );
47 }
48
49 for(100) {
50 unsigned idx = prng( this, cluster_cnt );
51
52 struct cluster_wrapper * next = &the_clusters[ idx ];
53 assert(next->canary == 0xDEAD2BADDEAD2BAD);
54
55 // next->
56
57 migrate( this, next->self );
58
59 assert( active_cluster() == &next->self );
60 assert( ((thread&)this).curr_cluster == active_cluster() );
61 assert( ((thread&)this).curr_cluster == active_processor()->cltr );
62 }
63}
64
65int main() {
66 cluster_cnt = 3;
67 cluster_wrapper cl[cluster_cnt];
68 the_clusters = cl;
69
70 {
71 set_concurrency( cl[0].self, 2 );
72 set_concurrency( cl[1].self, 2 );
73 set_concurrency( cl[2].self, 1 );
74
75 MyThread threads[17];
76 for(i;17) {
77 migrate( threads[i], cl[0].self );
78 }
79
80 }
81 // non-empty .expect file
82 printf( "done\n" );
83}
Note: See TracBrowser for help on using the repository browser.