@@ -205,7 +205,20 @@ namespace priv{
205205 struct Data {
206206 Mutex mtx;
207207 std::vector<std::shared_ptr<Function>> functions;
208+ std::atomic<bool > notified_ { false };
208209 bool enabled = true ;
210+
211+ bool didNotify () {
212+ if (notified_.load (std::memory_order_relaxed)) {
213+ notified_.store (false , std::memory_order_seq_cst);
214+ return true ;
215+ } else {
216+ return false ;
217+ }
218+ }
219+ void setNotified (bool state) {
220+ notified_.store (state, std::memory_order_relaxed);
221+ }
209222
210223 void remove (const BaseFunctionId & id){
211224 std::unique_lock<Mutex> lck (mtx);
@@ -425,9 +438,9 @@ class ofEventListeners{
425438 listeners.clear ();
426439 }
427440
428- bool empty () const {
429- return listeners.size () == 0 ;
430- }
441+ bool empty () const {
442+ return listeners.size () == 0 ;
443+ }
431444private:
432445 std::deque<ofEventListener> listeners;
433446};
@@ -566,18 +579,12 @@ class ofEvent: public of::priv::BaseEvent<of::priv::Function<T,Mutex>,Mutex>{
566579 // / \brief checks the state of the event
567580 // / \returns true if the Event's state was notified since the last check
568581 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 ;
574- }
582+ return ofEvent<T,Mutex>::self->didNotify ();
575583 }
576- std::atomic<bool > notified_ { false };
577-
584+
578585 inline bool notify (const void * sender, T & param) {
579586 if (ofEvent<T,Mutex>::self->enabled ) {
580- notified_. store ( true , std::memory_order_relaxed );
587+ ofEvent<T,Mutex>::self-> setNotified ( true );
581588 if (!ofEvent<T,Mutex>::self->functions .empty ()) {
582589 std::unique_lock<Mutex> lck (ofEvent<T,Mutex>::self->mtx );
583590 auto functions_copy = ofEvent<T,Mutex>::self->functions ;
@@ -729,18 +736,12 @@ class ofEvent<void,Mutex>: public of::priv::BaseEvent<of::priv::Function<void,Mu
729736 // / \brief checks the state of the event
730737 // / \returns true if the Event's state was notified since the last check
731738 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- }
739+ return ofEvent<void ,Mutex>::self->didNotify ();
738740 }
739- std::atomic<bool > notified_;
740741
741742 bool notify (const void * sender){
742743 if (ofEvent<void ,Mutex>::self->enabled ) {
743- notified_. store ( true , std::memory_order_relaxed );
744+ ofEvent< void ,Mutex>::self-> setNotified ( true );
744745 if (!ofEvent<void ,Mutex>::self->functions .empty ()) {
745746 std::unique_lock<Mutex> lck (ofEvent<void ,Mutex>::self->mtx );
746747 auto functions_copy = ofEvent<void ,Mutex>::self->functions ;
0 commit comments