#include <CoreFoundation/CoreFoundation.h>
static void
_perform(void *info __unused)
{
printf("hello\n");
}
static void
_timer(CFRunLoopTimerRef timer __unused, void *info)
{
CFRunLoopSourceSignal(info);
}
int
main()
{
CFRunLoopSourceRef source;
CFRunLoopSourceContext source_context;
CFRunLoopTimerRef timer;
CFRunLoopTimerContext timer_context;
bzero(&source_context, sizeof(source_context));
source_context.perform = _perform;
source = CFRunLoopSourceCreate(NULL, 0, &source_context);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
bzero(&timer_context, sizeof(timer_context));
timer_context.info = source;
timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent(), 1, 0, 0, _timer, &timer_context);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
CFRunLoopRun();
return 0;
}
#include <dispatch/dispatch.h>
#include <stdio.h>
int
main()
{
dispatch_source_t source, timer;
source = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_ADD, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_event_handler(source, ^{
printf("hello\n");
});
dispatch_resume(source);
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1ull * NSEC_PER_SEC, 0);
dispatch_source_set_event_handler(timer, ^{
dispatch_source_merge_data(source, 1);
});
dispatch_resume(timer);
dispatch_main();
}