当前位置: 首页>>代码示例>>C++>>正文


C++ dispatch_get_global_queue函数代码示例

本文整理汇总了C++中dispatch_get_global_queue函数的典型用法代码示例。如果您正苦于以下问题:C++ dispatch_get_global_queue函数的具体用法?C++ dispatch_get_global_queue怎么用?C++ dispatch_get_global_queue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dispatch_get_global_queue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Qt_dispatch_source_signal_lambda

extern "C" void Qt_dispatch_source_signal_lambda(){
    char argv[] = "test";
    int argc = 1;
    QDispatchApplication app(argc, (char**)&argv);

        MU_BEGIN_TEST(Qt_dispatch_source_signal_lambda);

    EmitterLambda object;

	// configure the source
	QDispatchSource src(new QDispatchSourceTypeSignal(&object, SIGNAL(ready())));
    src.setTargetQueue(QDispatch::globalQueue(QDispatch::LOW));
	src.setHandler([=]{
		MU_MESSAGE("Signal was emitted");
		if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0))
			MU_MESSAGE("Executed on low global queue");
		else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0))
			MU_MESSAGE("Executed on default global queue");
		else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0))
			MU_MESSAGE("Executed on high global queue");
		else if(QDispatch::currentQueue().native() == dispatch_get_main_queue())
			MU_MESSAGE("Executed on main queue");
		MU_ASSERT_EQUAL_HEX(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), QDispatch::currentQueue().native());
		MU_PASS("");
	});

	// trigger the signal
	object.notify();

	app.exec();
	MU_END_TEST;
}
开发者ID:digiverse,项目名称:cool,代码行数:32,代码来源:Qt_dispatch_source_signal_lambda.cpp

示例2: test_io_close

static void
test_io_close(int with_timer, bool from_path)
{
	#define chunks 4
	#define READSIZE (512*1024)
	unsigned int i;
	const char *path = LARGE_FILE;
	int fd = open(path, O_RDONLY);
	if (fd == -1) {
		if (errno == ENOENT) {
			test_skip("Large file not found");
			return;
		}
		test_errno("open", errno, 0);
		test_stop();
	}
#ifdef F_GLOBAL_NOCACHE
	if (fcntl(fd, F_GLOBAL_NOCACHE, 1) == -1) {
		test_errno("fcntl F_GLOBAL_NOCACHE", errno, 0);
		test_stop();
	}
#endif
	struct stat sb;
	if (fstat(fd, &sb)) {
		test_errno("fstat", errno, 0);
		test_stop();
	}
	const size_t size = (size_t)sb.st_size / chunks;
	const int expected_error = with_timer? ECANCELED : 0;
	dispatch_source_t t = NULL;
	dispatch_group_t g = dispatch_group_create();
	dispatch_group_enter(g);
	void (^cleanup_handler)(int error) = ^(int error) {
		test_errno("create error", error, 0);
		dispatch_group_leave(g);
		close(fd);
	};
	dispatch_io_t io;
	if (!from_path) {
		io = dispatch_io_create(DISPATCH_IO_RANDOM, fd,
				dispatch_get_global_queue(0, 0), cleanup_handler);
	} else {
#if DISPATCHTEST_IO_PATH
		io = dispatch_io_create_with_path(DISPATCH_IO_RANDOM, path, O_RDONLY, 0,
				dispatch_get_global_queue(0, 0), cleanup_handler);
#endif
	}
	dispatch_io_set_high_water(io, READSIZE);
	if (with_timer == 1) {
		dispatch_io_set_low_water(io, READSIZE);
		dispatch_io_set_interval(io,  2 * NSEC_PER_SEC,
				DISPATCH_IO_STRICT_INTERVAL);
	} else if (with_timer == 2) {
		t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
				dispatch_get_global_queue(0,0));
		dispatch_retain(io);
		dispatch_source_set_event_handler(t, ^{
			dispatch_io_close(io, DISPATCH_IO_STOP);
			dispatch_source_cancel(t);
		});
开发者ID:helje5,项目名称:swift-corelibs-libdispatch,代码行数:60,代码来源:dispatch_io.c

示例3: main

int
main()
{
	dispatch_queue_t q[PRIORITIES];
	int i;

#if USE_SET_TARGET_QUEUE
	test_start("Dispatch Priority (Set Target Queue)");
	for(i = 0; i < PRIORITIES; i++) {
		q[i] = dispatch_queue_create(labels[i], NULL);
		test_ptr_notnull("q[i]", q[i]);
		assert(q[i]);
		dispatch_set_target_queue(as_do(q[i]), dispatch_get_global_queue(priorities[i], 0));
		dispatch_queue_set_width(q[i], DISPATCH_QUEUE_WIDTH_MAX_LOGICAL_CPUS); 
	}
#else
	test_start("Dispatch Priority");
	for(i = 0; i < PRIORITIES; i++) {
		q[i] = dispatch_get_global_queue(priorities[i], 0);
	}
#endif
	
	for(i = 0; i < PRIORITIES; i++) {
		submit_work(q[i], &counts[i].count);
	}

	dispatch_main();
}
开发者ID:DrPizza,项目名称:libdispatch,代码行数:28,代码来源:dispatch_priority.c

示例4: CFSocketFinalize

static void
CFSocketFinalize (CFTypeRef cf)
{
  CFSocketRef s = (CFSocketRef)cf;
  
#if HAVE_LIBDISPATCH
  dispatch_queue_t q = dispatch_get_global_queue(
              DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  dispatch_source_cancel(s->_readSource);
  dispatch_source_cancel(s->_writeSource);
  
  // Wait for source handlers to complete
  // before we proceed to destruction.
  dispatch_barrier_sync_f(q, NULL, DummyBarrier);
  
  if (s->_source != NULL)
    CFRelease(s->_source);
#endif
  
  if (s->_socket != -1)
    {
      GSMutexLock (&_kCFSocketObjectsLock);
      CFDictionaryRemoveValue(_kCFSocketObjects,
                              (void*)(uintptr_t) s->_socket);
      closesocket (s->_socket);
      GSMutexUnlock (&_kCFSocketObjectsLock);
    }
  if (s->_address)
    CFRelease (s->_address);
  if (s->_peerAddress)
    CFRelease (s->_peerAddress);
}
开发者ID:1053948334,项目名称:myos.frameworks,代码行数:32,代码来源:CFSocket.c

示例5: mrb_queue_concurrent

static mrb_value
mrb_queue_concurrent(mrb_state *mrb, mrb_value self)
{
  mrb_value instance;
  mrb_sym priority;
  long priority_value;
  dispatch_queue_t q;

  mrb_get_args(mrb, "|n", &priority);
  if (priority == mrb_intern_cstr(mrb, "high")) {
    priority_value = DISPATCH_QUEUE_PRIORITY_HIGH;
  }
  else if (priority == mrb_intern_cstr(mrb, "low")) {
    priority_value = DISPATCH_QUEUE_PRIORITY_LOW;
  }
#ifdef DISPATCH_QUEUE_PRIORITY_BACKGROUND
  else if (priority == mrb_intern_cstr(mrb, "background")) {
    priority_value = DISPATCH_QUEUE_PRIORITY_BACKGROUND;
  }
#endif
  else {
    priority_value = DISPATCH_QUEUE_PRIORITY_DEFAULT;
  }

  instance = mrb_queue_create_instance(mrb);

  q = dispatch_get_global_queue(priority_value, 0);

  return mrb_queue_set_queue(instance, q);
}
开发者ID:dorentus,项目名称:mruby-dispatch,代码行数:30,代码来源:queue.c

示例6: halide_do_par_for

WEAK void halide_do_par_for(void (*f)(int, uint8_t *), int min, int size, uint8_t *closure) {
    halide_gcd_job job;
    job.f = f;
    job.closure = closure;
    job.min = min;   
    dispatch_apply_f(size, dispatch_get_global_queue(0, 0), &job, &halide_do_gcd_task);
}
开发者ID:hirokai,项目名称:Halide,代码行数:7,代码来源:gcd_thread_pool.cpp

示例7: tests

static void tests(void)
{
//    CFStringRef messageToUser = CFSTR("OK to sync with world?");
//    CFStringRef messageToUser = CFSTR("Allow “Emily‘s iPad to use your iCloud Keychain?");
#if !TARGET_IPHONE_SIMULATOR
#if TARGET_OS_EMBEDDED
    CFStringRef our_peer_id = (CFStringRef)MGCopyAnswer(kMGQUserAssignedDeviceName, NULL);
#else
    CFStringRef our_peer_id = CFSTR("🔥💩");
#endif
#else
    CFStringRef our_peer_id = CFSTR("Emily‘s iPad");
#endif

    CFStringRef messageToUser = CFStringCreateWithFormat(kCFAllocatorDefault, 0, CFSTR("Allow “%@” to use your iCloud Keychain?"), our_peer_id);
    dispatch_queue_t processQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t work_group = dispatch_group_create();

    // Prep the group for exitting the whole shebang.
    dispatch_group_enter(work_group);
    dispatch_group_notify(work_group, processQueue, ^
        {
            printf("Exiting via dispatch_group_notify; all work done\n");
            CFRunLoopStop(CFRunLoopGetMain());
        //  exit(0);
        });
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:26,代码来源:sc-102-cfusernotification.c

示例8: kcm_session_setup_handler

void
kcm_session_setup_handler(void)
{
#ifdef __APPLE__
    au_sdev_handle_t *h;
    dispatch_queue_t bgq;

    h = au_sdev_open(AU_SDEVF_ALLSESSIONS);
    if (h == NULL)
	return;

    bgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);

    dispatch_async(bgq, ^{
	    for (;;) {
		auditinfo_addr_t aio;
		int event;
	
		if (au_sdev_read_aia(h, &event, &aio) != 0)
		    continue;

		/* 
		 * Ignore everything but END. This should relly be
		 * CLOSE but since that is delayed until the credential
		 * is reused, we can't do that 
		 * */
		if (event != AUE_SESSION_END)
		    continue;
		
		dispatch_async(dispatch_get_main_queue(), ^{
			kcm_cache_remove_session(aio.ai_asid);
		    });
	    }
	});
开发者ID:alexzhang2015,项目名称:osx-10.9,代码行数:34,代码来源:sessions.c

示例9: test_dispatch_latency

void test_dispatch_latency(unsigned samples, unsigned sleeptime)
{
    unsigned i;

    uint64_t *lat = (uint64_t *)malloc(sizeof(uint64_t) * 3);
    uint64_t *history = (uint64_t *)malloc(sizeof(uint64_t) * samples);

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();

    for (i = 0; i < samples; i++) {
        usleep(sleeptime);

        /*
         lat[0] to lat[1] is latency to block execution
         lat[1] to lat[2] is latency from block execution to block synchronization
         */
        lat[0] = libtime_cpu();
        dispatch_group_async(group, queue, ^{ lat[1] = libtime_cpu(); });
        dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
        lat[2] = libtime_cpu();

        /*
        printf("%04u lat[0] = %" PRIu64 "\n", i, lat[0]);
        printf("%04u lat[1] = %" PRIu64 ", %" PRIu64 "\n", i, lat[1], lat[1] - lat[0]);
        printf("%04u lat[2] = %" PRIu64 ", %" PRIu64 "\n", i, lat[2], lat[2] - lat[1]);
        */

        history[i] = lat[1] - lat[0];
        //history[i] = lat[2] - lat[1];
    }
开发者ID:tycho,项目名称:microbench,代码行数:31,代码来源:main.c

示例10: cancelTimerSource

void RequestTimer::setTimeout(int seconds) {
  m_timeoutSeconds = seconds > 0 ? seconds : 0;

  cancelTimerSource();

  if (!m_timeoutSeconds) {
    return;
  }

  dispatch_queue_t q =
    dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  m_timerSource = dispatch_source_create(
    DISPATCH_SOURCE_TYPE_TIMER, 0, DISPATCH_TIMER_STRICT, q);

  dispatch_time_t t =
    dispatch_time(DISPATCH_TIME_NOW, m_timeoutSeconds * NSEC_PER_SEC);
  dispatch_source_set_timer(m_timerSource, t, DISPATCH_TIME_FOREVER, 0);

  // Use the timer group as a semaphore. When the source is cancelled,
  // libdispatch will make sure all pending event handlers have finished before
  // invoking the cancel handler. This means that if we cancel the source and
  // then wait on the timer group, when we are done waiting, we know the source
  // is completely done and it's safe to free memory (e.g., in the destructor).
  // See cancelTimerSource() above.
  dispatch_group_enter(m_timerGroup);
  dispatch_source_set_event_handler(m_timerSource, ^{
    onTimeout();

    // Cancelling ourselves isn't needed for correctness, but we can go ahead
    // and do it now instead of waiting on it later, so why not. (Also,
    // getRemainingTime does use this opportunistically, but it's best effort.)
    dispatch_source_cancel(m_timerSource);
  });
开发者ID:bd808,项目名称:hhvm,代码行数:33,代码来源:request-injection-data.cpp

示例11: distance

// Calculate distances with matrix/matrix operations (BLAS3)
void distance(int N, int D, float *data, float *result) {
	int blockSize = 512;
  int blockCount = N / blockSize;
  int remainder = N % blockSize;
  
  if (remainder) blockCount++; // Include the ragged edge
  
  dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  
	float *diag = (float *)malloc(sizeof(float) * N);
  float *C = (float *)malloc(blockCount * blockSize * blockSize * sizeof(float));
  
  dispatch_apply(blockCount, queue, ^(size_t m) {
    int i, j;
    
    int outerDim = blockSize;
    if (m == blockCount - 1 && remainder) outerDim = remainder;
    
    
    cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, outerDim, outerDim, D,
                1, &data[m * blockSize * D], D, &data[m * blockSize * D], D, 0,
                &C[m * blockSize * blockSize], outerDim);
    
    for(i = 0; i < outerDim; i++)
      diag[m * blockSize + i] = C[m * blockSize * blockSize + i * (outerDim + 1)];
    
    for(i = 0; i < outerDim; i++)
      for(j = i + 1; j < outerDim; j++)
        result[utndidx(i + m * blockSize, j + m * blockSize)] = \
        sqrt(diag[i + m * blockSize] + diag[j + m * blockSize] - \
             2 * C[m * blockSize * blockSize + j * outerDim + i]);
  });
开发者ID:abrahante,项目名称:divvy,代码行数:33,代码来源:distance.c

示例12: render

static void
render(unsigned char *img, int comps, int w, int h, int nsubsamples, int tilew, int tileh)
{

    float *fimg = (float *)malloc(sizeof(float) * w * h * 3);
    memset((void *)fimg, 0, sizeof(float) * w * h * 3);
    
    dispatch_queue_t dque = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    //dispatch_queue_t dque = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_group_t dgroup = dispatch_group_create();
    
    int i, j;
    for (j = 0; j < h; j += tileh) {
        for (i = 0; i < w; i += tilew) {

            void (^renderblock)(void) = ^{
                render_tile(img, comps, fimg, w, h, nsubsamples, i, j, tilew, tileh);
            };
            //renderblock();
            dispatch_group_async(dgroup, dque, renderblock);
        }
    }
    
    dispatch_group_wait(dgroup, DISPATCH_TIME_FOREVER);
    //dispatch_release(dgroup);
}
开发者ID:Pentan,项目名称:iaobenchCollection,代码行数:26,代码来源:aof_gcd.c

示例13: work3

void work3(void *(*f)(int))
{
    long count = 20;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);//dispatch_queue_create("com.mydomain.myapp.longrunningfunction", DISPATCH_QUEUE_CONCURRENT);
    //int *r = new int [count];//10000;
    //for(int i = 0; i < count; i++) r[i] = i;

    dispatch_apply(count, queue, ^(size_t i) {
        f(i);
    });
开发者ID:Daiver,项目名称:scripts,代码行数:10,代码来源:libpygcd.cpp

示例14: dispatch_api

void dispatch_api() {
    dispatch_queue_t q = NULL;

	MU_BEGIN_TEST(dispatch_api);

    q = dispatch_get_main_queue();
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_main_queue",q);
    dispatch_async_f(q, NULL, pass);

	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);
	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);
	q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0);
    MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q);

    dispatch_main();

	MU_END_TEST;
}
开发者ID:JackieXie168,项目名称:libdispatch,代码行数:20,代码来源:dispatch_api.c

示例15: mach_init

static int
mach_init(const char *service, void **ctx)
{
    struct mach_ctx *ipc;
    mach_port_t sport;
    int ret;

    dispatch_once(&jobqinited, ^{
	    jobq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
	    syncq = dispatch_queue_create("heim-ipc-syncq", NULL);
	});
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:11,代码来源:client.c


注:本文中的dispatch_get_global_queue函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。