source: tests/concurrent/preempt.cfa @ e21f253

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since e21f253 was b200492, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Fixed last push which wasn't checked properly.

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[c0f881b]1#include <fstream.hfa>
[096a2ff]2#include <kernel.hfa>
[73abe95]3#include <thread.hfa>
4#include <time.hfa>
[11dbfe1]5
[dc8511c]6#include "long_tests.hfa"
[7bdcac1]7
[11dbfe1]8#ifndef PREEMPTION_RATE
[8ad6533]9#define PREEMPTION_RATE 10`ms
[11dbfe1]10#endif
11
[8ad6533]12Duration default_preemption() {
[11dbfe1]13        return PREEMPTION_RATE;
14}
15
[7bdcac1]16#ifdef TEST_LONG
[b2fe1c9]17static const unsigned long N = 30_000ul;
18#else
19static const unsigned long N = 500ul;
20#endif
21
[b68fc85]22extern void __cfaabi_check_preemption();
23
[11dbfe1]24static volatile int counter = 0;
25
[0322865c]26thread worker_t {
[11dbfe1]27        int value;
[b200492]28        unsigned spin;
[11dbfe1]29};
30
[2afec66]31void ?{}( worker_t & this, int value ) {
32        this.value = value;
[1612315]33        this.spin = 0;
[11dbfe1]34}
35
[83a071f9]36void main(worker_t & this) {
[7bdcac1]37        while(TEST(counter < N)) {
[1612315]38                if(this.spin > 100_000_000) abort | "Worker" | this.value | "has been spinning too long! (" | this.spin | ")";
[b68fc85]39                __cfaabi_check_preemption();
[83a071f9]40                if( (counter % 7) == this.value ) {
[b68fc85]41                        __cfaabi_check_preemption();
[c701332a]42                        int next = __atomic_add_fetch( &counter, 1, __ATOMIC_SEQ_CST );
[b68fc85]43                        __cfaabi_check_preemption();
[12d2dc8]44                        if( (next % 100) == 0 ) printf("%d\n", (int)next);
[b68fc85]45                        __cfaabi_check_preemption();
[b200492]46                        this.spin = 0;
[11dbfe1]47                }
[b68fc85]48                __cfaabi_check_preemption();
[7bdcac1]49                KICK_WATCHDOG;
[1612315]50                this.spin++;
[11dbfe1]51        }
52}
53
54int main(int argc, char* argv[]) {
55        processor p;
56        {
[0322865c]57                worker_t w0 = 0;
58                worker_t w1 = 1;
59                worker_t w2 = 2;
60                worker_t w3 = 3;
61                worker_t w4 = 4;
62                worker_t w5 = 5;
63                worker_t w6 = 6;
[11dbfe1]64        }
[2afec66]65}
Note: See TracBrowser for help on using the repository browser.