@@ -563,33 +563,38 @@ class ofEvent: public of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>{
563
563
ofEvent<T,Mutex>::self->remove (*make_function (std::function<typename of::priv::callable_traits<TFunction>::function_type>(function), priority)->id );
564
564
}
565
565
566
- inline bool notify (const void * sender, T & param){
567
- if (ofEvent<T,Mutex>::self->enabled && !ofEvent<T,Mutex>::self->functions .empty ()){
568
- std::unique_lock<Mutex> lck (ofEvent<T,Mutex>::self->mtx );
569
- auto functions_copy = ofEvent<T,Mutex>::self->functions ;
570
- lck.unlock ();
571
- for (auto & f: functions_copy){
572
- if (f->notify (sender,param)){
573
- return true ;
574
- }
575
- }
566
+ // / \brief checks the state of the event
567
+ // / \returns true if the Event's state was notified since the last check
568
+ bool didNotify () {
569
+ if (notified_.load (std::memory_order_relaxed)) {
570
+ notified_.store (false , std::memory_order_seq_cst);
571
+ return true ;
572
+ } else {
573
+ return false ;
576
574
}
577
- return false ;
578
575
}
576
+ std::atomic<bool > notified_ { false };
579
577
580
- inline bool notify (T & param){
581
- if (ofEvent<T,Mutex>::self->enabled && !ofEvent<T,Mutex>::self->functions .empty ()){
582
- std::unique_lock<Mutex> lck (ofEvent<T,Mutex>::self->mtx );
583
- auto functions_copy = ofEvent<T,Mutex>::self->functions ;
584
- lck.unlock ();
585
- for (auto & f: functions_copy){
586
- if (f->notify (nullptr ,param)){
587
- return true ;
578
+ inline bool notify (const void * sender, T & param) {
579
+ if (ofEvent<T,Mutex>::self->enabled ) {
580
+ notified_.store (true , std::memory_order_relaxed);
581
+ if (!ofEvent<T,Mutex>::self->functions .empty ()) {
582
+ std::unique_lock<Mutex> lck (ofEvent<T,Mutex>::self->mtx );
583
+ auto functions_copy = ofEvent<T,Mutex>::self->functions ;
584
+ lck.unlock ();
585
+ for (auto & f: functions_copy) {
586
+ if (f->notify (sender,param)) {
587
+ return true ;
588
+ }
588
589
}
589
590
}
590
591
}
591
592
return false ;
592
593
}
594
+
595
+ inline bool notify (T & param){
596
+ return this ->notify (nullptr , param);
597
+ }
593
598
};
594
599
595
600
@@ -721,32 +726,37 @@ class ofEvent<void,Mutex>: public of::priv::BaseEvent<of::priv::Function<void,Mu
721
726
ofEvent<void ,Mutex>::self->remove (*make_function (std::function<typename of::priv::callable_traits<TFunction>::function_type>(function),priority)->id );
722
727
}
723
728
729
+ // / \brief checks the state of the event
730
+ // / \returns true if the Event's state was notified since the last check
731
+ bool didNotify () {
732
+ if (notified_.load (std::memory_order_relaxed)) {
733
+ notified_.store (false , std::memory_order_seq_cst);
734
+ return true ;
735
+ } else {
736
+ return false ;
737
+ }
738
+ }
739
+ std::atomic<bool > notified_;
740
+
724
741
bool notify (const void * sender){
725
- if (ofEvent<void ,Mutex>::self->enabled && !ofEvent<void ,Mutex>::self->functions .empty ()){
726
- std::unique_lock<Mutex> lck (ofEvent<void ,Mutex>::self->mtx );
727
- auto functions_copy = ofEvent<void ,Mutex>::self->functions ;
728
- lck.unlock ();
729
- for (auto & f: functions_copy){
730
- if (f->notify (sender)){
731
- return true ;
742
+ if (ofEvent<void ,Mutex>::self->enabled ) {
743
+ notified_.store (true , std::memory_order_relaxed);
744
+ if (!ofEvent<void ,Mutex>::self->functions .empty ()) {
745
+ std::unique_lock<Mutex> lck (ofEvent<void ,Mutex>::self->mtx );
746
+ auto functions_copy = ofEvent<void ,Mutex>::self->functions ;
747
+ lck.unlock ();
748
+ for (auto & f: functions_copy) {
749
+ if (f->notify (sender)) {
750
+ return true ;
751
+ }
732
752
}
733
753
}
734
754
}
735
755
return false ;
736
756
}
737
757
738
758
bool notify (){
739
- if (ofEvent<void ,Mutex>::self->enabled && !ofEvent<void ,Mutex>::self->functions .empty ()){
740
- std::unique_lock<Mutex> lck (ofEvent<void ,Mutex>::self->mtx );
741
- auto functions_copy = ofEvent<void ,Mutex>::self->functions ;
742
- lck.unlock ();
743
- for (auto & f: functions_copy){
744
- if (f->notify (nullptr )){
745
- return true ;
746
- }
747
- }
748
- }
749
- return false ;
759
+ return this ->notify (nullptr );
750
760
}
751
761
};
752
762
0 commit comments