Create CFRunLoopSourceContext via calloc

This commit is contained in:
Michael Schneider 2016-03-18 14:32:45 -07:00
parent d1756baae7
commit 14b9df30a3

View File

@ -9,6 +9,7 @@
#import "ASRunLoopQueue.h" #import "ASRunLoopQueue.h"
#import "ASThread.h" #import "ASThread.h"
#import <cstdlib>
#import <deque> #import <deque>
static void runLoopSourceCallback(void *info) { static void runLoopSourceCallback(void *info) {
@ -44,9 +45,11 @@ static void runLoopSourceCallback(void *info) {
// It is not guaranteed that the runloop will turn if it has no scheduled work, and this causes processing of // It is not guaranteed that the runloop will turn if it has no scheduled work, and this causes processing of
// the queue to stop. Attaching a custom loop source to the run loop and signal it if new work needs to be done // the queue to stop. Attaching a custom loop source to the run loop and signal it if new work needs to be done
CFRunLoopSourceContext runLoopSourceContext = {0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &runLoopSourceCallback}; CFRunLoopSourceContext *runLoopSourceContext = (CFRunLoopSourceContext *)calloc(1, sizeof(CFRunLoopSourceContext));
_runLoopSource = CFRunLoopSourceCreate(NULL, 0, &runLoopSourceContext); runLoopSourceContext->perform = runLoopSourceCallback;
_runLoopSource = CFRunLoopSourceCreate(NULL, 0, runLoopSourceContext);
CFRunLoopAddSource(runloop, _runLoopSource, kCFRunLoopCommonModes); CFRunLoopAddSource(runloop, _runLoopSource, kCFRunLoopCommonModes);
free(runLoopSourceContext);
} }
return self; return self;
} }