From dc968e449f7a9ddc436465f2d57985a28c62dfd5 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 25 Jan 2016 19:23:41 +0100 Subject: [PATCH] Native fixed locking --- app/src/main/jni/netguard/netguard.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/main/jni/netguard/netguard.c b/app/src/main/jni/netguard/netguard.c index 316df97c..3c54521e 100644 --- a/app/src/main/jni/netguard/netguard.c +++ b/app/src/main/jni/netguard/netguard.c @@ -362,14 +362,8 @@ void *handle_events(void *a) { stopping = 0; signaled = 0; - if (pthread_mutex_lock(&lock)) - log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed"); - // Loop while (1) { - if (pthread_mutex_unlock(&lock)) - log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed"); - log_android(ANDROID_LOG_DEBUG, "Loop thread %lu", thread_id); // Check sessions @@ -384,9 +378,6 @@ void *handle_events(void *a) { udp_session == NULL && tcp_session == NULL ? NULL : &ts, &emptyset); - if (pthread_mutex_lock(&lock)) - log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed"); - if (ready < 0) { if (errno == EINTR) { if (stopping && signaled) { ; @@ -447,12 +438,18 @@ void *handle_events(void *a) { gettimeofday(&start, NULL); #endif + if (pthread_mutex_lock(&lock)) + log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed"); + // Check UDP downstream check_udp_sockets(args, &rfds, &wfds, &efds); // Check TCP downstream check_tcp_sockets(args, &rfds, &wfds, &efds); + if (pthread_mutex_unlock(&lock)) + log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed"); + #ifdef PROFILE gettimeofday(&end, NULL); mselapsed = (end.tv_sec - start.tv_sec) * 1000.0 + @@ -460,12 +457,10 @@ void *handle_events(void *a) { if (mselapsed > 1) log_android(ANDROID_LOG_INFO, "sockets %f", mselapsed); #endif + } } - if (pthread_mutex_unlock(&lock)) - log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed"); - (*env)->DeleteGlobalRef(env, args->instance); // Detach from Java