@@ -36,28 +36,33 @@ void cpuAsyncLoad(void *args);
3636void cpuAsyncLoadWithMaxSpinCount (void *args);
3737
3838struct flagcxHostSemaphore {
39- int flag; // if ready to be triggered
40- int counter; // total operations to wait for inside the group
39+ int start = 0 ; // started or not
40+ int end = 0 ; // ended or not
41+ int counter = 0 ; // total operations to wait for inside the group
4142 std::vector<flagcxEvent_t> events;
4243
44+ ~flagcxHostSemaphore () {
45+ for (auto event : events) {
46+ deviceAdaptor->eventDestroy (event);
47+ }
48+ }
4349 flagcxEvent_t getEvent () {
4450 events.push_back (nullptr );
4551 auto &event = events.back ();
4652 deviceAdaptor->eventCreate (&event);
4753 return event;
4854 }
49- void signalFlag () { __atomic_store_n (&flag, 1 , __ATOMIC_RELEASE); }
55+ void signalStart () { __atomic_store_n (&start, 1 , __ATOMIC_RELEASE); }
56+ void signalEnd () { __atomic_store_n (&end, 1 , __ATOMIC_RELEASE); }
5057 void signalCounter (int value) {
5158 __atomic_fetch_sub (&counter, value, __ATOMIC_RELEASE);
5259 }
53- int poll () { return __atomic_load_n (&flag, __ATOMIC_ACQUIRE); }
60+ int pollStart () { return __atomic_load_n (&start, __ATOMIC_ACQUIRE); }
61+ int pollEnd () { return __atomic_load_n (&end, __ATOMIC_ACQUIRE); }
5462 void wait () {
5563 while (__atomic_load_n (&counter, __ATOMIC_ACQUIRE) > 0 ) {
5664 sched_yield ();
5765 }
58- for (auto event : events) {
59- deviceAdaptor->eventDestroy (event);
60- }
6166 }
6267};
6368
0 commit comments