Mark an nl_pid_watch_t busy while it is being scanned. If a
client callback destroys the last watch, check if the pid
watch is busy. If it is, just unhash it and mark it dead,
otherwise unhash and destroy it right away. Each time a watch
scan finishes, check and destroy the watch if it has been
marked dead.
mrp_list_hook_t clients;
int n_clients;
+ int busy : 1;
+ int dead : 1;
} nl_pid_watch_t;
/* murphy pid file directory notify */
MRP_UNUSED(key);
- mrp_free(w);
+ if (!w->busy)
+ mrp_free(w);
+ else
+ w->dead = TRUE;
}
break;
}
+ nl_w->busy = TRUE;
mrp_list_foreach(&nl_w->clients, p, n) {
nl_pid_client_t *client;
client->cb(nl_w->pid, MRP_PROCESS_STATE_NOT_READY,
client->user_data);
}
+ if (nl_w->dead)
+ mrp_free(nl_w);
+ else
+ nl_w->busy = FALSE;
/* TODO: should we automatically free the wathces? Or let
* client do that to preserver symmetricity? */