示例#1
0
void queue::after(
    dispatch_time_t time,
    operation *op
)
{
    dispatch_after_f( time, d->native, op, _xdispatch_run_operation );
}
示例#2
0
void
func_outer(void* context)
{
    UNREFERENCED_PARAMETER(context);
    time_a_min = dispatch_time(0,  (int64_t)5.5*NSEC_PER_SEC);
    time_a     = dispatch_time(0,   6*NSEC_PER_SEC);
    time_a_max = dispatch_time(0,  (int64_t)6.5*NSEC_PER_SEC);
    dispatch_after_f(time_a, dispatch_get_current_queue(), NULL, func_a);
}
示例#3
0
static void dispatch_start(void* context) {
    dispatch_time_t time_a;
    time_delta_t* delta = (time_delta_t*)malloc(sizeof(time_delta_t));
    delta->min = dispatch_time(0,  NSEC_PER_SEC*5.5);
    time_a     = dispatch_time(0,  NSEC_PER_SEC*6.0);
    delta->max = dispatch_time(0,  NSEC_PER_SEC*6.5);
    delta->start = dispatch_time(0,0);
    dispatch_after_f(time_a, dispatch_get_current_queue(), delta, dispatch_6);
}
示例#4
0
文件: gcd.c 项目: JosephKu/MacRuby
/* 
 *  call-seq:
 *    gcdq.after(delay) { block }
 *
 *  Runs the passed block after the given delay (in seconds) using
 *  dispatch_after(3)[http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man3/dispatch_after.3.html],
 *  
 *     gcdq.after(0.5) { puts 'wait is over :)' }
 *
 */
static VALUE
rb_queue_dispatch_after(VALUE self, SEL sel, VALUE delay)
{
    dispatch_time_t offset = NIL_P(delay) ? DISPATCH_TIME_NOW : rb_num2timeout(delay);
    rb_vm_block_t *block = get_prepared_block();
    dispatch_after_f(offset, RQueue(self)->queue, (void *)block,
	    rb_block_dispatcher);

    return Qnil;
}
示例#5
0
void
func_a(void* context)
{
    dispatch_time_t now_a = dispatch_time(0, 0);
    UNREFERENCED_PARAMETER(context);
    test_time_less_than("can't finish faster than 5.5s", 0, now_a - time_a_min);
    test_time_less_than("must finish faster than  6.5s", 0, time_a_max - now_a);

    time_b_min = dispatch_time(0,  (int64_t)1.5*NSEC_PER_SEC);
    time_b     = dispatch_time(0,    2*NSEC_PER_SEC);
    time_b_max = dispatch_time(0,  (int64_t)2.5*NSEC_PER_SEC);
    dispatch_after_f(time_b, dispatch_get_current_queue(), NULL, func_b);
}
static void collect(void *context)
{
	
	MU_MESSAGE("All workers done.");

	// give the threads some time to settle before test_stop() runs "leaks"
	// ...also note, this is a total cheat.   dispatch_after lets this
	// thread go idle, so dispatch cleans up the continuations cache.
	// Doign the "old style" sleep left that stuff around and leaks
    // took a LONG TIME to complete. Long enough that the test harness
	// decided to kill us.
	dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), NULL, MU_PASS_AFTER_DELAY);
}
示例#7
0
static void dispatch_6(void* context) {
    dispatch_time_t time_b;
    time_delta_t* previous = (time_delta_t*)context;
    time_delta_t* delta = (time_delta_t*)malloc(sizeof(time_delta_t));
    dispatch_time_t now_a = dispatch_time(0, 0);
    MU_MESSAGE("must finish between 5.5s and 6.5s: %f",(now_a-previous->start)/(float)NSEC_PER_SEC);
    MU_ASSERT_TRUE(0<=(now_a - previous->min));
    MU_ASSERT_TRUE(0<=(previous->max - now_a));

    delta->min = dispatch_time(0,  1.5*NSEC_PER_SEC);
    time_b = dispatch_time(0,    2*NSEC_PER_SEC);
    delta->max = dispatch_time(0,  2.5*NSEC_PER_SEC);
    delta->start = dispatch_time(0,0);
    dispatch_after_f(time_b, dispatch_get_current_queue(), delta, dispatch_2);
}
示例#8
0
void
rwsched_dispatch_after_f(rwsched_tasklet_ptr_t sched_tasklet,
                         dispatch_time_t when,
                         rwsched_dispatch_queue_t queue,
                         void *context,
                         dispatch_function_t handler)
{
  // Validate input paraemters
  RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t);
  rwsched_instance_ptr_t instance = sched_tasklet->instance;
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);
  RW_ASSERT_TYPE(queue, rwsched_dispatch_queue_t);

  // If libdispatch is enabled for the entire instance, then call the libdispatch routine
  if (instance->use_libdispatch_only) {
    RW_ASSERT(queue->header.libdispatch_object._dq);
    if (queue == instance->main_rwqueue &&
        sched_tasklet->blocking_mode.blocked) {
      //RW_CRASH();
      rwsched_dispatch_what_ptr_t what = (rwsched_dispatch_what_ptr_t) RW_MALLOC0_TYPE(sizeof(*what), rwsched_dispatch_what_ptr_t); /* always leaked! */
      what->type = RWSCHED_DISPATCH_ASYNC;
      what->closure.handler = handler;
      what->closure.context = context;
      what->queue = queue;
      g_array_append_val(sched_tasklet->dispatch_what_array, what);
    }
    else {
      rwsched_dispatch_what_ptr_t what = (rwsched_dispatch_what_ptr_t) RW_MALLOC0_TYPE(sizeof(*what), rwsched_dispatch_what_ptr_t);
      what->type = RWSCHED_DISPATCH_ASYNC;
      what->closure.handler = handler;
      what->closure.context = context;
      what->queue = queue;
      rwsched_tasklet_ref(sched_tasklet);
      what->tasklet_info = sched_tasklet;
      dispatch_after_f(when, queue->header.libdispatch_object._dq, (void*)what, rwsched_dispatch_intercept);
    }
    return;
  }

  // Not yet implemented
  RW_CRASH();
}
static void
		collect(void *context)
{
	uint64_t delta;
	long double math;
	size_t i;

	if (--count_down) {
		return;
	}

	delta = dispatch_time(0,0) - start;
	math = (long double)delta;
	math /= COUNT * COUNT * 2ul + COUNT * 2ul;

	MU_MESSAGE("lap: %ld", lap_count_down);
	MU_MESSAGE("count: %lu", COUNT);
	MU_MESSAGE("delta: %llu ns", (uintmax_t)delta);
	MU_MESSAGE("math: %Lf ns / lap", math);

	for (i = 0; i < COUNT; i++) {
		dispatch_release(queues[i]);
	}

	// our malloc could be a lot better,
	// this result is really a malloc torture test
	MU_ASSERT_TRUE((unsigned long)math<10000);

	if (--lap_count_down) {
		do_test();
		return;
	}

	// give the threads some time to settle before test_stop() runs "leaks"
	// ...also note, this is a total cheat.   dispatch_after lets this
	// thread go idle, so dispatch cleans up the continuations cache.
	// Doign the "old style" sleep left that stuff around and leaks
	// took a LONG TIME to complete.   Long enough that the test harness
	// decided to kill us.
	dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), NULL, MU_PASS_AFTER_DELAY);
}
示例#10
0
static void
fd_tcpinfo_carbon_tick(void *arg)
{
	struct carbon_ctx *ctx = arg;
	dispatch_time_t milestone;
	struct tcp_info i = {0};
	struct tcp_info *info = &i;

	if (ctx->fd < 0) {
		printf("noconn\n");
		goto resched;
	}

	if (fd_tcpinfo(ctx->fd, info) == 0) {
		time_t ts;
		time(&ts);

		const char *qname = dispatch_queue_get_label(ctx->queue);
		char label[1024];

		snprintf(label, sizeof(label), "%s.rtt", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_rttcur, ts);

		snprintf(label, sizeof(label), "%s.rxpackets", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_rxpackets, ts);

		snprintf(label, sizeof(label), "%s.txpackets", qname);
		carbon_dispatch(ctx->queue, ctx->io, label, info->tcpi_txpackets, ts);

		printf("%s rtt: %u rxpackets: %llu txpackets: %llu\n", qname, info->tcpi_rttcur, info->tcpi_rxpackets, info->tcpi_txpackets);
	} else {
		perror("getsockopt");
	}

resched:
	milestone = dispatch_time(DISPATCH_TIME_NOW, T_TIMEOUT);
	dispatch_after_f(milestone, ctx->queue, ctx, fd_tcpinfo_carbon_tick);
}
示例#11
0
void WorkQueue::dispatchAfterDelay(const Function<void()>& function, double delay)
{
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);

    dispatch_after_f(delayTime, m_dispatchQueue, new Function<void()>(function), executeFunction);
}
示例#12
0
void WorkQueue::scheduleWorkAfterDelay(PassOwnPtr<WorkItem> item, double delay)
{
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);

    dispatch_after_f(delayTime, m_dispatchQueue, item.leakPtr(), executeWorkItem);
}