- /* removes all watchers */
- while(evt->watchs != NULL)
- remove_watch(evt->watchs);
- free(evt);
+ /* unlinks the event if valid! */
+ pthread_mutex_lock(&events_mutex);
+ found = 0;
+ prv = &events;
+ while (*prv && !(found = (*prv == evt)))
+ prv = &(*prv)->next;
+ if (found)
+ *prv = evt->next;
+ pthread_mutex_unlock(&events_mutex);
+
+ /* destroys the event */
+ if (found) {
+ /* removes all watchers */
+ while(evt->watchs != NULL) {
+ listener = evt->watchs->listener;
+ pthread_mutex_lock(&listener->mutex);
+ pthread_mutex_lock(&evt->mutex);
+ remove_watch(evt->watchs);
+ pthread_mutex_unlock(&evt->mutex);
+ pthread_mutex_unlock(&listener->mutex);
+ }
+
+ /* hook */
+ if (evt->hookflags & afb_hook_flag_evt_drop)
+ afb_hook_evt_drop(evt->name, evt->id);
+
+ /* free */
+ pthread_mutex_destroy(&evt->mutex);
+ free(evt);
+ }