src/video/cocoa/SDL_cocoamousetap.m
changeset 7610 b043c5c726c1
parent 7607 7753a6f8cda8
child 7917 686df9c2b98a
     1.1 --- a/src/video/cocoa/SDL_cocoamousetap.m	Thu Aug 08 13:22:21 2013 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamousetap.m	Thu Aug 08 13:29:44 2013 -0700
     1.3 @@ -131,6 +131,12 @@
     1.4      return event;
     1.5  }
     1.6  
     1.7 +static void
     1.8 +SemaphorePostCallback(CFRunLoopTimerRef timer, void *info)
     1.9 +{
    1.10 +    SDL_SemPost((SDL_sem*)info);
    1.11 +}
    1.12 +
    1.13  static int
    1.14  Cocoa_MouseTapThread(void *data)
    1.15  {
    1.16 @@ -163,10 +169,11 @@
    1.17  
    1.18      tapdata->runloop = CFRunLoopGetCurrent();
    1.19      CFRunLoopAddSource(tapdata->runloop, tapdata->runloopSource, kCFRunLoopCommonModes);
    1.20 -    CFRunLoopPerformBlock(tapdata->runloop, kCFRunLoopCommonModes, ^{
    1.21 -        /* We signal this *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
    1.22 -        SDL_SemPost(tapdata->runloopStartedSemaphore);
    1.23 -    });
    1.24 +    CFRunLoopTimerContext context = {.info = tapdata->runloopStartedSemaphore};
    1.25 +    /* We signal the runloop started semaphore *after* the run loop has started, indicating it's safe to CFRunLoopStop it. */
    1.26 +    CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent(), 0, 0, 0, &SemaphorePostCallback, &context);
    1.27 +    CFRunLoopAddTimer(tapdata->runloop, timer, kCFRunLoopCommonModes);
    1.28 +    CFRelease(timer);
    1.29  
    1.30      /* Run the event loop to handle events in the event tap. */
    1.31      CFRunLoopRun();