From 5432e665fd6eac776c5985d98058e5c4645ec0e4 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Thu, 11 Aug 2016 17:39:39 +0200 Subject: ipcpd: Add condition variable to IPCP state This adds a condition variable to the IPCP state, so that upon state changes any listeners to state changes can be notified. It also replaces the read/write lock with a mutex in order to be able to do so. --- src/ipcpd/ipcp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/ipcpd/ipcp.c') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 24f580e5..5c066cb0 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -42,11 +42,22 @@ struct ipcp * ipcp_instance_create() i->irmd_fd = -1; i->state = IPCP_INIT; - pthread_rwlock_init(&i->state_lock, NULL); + pthread_mutex_init(&i->state_lock, NULL); + pthread_cond_init(&i->state_cond, NULL); return i; } +void ipcp_state_change(struct ipcp * ipcp, + enum ipcp_state state) +{ + if (ipcp == NULL) + return; + + ipcp->state = state; + pthread_cond_broadcast(&ipcp->state_cond); +} + int ipcp_parse_arg(int argc, char * argv[]) { char * log_file; -- cgit v1.2.3