changeset 127:d2cc7400c971

Bug of subject_notify() when free subjects.
author Thinker K.F. Li <thinker@branda.to>
date Tue, 16 Sep 2008 16:06:04 +0800
parents 55f2c6402c81
children 07dc9ec71221
files src/observer.c
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/observer.c	Tue Sep 16 15:44:01 2008 +0800
+++ b/src/observer.c	Tue Sep 16 16:06:04 2008 +0800
@@ -48,15 +48,15 @@
 void subject_notify(ob_factory_t *factory, subject_t *subject, event_t *evt) {
     observer_t *observer;
 
-    /*!
-     * \note What is happend when the subject is freed by observer?
-     *		Postponding the request of free until notification
-     *		been finished. (\ref SUBF_BUSY / \ref SUBF_FREE)
-     */
-    subject->flags |= SUBF_BUSY;
-
     evt->tgt = subject;
     while(subject) {
+	/*!
+	 * \note What is happend when the subject is freed by observer?
+	 *		Postponding the request of free until notification
+	 *		been finished. (\ref SUBF_BUSY / \ref SUBF_FREE)
+	 */
+	subject->flags |= SUBF_BUSY;
+
 	evt->cur_tgt = subject->obj;
 	for(observer = STAILQ_HEAD(subject->observers);
 	    observer != NULL;
@@ -64,15 +64,16 @@
 	    observer->hdr(evt, observer->arg);
 	}
 
+	subject->flags &= ~SUBF_BUSY;
+	if(subject->flags & SUBF_FREE)
+	    subject_free(factory, subject);
+
 	if(subject->flags & SUBF_STOP_PROPAGATE)
 	    break;
 
 	subject = factory->get_parent_subject(factory, subject);
     }
 
-    subject->flags &= ~SUBF_BUSY;
-    if(subject->flags & SUBF_FREE)
-	subject_free(factory, subject);
 }
 
 observer_t *subject_add_observer(ob_factory_t *factory,