本文整理匯總了C++中CFAbsoluteTimeGetCurrent函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFAbsoluteTimeGetCurrent函數的具體用法?C++ CFAbsoluteTimeGetCurrent怎麽用?C++ CFAbsoluteTimeGetCurrent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFAbsoluteTimeGetCurrent函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: dispatchUnicodeEvent
static void dispatchUnicodeEvent(char c)
{
UnicodeReport report;
static CFAbsoluteTime sDeadline = 0;
CFAbsoluteTime delta;
bzero(&report, sizeof(report));
if ( c < 'a' || c > 'z' )
return;
printf("dispatching unicode event for '%c'\n", c);
pthread_mutex_lock(&gMuxtex);
delta = sDeadline - CFAbsoluteTimeGetCurrent();
if ( delta > 0 )
usleep(delta*1000000);
report.usage = c;
OSSwapHostToLittleInt16(report.usage);
printReport((uint8_t*)&report, sizeof(report), 0);
IOHIDUserDeviceHandleReport(gDevice, (uint8_t*)&report, sizeof(report));
sDeadline = CFAbsoluteTimeGetCurrent() + kKeyboardInterval;
pthread_mutex_unlock(&gMuxtex);
}
示例2: fseventerCallback
void fseventerCallback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
(void)streamRef; // unused
(void)numEvents; // unused
(void)eventPaths; // unused
(void)eventFlags; // unused
(void)eventIds; // unused
Autobuild::Impl *mPimpl = static_cast<Autobuild::Impl*>(clientCallBackInfo);
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
// Ignore when events are under ignoretime from last executed event
if(now - mPimpl->last < mPimpl->ignore) {
return;
}
std::cout << "[autobuild] " << mPimpl->command << std::endl;
system(mPimpl->command);
// set the last updated timestamp *after* command
mPimpl->last = CFAbsoluteTimeGetCurrent();
}
示例3: dispatchKeyboardEvent
static void dispatchKeyboardEvent(char c)
{
KeyboardInputReport report;
static CFAbsoluteTime sDeadline = 0;
CFAbsoluteTime delta;
bzero(&report, sizeof(report));
if ( c < 'a' || c > 'z' )
return;
printf("dispatching keyboard event for '%c'\n", c);
pthread_mutex_lock(&gMuxtex);
delta = sDeadline - CFAbsoluteTimeGetCurrent();
if ( delta > 0 )
usleep(delta*1000000);
report.keys[0] = 4 + c - 97;
printReport((uint8_t*)&report, sizeof(report), 0);
IOHIDUserDeviceHandleReport(gDevice, (uint8_t*)&report, sizeof(report));
usleep(kKeyboardInterval*1000000);
report.keys[0] = 0;
printReport((uint8_t*)&report, sizeof(report), 0);
IOHIDUserDeviceHandleReport(gDevice, (uint8_t*)&report, sizeof(report));
sDeadline = CFAbsoluteTimeGetCurrent() + kKeyboardInterval;
pthread_mutex_unlock(&gMuxtex);
}
示例4: _HttpContextHandleHasBytesAvailable
/* static */ void
_HttpContextHandleHasBytesAvailable(HttpContextRef context) {
UInt8 buffer[2048];
// Try reading the bytes into the buffer.
CFIndex bytesRead = CFReadStreamRead(context->_inStream, buffer, sizeof(buffer));
// Reset the timeout.
CFRunLoopTimerSetNextFireDate(context->_timer, CFAbsoluteTimeGetCurrent() + kTimeOutInSeconds);
// If there wasn't an error (-1) and not end (0), process the data.
if (bytesRead > 0) {
// Add the bytes of data to the receive buffer.
CFDataAppendBytes(context->_rcvdBytes, buffer, bytesRead);
// Parse recieved data
int result = HTTPParseRequest(context);
if ( result == 1 ) {
// HTTP message is fully loaded, process it
HTTPProcessMessage(context);
// Reset the timeout.
CFRunLoopTimerSetNextFireDate(context->_timer, CFAbsoluteTimeGetCurrent() + kTimeOutInSeconds);
}
// If the ouput stream can write, try sending the bytes.
if (result != 0 && CFWriteStreamCanAcceptBytes(context->_outStream))
_HttpContextHandleCanAcceptBytes(context);
}
}
示例5: check_date_comparison
bool check_date_comparison ()
{
CFDateRef date1, date2;
// Standard Core Foundation comparison result.
CFComparisonResult result;
CFShow(CFSTR("Checking date comparison functions:"));
// Create two CFDates from absolute time.
date1 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent());
date2 = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent());
// Pass NULL for the context param.
result = CFDateCompare(date1, date2, NULL);
switch (result) {
case kCFCompareLessThan:
CFShow(CFSTR("date1 is before date2!\n"));
break;
case kCFCompareEqualTo:
CFShow(CFSTR("date1 is the same as date2!\n"));
break;
case kCFCompareGreaterThan:
CFShow(CFSTR("date1 is after date2!\n"));
break;
}
printf("\n");
return true;
}
示例6: test_dotproduct
void test_dotproduct() {
printf("--------------------------------------------------------------------------------\n");
printf("dot product\n");
printf("--------------------------------------------------------------------------------\n");
CFAbsoluteTime startTime;
float *inputOne, *inputTwo, *result, dotProduct;
int32_t strideOne=1, strideTwo=1;
uint32_t size = 1024;
int test_count = 100;
// alloc memory
inputOne = (float*)malloc(size * sizeof(float));
inputTwo = (float*)malloc(size * sizeof(float));
result = (float*)malloc(size * sizeof(float));
// initialize two vectors
for (int i = 0; i < size; i++) {
inputOne[i] = 1;
inputTwo[i] = 0.5;
}
printf("----------------------------------------\n");
printf("Condition\n");
// display condition
printf(" %d-dim vec\n", size);
printf(" test, %d times\n", test_count);
printf("----------------------------------------\n");
printf("Result\n");
// use vDSP
startTime=CFAbsoluteTimeGetCurrent();
for (int j = 0; j < test_count; j++) {
vDSP_dotpr(inputOne, strideOne, inputTwo, strideTwo, &dotProduct, size);
}
printf("Accelerate.framework\n");
printf(" %f msec\n", (CFAbsoluteTimeGetCurrent() - startTime)*1000.0f );
// use CPU
startTime=CFAbsoluteTimeGetCurrent();
for (int j = 0; j < test_count; j++) {
dotProduct = 0;
for (int i = 0; i < size; i++) {
dotProduct += inputOne[j] * inputTwo[j];
}
}
printf("Normal\n");
printf(" %f msec\n", (CFAbsoluteTimeGetCurrent() - startTime)*1000.0f );
printf("\n");
// release objects
free(inputOne);
free(inputTwo);
free(result);
}
示例7: doFftForStripeSize
/*
* -- Set up a plan for specified FFT type and column stripe size
* -- time the execution of 'loops' pairs of FFT;
* -- if elapsed time < current fastest, replace fasted time & stripe size with current
*/
static int doFftForStripeSize(
FFTParams *params,
size_t newStripeSize,
CFAbsoluteTime *fastest, // IN/OUT
size_t *fastestStripeSize, // IN/OUT
CFAbsoluteTime *slowest, // IN/OUT
Verbosity verbosity)
{
uint32_t fwdFlags = 0;
uint32_t invFlags = MEF_NormOutput;
MatrixFFTPlan mfftPlan;
MFFTReturn mrtn;
mfftSetColumnStripeSize(params->isReal, newStripeSize);
mrtn = mfftCreatePlan(params->dims, params->n, params->isReal, 0, 0, &mfftPlan);
if(mrtn) {
mfftPrintErrInfo("mfftCreatePlan", mrtn);
return -1;
}
CFAbsoluteTime startTime, endTime, elapsed;
if(verbosity == V_Noisy) {
printf("+++++++++ stripeSize %llu\n", (unsigned long long)newStripeSize);
}
startTime = CFAbsoluteTimeGetCurrent();
for(unsigned loop=0; loop<params->loops; loop++) {
mrtn = mfftExecute(mfftPlan, fwdFlags, true, params->buf, params->buf);
if(mrtn) {
mfftPrintErrInfo("mfftExecute(fwd)", mrtn);
break;
}
mrtn = mfftExecute(mfftPlan, invFlags, false, params->buf, params->buf);
if(mrtn) {
mfftPrintErrInfo("mfftExecute(inv)", mrtn);
break;
}
}
endTime = CFAbsoluteTimeGetCurrent();
elapsed = endTime - startTime;
if(verbosity == V_Noisy) {
printf(" elapsed %.2e\n", elapsed);
}
if((*fastest == 0.0) || // i.e. nothing measured yet
(*fastest > elapsed)) {
*fastest = elapsed;
*fastestStripeSize = newStripeSize;
}
if(elapsed > *slowest) {
*slowest = elapsed;
}
mfftFreePlan(mfftPlan);
return (mrtn == MR_Success) ? 0 : 1;
}
示例8: ASSERT
MessageQueueWaitResult WorkerRunLoop::runInMode(WorkerGlobalScope* context, const ModePredicate& predicate, WaitMode waitMode)
{
ASSERT(context);
ASSERT(context->thread().threadID() == currentThread());
#if PLATFORM(GTK) || PLATFORM(WPE)
GMainContext* mainContext = g_main_context_get_thread_default();
if (g_main_context_pending(mainContext))
g_main_context_iteration(mainContext, FALSE);
#endif
double deadline = MessageQueue<Task>::infiniteTime();
#if USE(CF)
CFAbsoluteTime nextCFRunLoopTimerFireDate = CFRunLoopGetNextTimerFireDate(CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
double timeUntilNextCFRunLoopTimerInSeconds = nextCFRunLoopTimerFireDate - CFAbsoluteTimeGetCurrent();
deadline = currentTime() + std::max(0.0, timeUntilNextCFRunLoopTimerInSeconds);
#endif
double absoluteTime = 0.0;
if (waitMode == WaitForMessage) {
if (predicate.isDefaultMode() && m_sharedTimer->isActive())
absoluteTime = std::min(deadline, m_sharedTimer->fireTime());
else
absoluteTime = deadline;
}
MessageQueueWaitResult result;
auto task = m_messageQueue.waitForMessageFilteredWithTimeout(result, predicate, absoluteTime);
// If the context is closing, don't execute any further JavaScript tasks (per section 4.1.1 of the Web Workers spec). However, there may be implementation cleanup tasks in the queue, so keep running through it.
switch (result) {
case MessageQueueTerminated:
break;
case MessageQueueMessageReceived:
task->performTask(*this, context);
break;
case MessageQueueTimeout:
if (!context->isClosing())
m_sharedTimer->fire();
#if USE(CF)
if (nextCFRunLoopTimerFireDate <= CFAbsoluteTimeGetCurrent())
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, /*returnAfterSourceHandled*/ false);
#endif
break;
}
return result;
}
示例9: WaitForValidPidFile
pid_t
WaitForValidPidFile(void)
{
CFAbsoluteTime patience = CFAbsoluteTimeGetCurrent() + kChildStartPidTimeout;
// Poll for a child process and pidfile to be generated, until we lose patience.
pid_t pid = -1;
while ((pid = CheckForValidPidFile()) == -1 && (patience - CFAbsoluteTimeGetCurrent() > 0))
sleep(1);
if (verbosity >= 3)
LogMessage("Discovered pid %d from pidfile %s\n", pid, pidFile);
return pid;
}
示例10: main
int
main(int argc, const char * argv[])
{
int result = 0;
FSEventStreamRef streamRef;
Boolean startedOK;
int flush_seconds = 3600; // When to force-flush any queued events
if(argc < 2 || strcasecmp(argv[1], "--help") == 0) {
fprintf(stderr, "usage: %s path ...\n", argv[0]);
exit(1);
}
const char **paths = &argv[1];
streamRef = my_FSEventStreamCreate(paths, argc-1);
FSEventStreamScheduleWithRunLoop(streamRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
startedOK = FSEventStreamStart(streamRef);
if (!startedOK) {
log_error("FSEventStreamStart(streamRef) failed");
goto out;
}
if (flush_seconds >= 0) {
log_debug("CFAbsoluteTimeGetCurrent() => %.3f", CFAbsoluteTimeGetCurrent());
CFAllocatorRef allocator = kCFAllocatorDefault;
CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + /*settings->*/flush_seconds;
CFTimeInterval interval = /*settings->*/flush_seconds;
CFOptionFlags flags = 0;
CFIndex order = 0;
CFRunLoopTimerCallBack callback = (CFRunLoopTimerCallBack)timer_callback;
CFRunLoopTimerContext context = { 0, streamRef, NULL, NULL, NULL };
CFRunLoopTimerRef timer = CFRunLoopTimerCreate(allocator, fireDate, interval, flags, order, callback, &context);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopDefaultMode);
}
// Run
CFRunLoopRun();
// Stop / Invalidate / Release
FSEventStreamStop(streamRef);
out:
FSEventStreamInvalidate(streamRef);
FSEventStreamRelease(streamRef);
return result;
}
示例11: timer_callout_set
int
timer_callout_set(timer_callout_t * callout,
CFAbsoluteTime relative_time, timer_func_t * func,
void * arg1, void * arg2, void * arg3)
{
CFRunLoopTimerContext context = { 0, NULL, NULL, NULL, NULL };
CFAbsoluteTime wakeup_time;
if (callout == NULL) {
return (0);
}
timer_cancel(callout);
if (func == NULL) {
return (0);
}
callout->func = func;
callout->arg1 = arg1;
callout->arg2 = arg2;
callout->arg3 = arg3;
callout->enabled = TRUE;
callout->time_generation = S_time_generation;
context.info = callout;
wakeup_time = CFAbsoluteTimeGetCurrent() + relative_time;
callout->timer_source
= CFRunLoopTimerCreate(NULL, wakeup_time,
0.0, 0, 0,
timer_callout_process,
&context);
my_log(LOG_DEBUG, "timer: wakeup time is (%0.09g) %0.09g",
relative_time, wakeup_time);
my_log(LOG_DEBUG, "timer: adding timer source");
CFRunLoopAddTimer(CFRunLoopGetCurrent(), callout->timer_source,
kCFRunLoopDefaultMode);
return (1);
}
示例12: timer_callback
static void
timer_callback(CFRunLoopRef timer, void *info) {
FSEventStreamRef streamRef = (FSEventStreamRef)info;
log_debug("CFAbsoluteTimeGetCurrent() => %.3f", CFAbsoluteTimeGetCurrent());
log_debug("FSEventStreamFlushAsync(streamRef = %p)...", streamRef);
FSEventStreamFlushAsync(streamRef);
}
示例13: rwsched_cfrunloop_relocate_timers_to_main_mode
void
rwsched_cfrunloop_relocate_timers_to_main_mode(rwsched_tasklet_ptr_t sched_tasklet)
{
//unsigned int i, j;
unsigned int i;
rwsched_CFRunLoopTimerRef rwsched_object;
rwsched_instance_ptr_t instance;
// Validate input parameters
RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t);
for (i = 1 ; i < sched_tasklet->cftimer_array->len ; i++) {
if ((rwsched_object = g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, i)) != NULL) {
RW_CF_TYPE_VALIDATE(rwsched_object, rwsched_CFRunLoopTimerRef);
instance = rwsched_object->callback_context.instance;
RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);
//CFRunLoopRemoveTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->deferred_cfrunloop_mode);
if (rwsched_object->onetime_timer_fired_while_blocked) {
//(rwsched_object->cf_callout)(rwsched_object, rwsched_object->cf_context.info);
RW_ASSERT(rwsched_object->onetime_timer);
rwsched_object->cf_object = CFRunLoopTimerCreate(rwsched_object->ott.allocator,
CFAbsoluteTimeGetCurrent()+0.000001,
0,
rwsched_object->ott.flags,
rwsched_object->ott.order,
rwsched_cftimer_callout_intercept,
&rwsched_object->tmp_context);
rwsched_object->onetime_timer_fired_while_blocked = 0;
}
CFRunLoopAddTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->main_cfrunloop_mode);
}
}
}
示例14: fx_setTimeout
void fx_setTimeout(txMachine* the)
{
txTimeoutData* data;
#if mxMacOSX
CFRunLoopTimerContext context;
#endif
txNumber duration = fxToNumber(the, mxArgv(1)) / 1000;
data = c_malloc(sizeof(txTimeoutData));
mxElseError(data);
c_memset(data, 0, sizeof(txTimeoutData));
data->the = the;
data->function.kind = mxArgv(0)->kind;
data->function.value = mxArgv(0)->value;
fxRemember(the, &(data->function));
if (mxArgc > 2) {
data->argument.kind = mxArgv(2)->kind;
data->argument.value = mxArgv(2)->value;
}
fxRemember(the, &(data->argument));
#if mxMacOSX
memset(&context, 0, sizeof(context));
context.info = data;
context.release = fx_setTimeoutRelease;
data->timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + duration, 0, 0, 0, fx_setTimeoutCallback, &context);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), data->timer, gxRunLoopMode);
#endif
}
示例15: WaitForValidPidFile
/* WaitForValidPidFile: Sometimes a valid pidfile will need to be generated first before anything can be done.
* Arguments: None.
* Return value: The valid pidfile that was found after waiting for it.
* Notes: Requires CoreFoundation (checked for by the MP_CHECK_FRAMEWORK_COREFOUNDATION autoconf macro in configure.ac, which comes from acinclude.m4)
*/
pid_t
WaitForValidPidFile(void)
{
CFAbsoluteTime patience = CFAbsoluteTimeGetCurrent() + kChildStartPidTimeout;
// Poll for a child process and pidfile to be generated, until we lose patience (literally: "patience" is a variable name).
// TODO: polling is generally considered bad; could there be a better way to do this?
pid_t pid = -1;
while ((pid = CheckForValidPidFile()) == -1 && (patience - CFAbsoluteTimeGetCurrent() > 0))
sleep(1);
if (verbosity >= 3)
LogMessage("Discovered pid %d from pidfile %s\n", pid, pidFile);
return pid;
}