1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2025-02-25 15:42:53 +00:00

Native fixed locking

This commit is contained in:
M66B 2016-01-25 19:23:41 +01:00
parent 6b7ecedffe
commit dc968e449f

View file

@ -362,14 +362,8 @@ void *handle_events(void *a) {
stopping = 0; stopping = 0;
signaled = 0; signaled = 0;
if (pthread_mutex_lock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed");
// Loop // Loop
while (1) { 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); log_android(ANDROID_LOG_DEBUG, "Loop thread %lu", thread_id);
// Check sessions // Check sessions
@ -384,9 +378,6 @@ void *handle_events(void *a) {
udp_session == NULL && tcp_session == NULL ? NULL : &ts, udp_session == NULL && tcp_session == NULL ? NULL : &ts,
&emptyset); &emptyset);
if (pthread_mutex_lock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed");
if (ready < 0) { if (ready < 0) {
if (errno == EINTR) { if (errno == EINTR) {
if (stopping && signaled) { ; if (stopping && signaled) { ;
@ -447,12 +438,18 @@ void *handle_events(void *a) {
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
#endif #endif
if (pthread_mutex_lock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed");
// Check UDP downstream // Check UDP downstream
check_udp_sockets(args, &rfds, &wfds, &efds); check_udp_sockets(args, &rfds, &wfds, &efds);
// Check TCP downstream // Check TCP downstream
check_tcp_sockets(args, &rfds, &wfds, &efds); check_tcp_sockets(args, &rfds, &wfds, &efds);
if (pthread_mutex_unlock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed");
#ifdef PROFILE #ifdef PROFILE
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
mselapsed = (end.tv_sec - start.tv_sec) * 1000.0 + mselapsed = (end.tv_sec - start.tv_sec) * 1000.0 +
@ -460,12 +457,10 @@ void *handle_events(void *a) {
if (mselapsed > 1) if (mselapsed > 1)
log_android(ANDROID_LOG_INFO, "sockets %f", mselapsed); log_android(ANDROID_LOG_INFO, "sockets %f", mselapsed);
#endif #endif
} }
} }
if (pthread_mutex_unlock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed");
(*env)->DeleteGlobalRef(env, args->instance); (*env)->DeleteGlobalRef(env, args->instance);
// Detach from Java // Detach from Java