Giter Site home page Giter Site logo

Comments (9)

kwhat avatar kwhat commented on May 18, 2024

Hi,

Thanks for the report! The double lock should cause the calling thread of the second lock to wait until the mutex is unlocked by some other thread. In this case the callback thread should be waiting for the main runloop to execute the message_port_proc function. Either the main runloop never woke up or something is stuck somewhere in this function. There was another report here about a similar issue, but I can't seem to duplicate it. Are you building from source, if so what version? Could you drop a break-point in one of the functions and see if you can figure out where it gets stuck? Much appreciated, and I am glad you are enjoying the project ;)

from libuiohook.

reppners avatar reppners commented on May 18, 2024

Hi,

I'm building from source with the latest repository version of the master branch.
It is basically your demo_hook application.

I put a breakpoint in the message_port_proc and it never got called.

So this seems to be the issue but I'm not an expert in POSIX-thread programming(did some a few years ago) - can you give me any hints about what I could try? Also on which OSX version are you developing the library? Since it seems to be only a problem on MacBook Air/OSX Maverix so far.

Just for checking I commented out the "event.reserved" if-clause where the mutex is locked and it works just fine this way.

QUICK_FIX: To be able to build I had to make a small change here. I changed this line to:
scancode = keycode_scancode_table[keycode][0];

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

Alright, I was able to duplicate the issue on a 10.9 machine I have access to. It looks like the main runloop never gets woken up for some reason. Its more of an Apple thread RunLoop issue.

A little background about what is going on with the code in question: In order to get the char associated with the key that was pressed and the current keyboard layout and language the TIS functions in keycode_to_string need to be called. The problem is that the TIS functions can only be called from the "main CFRunLoop." It looks like start_message_port_runloop was called successfully, so the function should be running on the main CFRunLoop but its not starting because it is not receiving the signal or it terminated after starting for some reason.

On to the bizarre: So the code in question works fine in the parent project on the same computer. The only difference being what thread CFRunLoop start_message_port_runloop gets called from. In the demo application, that runloop is main.

If I was to take a guess, we are signaling message_port_proc to start, but it cannot because main never sleeps correctly in the demo. I am guessing that the ideal solution would be to stop the main run loop if it is active, then execute message_port_proc, and resume the main runloop... I just don't have a clue how to do that yet ;)

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

I did a little more digging and I don't believe the main runloop was started correctly in the example, also, that double lock you mentioned earlier should use a condition variable instead of a mutex but thats the smaller of the two issues. The main runloop issues is going to take some reworking to fix. I have a feeling I abused that functionality in new and unique ways.

from libuiohook.

reppners avatar reppners commented on May 18, 2024

Thanks for the details, I start to get a clear picture of whats going on. Got to get used to read C-Code again ;)
I read this Apple Doc about RunLoops. Seems like a powerful tool for thread-programming.
Unfortunately at the moment I don't have enough time to start digging deeper and come up with a valid solution.

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

This should work for the demo. The issue is the main run loop never started so you cant wake it up. This code needs some improvement so I am going to leave this bug open for a little while.

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- origin/master
+++ HEAD
@@ -91,8 +91,12 @@
        #ifdef _WIN32
        Sleep(100);
        #else
+       #if defined(__APPLE__) && defined(__MACH__)
+       CFRunLoopRun();
+       #else
        nanosleep((struct timespec[]) {{0, 100 * 1000000}}, NULL);
        #endif
+       #endif
    }

    if (hook_is_enabled()) {

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

Alright I have pushed some changes that will solve the problem and a check to make sure it wont deadlock. I still need to fix the mutex issue. Have you checked the CPU usage for the program? I am wondering if it is using 100% of one or more cores.

from libuiohook.

reppners avatar reppners commented on May 18, 2024

Checked it out and it works like a charm - awesome!
Also had an eye on CPU usage. Nothing suspicious here.
Great work :)

from libuiohook.

kwhat avatar kwhat commented on May 18, 2024

Awesome! I did notice that the run loop seems to time out after some short period of inactivity... Keep an eye on it, if you notice it stop working please open a new bug. Thanks again for the report!

from libuiohook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.