Skip to content

Commit

Permalink
Fix app freezing (fixes: wilix-team#93)
Browse files Browse the repository at this point in the history
I am not a c++ programmer, and I am not sure what I did here. But this fixes issue wilix-team#93.
  • Loading branch information
Luke265 committed Feb 13, 2019
1 parent 8233c8a commit a0aaddd
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/iohook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,43 @@ void dispatch_proc(uiohook_event * const event) {
case EVENT_HOOK_ENABLED:
// Lock the running mutex so we know if the hook is enabled.
#ifdef _WIN32
WaitForSingleObject(hook_running_mutex, INFINITE);
if (WaitForSingleObject(hook_running_mutex, 0) != WAIT_TIMEOUT) {
#else
pthread_mutex_lock(&hook_running_mutex);
if (pthread_mutex_trylock(&hook_running_mutex) == 0) {
#endif


#ifdef _WIN32
// Signal the control event.
SetEvent(hook_control_cond);
#else
// Unlock the control mutex so hook_enable() can continue.
pthread_cond_signal(&hook_control_cond);
pthread_mutex_unlock(&hook_control_mutex);
#endif
#ifdef _WIN32
// Signal the control event.
SetEvent(hook_control_cond);
#else
// Unlock the control mutex so hook_enable() can continue.
pthread_cond_signal(&hook_control_cond);
pthread_mutex_unlock(&hook_control_mutex);
#endif
}
break;

case EVENT_HOOK_DISABLED:
// Lock the control mutex until we exit.
#ifdef _WIN32
WaitForSingleObject(hook_control_mutex, INFINITE);
#ifdef _WIN32
if (WaitForSingleObject(hook_control_mutex, 0) != WAIT_TIMEOUT) {
#else
pthread_mutex_lock(&hook_control_mutex);
if (pthread_mutex_trylock(&hook_control_mutex) == 0) {
#endif

// Unlock the running mutex so we know if the hook is disabled.
#ifdef _WIN32
ReleaseMutex(hook_running_mutex);
ResetEvent(hook_control_cond);
#else
#if defined(__APPLE__) && defined(__MACH__)
// Stop the main runloop so that this program ends.
CFRunLoopStop(CFRunLoopGetMain());
#endif

pthread_mutex_unlock(&hook_running_mutex);
#endif
// Unlock the running mutex so we know if the hook is disabled.
#ifdef _WIN32
ReleaseMutex(hook_running_mutex);
ResetEvent(hook_control_cond);
#else
#if defined(__APPLE__) && defined(__MACH__)
// Stop the main runloop so that this program ends.
CFRunLoopStop(CFRunLoopGetMain());
#endif

pthread_mutex_unlock(&hook_running_mutex);
#endif
}
break;

case EVENT_KEY_PRESSED:
Expand Down

0 comments on commit a0aaddd

Please sign in to comment.