Mercurial > MadButterfly
comparison src/observer.c @ 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 | c7e5b8779bb5 |
comparison
equal
deleted
inserted
replaced
126:55f2c6402c81 | 127:d2cc7400c971 |
---|---|
46 | 46 |
47 | 47 |
48 void subject_notify(ob_factory_t *factory, subject_t *subject, event_t *evt) { | 48 void subject_notify(ob_factory_t *factory, subject_t *subject, event_t *evt) { |
49 observer_t *observer; | 49 observer_t *observer; |
50 | 50 |
51 /*! | |
52 * \note What is happend when the subject is freed by observer? | |
53 * Postponding the request of free until notification | |
54 * been finished. (\ref SUBF_BUSY / \ref SUBF_FREE) | |
55 */ | |
56 subject->flags |= SUBF_BUSY; | |
57 | |
58 evt->tgt = subject; | 51 evt->tgt = subject; |
59 while(subject) { | 52 while(subject) { |
53 /*! | |
54 * \note What is happend when the subject is freed by observer? | |
55 * Postponding the request of free until notification | |
56 * been finished. (\ref SUBF_BUSY / \ref SUBF_FREE) | |
57 */ | |
58 subject->flags |= SUBF_BUSY; | |
59 | |
60 evt->cur_tgt = subject->obj; | 60 evt->cur_tgt = subject->obj; |
61 for(observer = STAILQ_HEAD(subject->observers); | 61 for(observer = STAILQ_HEAD(subject->observers); |
62 observer != NULL; | 62 observer != NULL; |
63 observer = STAILQ_NEXT(observer_t, next, observer)) { | 63 observer = STAILQ_NEXT(observer_t, next, observer)) { |
64 observer->hdr(evt, observer->arg); | 64 observer->hdr(evt, observer->arg); |
65 } | 65 } |
66 | 66 |
67 subject->flags &= ~SUBF_BUSY; | |
68 if(subject->flags & SUBF_FREE) | |
69 subject_free(factory, subject); | |
70 | |
67 if(subject->flags & SUBF_STOP_PROPAGATE) | 71 if(subject->flags & SUBF_STOP_PROPAGATE) |
68 break; | 72 break; |
69 | 73 |
70 subject = factory->get_parent_subject(factory, subject); | 74 subject = factory->get_parent_subject(factory, subject); |
71 } | 75 } |
72 | 76 |
73 subject->flags &= ~SUBF_BUSY; | |
74 if(subject->flags & SUBF_FREE) | |
75 subject_free(factory, subject); | |
76 } | 77 } |
77 | 78 |
78 observer_t *subject_add_observer(ob_factory_t *factory, | 79 observer_t *subject_add_observer(ob_factory_t *factory, |
79 subject_t *subject, | 80 subject_t *subject, |
80 evt_handler hdr, void *arg) { | 81 evt_handler hdr, void *arg) { |