示例#1
0
int main(){
    dispatch_queue_t logQueue = dispatch_queue_create("logging file access queue", DISPATCH_QUEUE_SERIAL);
    dispatch_queue_t workQueue = dispatch_queue_create("concurrent work queue", DISPATCH_QUEUE_CONCURRENT);
    
    dispatch_block_t logRequest = ^{  
        logData:
        /* write request meta data on the log */; };
        
    dispatch_block_t handleRendering = ^{  
        while(NONDETERMINISTIC){
            /* do some heavy rendering computations */
            dispatch_async(logQueue, logRequest);
        } };
        
    dispatch_block_t handleFileStorage = ^{  
        storeFile: /*  store file */
        dispatch_async(logQueue, logRequest);
        storage_system_busy = 0; };

    while(1){
        if(storage_system_busy == 0 && NONDETERMINISTIC){ 
            assert(storage_system_busy == 0); // check for possible race conditions
            storage_system_busy = 1;
            dispatch_async(workQueue, handleFileStorage);
        } else if(NONDETERMINISTIC){
            dispatch_async(workQueue, handleRendering);
        }
    }

    return 0;
}
示例#2
0
TCController::TCController(TCConfig *_config) :
	config(_config),
	running(false)
{
	// Retain config
	_config->retain();
	
	// Init vars
	mstatus = tccontroller_available;
	running = false;
	socketAccept = 0;
	
	nQueue = 0;
	nBlock = NULL;
	
	buddiesLoaded = false;
	
	timer = 0;
	
	// Get profile avatar
	pavatar = config->get_profile_avatar();
	
	if (!pavatar)
		pavatar = new TCImage(64, 64);
	
	// Get profile name & text
	pname = new TCString(config->get_profile_name());
	ptext = new TCString(config->get_profile_text());
	
	// Alloc queue
	mainQueue = dispatch_queue_create("com.torchat.core.controller.main", DISPATCH_QUEUE_SERIAL);
	socketQueue = dispatch_queue_create("com.torchat.core.controller.socket", DISPATCH_QUEUE_SERIAL);
}
示例#3
0
void Syslog(char *udid)
{
	operatingQueue = dispatch_queue_create("com.samdmarshall.mobile.syslog.operations", DISPATCH_QUEUE_SERIAL);
	updatelogQueue = dispatch_queue_create("com.samdmarshall.mobile.syslog.updatelog", DISPATCH_QUEUE_SERIAL);
	AttachToSyslog(udid);
	PrintSysLog();
}
示例#4
0
文件: server.c 项目: Henauxg/minix
static void
init_globals(void)
{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
	timerq = dispatch_queue_create("hiem-sipc-timer-q", NULL);
        timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timerq);
	dispatch_source_set_event_handler(timer, ^{ timer_ev(); } );

	workq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
	eventq = dispatch_queue_create("heim-ipc.event-queue", NULL);
    });
void CAPlayThroughHost::CreatePlayThrough(AudioDeviceID input, AudioDeviceID output)
{
	mPlayThrough = new CAPlayThrough(input, output);
    StreamListenerQueue = dispatch_queue_create("com.CAPlayThough.StreamListenerQueue", DISPATCH_QUEUE_SERIAL);
    //if (StreamListenerQueue) dispatch_set_context(StreamListenerQueue, this);
	AddDeviceListeners(input);
}
示例#6
0
void
IOPowerWatcher::setupDarkWake()
{
    IOReturn            ret;
    
    mInDarkWake = false;

    mIOPMqueue = dispatch_queue_create("com.apple.security.IOPowerWatcher", NULL);
    if (mIOPMqueue == NULL)
	return;

    ret = ::IOPMConnectionCreate(CFSTR("IOPowerWatcher"),
				 kIOPMSystemPowerStateCapabilityDisk 
				 | kIOPMSystemPowerStateCapabilityNetwork
				 | kIOPMSystemPowerStateCapabilityAudio 
				 | kIOPMSystemPowerStateCapabilityVideo,
				 &mIOPMconn);
    if (ret != kIOReturnSuccess)
	return;
	
    ret = ::IOPMConnectionSetNotification(mIOPMconn, this,
					  (IOPMEventHandlerType)iopmcallback);
    if (ret != kIOReturnSuccess)
	return;

    ::IOPMConnectionSetDispatchQueue(mIOPMconn, mIOPMqueue);
}
示例#7
0
rwsched_dispatch_queue_t
rwsched_dispatch_queue_create(rwsched_tasklet_ptr_t sched_tasklet,
                              const char *label,
                              dispatch_queue_attr_t attr)
{
  struct rwsched_dispatch_queue_s *queue;

  // 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);

  // Allocate memory for the dispatch queue
  queue = (rwsched_dispatch_queue_t) RW_MALLOC0_TYPE(sizeof(*queue), rwsched_dispatch_queue_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) {
    queue->header.libdispatch_object._dq = dispatch_queue_create(label, attr);
    RW_ASSERT(queue->header.libdispatch_object._dq);

    rwsched_tasklet_ref(sched_tasklet);
    ck_pr_inc_32(&sched_tasklet->counters.queues);

    return queue;
  }

  // Not yet implemented
  RW_CRASH();
  return NULL;
}
示例#8
0
int
mdns_init(void)
{
  DPRINTF(E_DBG, L_MDNS, "Initializing Avahi mDNS\n");

  all_w = NULL;
  all_t = NULL;
  group_entries = NULL;
  browser_list = NULL;

  mdns_sq = dispatch_queue_create("org.forked-daapd.mdns", NULL);
  if (!mdns_sq)
    {
      DPRINTF(E_FATAL, L_MDNS, "mdns_init: Could not create dispatch queue\n");
      return -1;
    }

  dispatch_sync_f(mdns_sq, NULL, mdns_init_task);

  if (!mdns_client)
    goto client_fail;

  return 0;

 client_fail:
  dispatch_release(mdns_sq);

  return -1;
}
示例#9
0
文件: vsys.c 项目: stiartsly/eCamera
static
dispatch_queue_t timer_manager_queue() {
    static dispatch_queue_t timer_manager_queue;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        timer_manager_queue = dispatch_queue_create("com.elastos.cloud.ecdev", DISPATCH_QUEUE_SERIAL);
    });
示例#10
0
static void do_test(void)
{
	size_t i;
	char buf[1000];

	count_down = COUNT;

	start = dispatch_time(0,0);

	for (i = 0; i < COUNT; i++) {
#ifdef WIN32
		_snprintf(buf, sizeof(buf), "com.example.starfish-node#%ld", i);
#else
		snprintf(buf, sizeof(buf), "com.example.starfish-node#%ld", (long int)i);
#endif
		queues[i] = dispatch_queue_create(buf, NULL);
		dispatch_suspend(queues[i]);
	}

	for (i = 0; i < COUNT; i++) {
		dispatch_async_f(queues[i], queues[i], start_node);
	}

	for (i = 0; i < COUNT; i++) {
		dispatch_resume(queues[i]);
	}
}
示例#11
0
CF_INLINE void LOCKED(dispatch_block_t work) {
    static dispatch_once_t guard;
    static dispatch_queue_t CFUUIDGlobalDataLock;
    dispatch_once(&guard, ^{
        dispatch_queue_attr_t dqattr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, qos_class_main(), 0);
        CFUUIDGlobalDataLock = dispatch_queue_create("com.apple.CFUUID", dqattr);
    });
示例#12
0
char *
Digest_File(CCDigestAlg algorithm, const char *filename, char *buf)
{
	int fd;
	__block CCDigestCtx ctx;
	dispatch_queue_t queue;
	dispatch_semaphore_t sema;
	dispatch_io_t io;
	__block int s_error = 0;

	/* dispatch_io_create_with_path requires an absolute path */
	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		return NULL;
	}

	(void)fcntl(fd, F_NOCACHE, 1);

	(void)osx_assumes_zero(CCDigestInit(algorithm, &ctx));

	queue = dispatch_queue_create("com.apple.mtree.io", NULL);
	osx_assert(queue);
	sema = dispatch_semaphore_create(0);
	osx_assert(sema);

	io = dispatch_io_create(DISPATCH_IO_STREAM, fd, queue, ^(int error) {
		if (error != 0) {
			s_error = error; 
		}
		(void)close(fd);
		(void)dispatch_semaphore_signal(sema);
	});
static void do_test(void)
{
	size_t i;
	char buf[1000];
	dispatch_group_t g = dispatch_group_create();

	for (i = 0; i < QUEUES; i++) {
#ifdef WIN32
		_snprintf(buf, sizeof(buf), "com.example.memoryload-node#%ld", i);
#else
		snprintf(buf, sizeof(buf), "com.example.memoryload-node#%ld", (long int)i);
#endif
		queues[i] = dispatch_queue_create(buf, NULL);
		dispatch_suspend(queues[i]);
	}

	for (i = 0; i < QUEUES; i++) {
		dispatch_group_async_f(g, queues[i], g, start_node);
	}

	dispatch_group_notify_f(g, dispatch_get_main_queue(), NULL, collect);

	for (i = 0; i < QUEUES; i++) {
		dispatch_resume(queues[i]);
		dispatch_release(queues[i]);
	}
}
示例#14
0
static dispatch_queue_t _CFMachPortQueue() {
    static volatile dispatch_queue_t __CFMachPortQueue = NULL;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dispatch_queue_attr_t dqattr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_BACKGROUND, 0);
        __CFMachPortQueue = dispatch_queue_create("com.apple.CFMachPort", dqattr);
    });
示例#15
0
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();
}
示例#16
0
USBMuxAgentRef USBMuxAgentCreate() {
	USBMuxAgentRef agent = (USBMuxAgentRef)calloc(1, sizeof(struct USBMuxAgentClass));
	agent->socket = -1;
	agent->isActive = false;
	agent->socketQueue = dispatch_queue_create("com.samdmarshall.sdm_usbmux.socketQueue", NULL);
	return agent;
}
示例#17
0
AudioUnitALSA::AudioUnitALSA(int cardIndex, char* cardName)
    : m_cardIndex(cardIndex), m_cardName(cardName), m_pcmOutput(nullptr), m_pcmInput(nullptr)
{
    static dispatch_once_t pred;
    dispatch_once(&pred, ^ {
        g_audioQueue = dispatch_queue_create("org.darlinghw.audiounit", nullptr);
    });
示例#18
0
/* Called when a new client connects */
BOOL mf_peer_init(freerdp_peer* client)
{
	client->ContextSize = sizeof(mfPeerContext);
	client->ContextNew = (psPeerContextNew) mf_peer_context_new;
	client->ContextFree = (psPeerContextFree) mf_peer_context_free;

	if (!freerdp_peer_context_new(client))
		return FALSE;
	
	info_event_queue = mf_event_queue_new();
	
	info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL);
	info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue);
	
	if(info_timer)
	{
		//DEBUG_WARN( "created timer\n");
		dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC);
		dispatch_source_set_event_handler(info_timer, ^{
			//DEBUG_WARN( "dispatch\n");
			mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK);
			mf_event_push(info_event_queue, (mfEvent*) event);}
						  );
		dispatch_resume(info_timer);
	}
示例#19
0
CAMLprim value
caml_init_vmnet(value v_mode)
{
  CAMLparam1(v_mode);
  CAMLlocal3(v_iface_ref,v_res,v_mac);
  xpc_object_t interface_desc = xpc_dictionary_create(NULL, NULL, 0);
  xpc_dictionary_set_uint64(interface_desc, vmnet_operation_mode_key, Int_val(v_mode));
  uuid_t uuid;
  uuid_generate_random(uuid);
  xpc_dictionary_set_uuid(interface_desc, vmnet_interface_id_key, uuid);
  __block interface_ref iface = NULL;
  __block vmnet_return_t iface_status = 0;
  __block unsigned char *mac = malloc(6);
  if (!mac) caml_raise_out_of_memory ();
  __block unsigned int mtu = 0;
  __block unsigned int max_packet_size = 0;
  dispatch_queue_t if_create_q = dispatch_queue_create("org.openmirage.vmnet.create", DISPATCH_QUEUE_SERIAL);
  dispatch_semaphore_t iface_created = dispatch_semaphore_create(0);
  iface = vmnet_start_interface(interface_desc, if_create_q,
    ^(vmnet_return_t status, xpc_object_t interface_param) { 
      iface_status = status;
      if (status != VMNET_SUCCESS || !interface_param) {
         dispatch_semaphore_signal(iface_created);
         return;
      }
      //printf("mac desc: %s\n", xpc_copy_description(xpc_dictionary_get_value(interface_param, vmnet_mac_address_key)));
      const char *macStr = xpc_dictionary_get_string(interface_param, vmnet_mac_address_key);
      unsigned char lmac[6];
      if (sscanf(macStr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &lmac[0], &lmac[1], &lmac[2], &lmac[3], &lmac[4], &lmac[5]) != 6)
        errx(1, "Unexpected MAC address received from vmnet");
      memcpy(mac, lmac, 6);
      mtu = xpc_dictionary_get_uint64(interface_param, vmnet_mtu_key);
      max_packet_size = xpc_dictionary_get_uint64(interface_param, vmnet_max_packet_size_key);
      dispatch_semaphore_signal(iface_created);
    });
示例#20
0
SDMMD_AFCConnectionRef SDMMD_AFCConnectionCreate(SDMMD_AMConnectionRef conn) {
	SDMMD_AFCConnectionRef afc = calloc(1, sizeof(struct sdmmd_AFCConnectionClass));
	afc->handle = conn;
	CFStringRef name = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%s.%s.%s"), "com.samdmarshall.sdmmobiledevice.afc", SDMCFStringGetString((conn->ivars.device)->ivars.unique_device_id), SDMCFStringGetString(SDMGetCurrentDateString()));
	afc->operationQueue = dispatch_queue_create(SDMCFStringGetString(name), NULL);
	afc->operationCount = 0;
	return afc;
}
示例#21
0
queue::queue (
    const char *label
)
    : m_native( dispatch_queue_create( label, NULL ) ),
      m_label( label )
{
    XDISPATCH_ASSERT( m_native );
}
示例#22
0
文件: Noble.cpp 项目: phated/noble
void Noble::setupXpcConnection() {
  this->dispatchQueue = dispatch_queue_create("com.apple.blued", 0);
  this->xpcConnnection = xpc_connection_create_mach_service("com.apple.blued", this->dispatchQueue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);

  xpc_connection_set_event_handler(this->xpcConnnection, ^(xpc_object_t event) {
    xpc_retain(event);
    this->handleXpcEvent(event);
  });
示例#23
0
CIMIClassicView::CIMIClassicView()
    : CIMIView(), m_cursorFrIdx(0), m_candiFrIdx(0),
      m_candiPageFirst(0)
#if __APPLE__
    , m_workqueue(dispatch_queue_create("com.sunpinyin.workq", 0))
#endif
{
}
示例#24
0
ResourceHandleCFURLConnectionDelegateWithOperationQueue::ResourceHandleCFURLConnectionDelegateWithOperationQueue(ResourceHandle* handle)
    : ResourceHandleCFURLConnectionDelegate(handle)
    , m_queue(dispatch_queue_create("com.apple.WebCore/CFNetwork", DISPATCH_QUEUE_SERIAL))
    , m_semaphore(dispatch_semaphore_create(0))
{
    dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
    dispatch_set_target_queue(m_queue, backgroundQueue);
}
示例#25
0
queue::queue (
    const std::string &label
)
    : m_native( dispatch_queue_create( label.c_str(), NULL ) ),
      m_label( label )
{
    XDISPATCH_ASSERT( m_native );
}
示例#26
0
void* InvokeDispatch(int n)
{
    static int dummy = 0;
    static dispatch_queue_t queue = NULL;
    if (NULL == queue) queue = dispatch_queue_create("com.apple.gcd.examples.compare.invoke", NULL);
    dispatch_suspend(queue);
    for (int i = 0; i < n; i++) {
        dispatch_async(queue, ^{ dummy = i; }); // Assign variable to avoid over-optimization
    }
static dispatch_queue_t
_dnsinfo_server_queue()
{
	static dispatch_once_t	once;
	static dispatch_queue_t	q;

	dispatch_once(&once, ^{
		q = dispatch_queue_create(DNSINFO_SERVICE_NAME ".server", NULL);
	});
static void tests() {

    SecKeychainRef kc = getPopulatedTestKeychain();

    static dispatch_once_t onceToken = 0;
    static dispatch_queue_t release_queue = NULL;
    dispatch_once(&onceToken, ^{
        release_queue = dispatch_queue_create("com.apple.security.identity-search-queue", DISPATCH_QUEUE_CONCURRENT);
    });
static dispatch_queue_t
_reach_requests_rbt_queue()
{
	static dispatch_once_t	once;
	static dispatch_queue_t	q;

	dispatch_once(&once, ^{
		q = dispatch_queue_create(REACH_SERVICE_NAME ".requests.rbt", NULL);
	});
void XpcConnection::setup() {
  this->dispatchQueue = dispatch_queue_create(this->serviceName.c_str(), 0);
  this->xpcConnnection = xpc_connection_create_mach_service(this->serviceName.c_str(), this->dispatchQueue, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);

  xpc_connection_set_event_handler(this->xpcConnnection, ^(xpc_object_t event) {
    xpc_retain(event);
//    NSLog(@"event = %@", event);
    this->handleEvent(event);
  });