@@ -563,33 +563,38 @@ class ofEvent: public of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>{
563563 ofEvent<T,Mutex>::self->remove (*make_function (std::function<typename of::priv::callable_traits<TFunction>::function_type>(function), priority)->id );
564564 }
565565
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 ;
576574 }
577- return false ;
578575 }
576+ std::atomic<bool > notified_ { false };
579577
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+ }
588589 }
589590 }
590591 }
591592 return false ;
592593 }
594+
595+ inline bool notify (T & param){
596+ return this ->notify (nullptr , param);
597+ }
593598};
594599
595600
@@ -721,32 +726,37 @@ class ofEvent<void,Mutex>: public of::priv::BaseEvent<of::priv::Function<void,Mu
721726 ofEvent<void ,Mutex>::self->remove (*make_function (std::function<typename of::priv::callable_traits<TFunction>::function_type>(function),priority)->id );
722727 }
723728
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+
724741 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+ }
732752 }
733753 }
734754 }
735755 return false ;
736756 }
737757
738758 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 );
750760 }
751761};
752762
0 commit comments