Пример #1
0
static void
AtForkChild(void)
{
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    UNLOCK_NOTIFIER;
    UNLOCK_NOTIFIER_INIT;
    if (tsdPtr->runLoop) {
	tsdPtr->runLoop = NULL;
	if (!noCFafterFork) {
	    CFRunLoopSourceInvalidate(tsdPtr->runLoopSource);
	}
	CFRelease(tsdPtr->runLoopSource);
	tsdPtr->runLoopSource = NULL;
    }
    if (notifierCount > 0) {
	notifierCount = 0;

	/*
	 * Assume that the return value of Tcl_InitNotifier in the child will
	 * be identical to the one stored as clientData in tclNotify.c's
	 * ThreadSpecificData by the parent's TclInitNotifier, so discard the
	 * return value here. This assumption may require the fork() to be
	 * executed in the main thread of the parent, otherwise
	 * Tcl_AlertNotifier may break in the child.
	 */

	if (!noCFafterFork) {
	    Tcl_InitNotifier();
	}
    }
}
Пример #2
0
/*
	druBurn
	
	Called to do a burn.  Burning is a long async process, so this function mostly
	handles providing appropriate progress and completion information to the user.
*/
int
druBurn(DRBurnRef burn, CFTypeRef layout)
{
	DRNotificationCenterRef		notificationCenter = NULL;
	CFRunLoopSourceRef			source = NULL;
	druBurnStatus				status = {0, NULL, NULL, NULL, {0}, 0};
	
	/* Create a progress bar. */
	status.progressBar = druProgressBarCreate();
	
	/* Sign up for notifications from the burn object. */
	notificationCenter = DRNotificationCenterCreate();
	source = DRNotificationCenterCreateRunLoopSource(notificationCenter);
	CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
	DRNotificationCenterAddObserver(notificationCenter,&status,druProgressCallback, kDRBurnStatusChangedNotification, burn);
	
	/* Okay, kick off the burn. */
	DRBurnWriteLayout(burn, layout);
	
	/* Enter a runloop until the burn finishes. */
	CFRunLoopRun();
	
	/* Clean up memory and exit. */
	CFRunLoopSourceInvalidate(source);
	if (notificationCenter != NULL)	CFRelease(notificationCenter);
	if (source != NULL)				CFRelease(source);
	if (status.progressBar != NULL)	druProgressBarDispose(status.progressBar,status.success);
	if (status.success)
		printf("Burn completed.\n");
	else
		druPrintFailureMessage("Burn", status.completionStatus);
	if (status.completionStatus != NULL)	CFRelease(status.completionStatus);
	
	return status.success;
}
Пример #3
0
static void btstack_thread_func(void* data)
{
   RARCH_LOG("[BTstack]: Thread started");

   if (bt_open_ptr())
      return;

#ifdef __APPLE__
   CFRunLoopSourceContext ctx = { 0, 0, 0, 0, 0, 0, 0, 0, 0, btstack_thread_stop };
   btstack_quit_source = CFRunLoopSourceCreate(0, 0, &ctx);
   CFRunLoopAddSource(CFRunLoopGetCurrent(), btstack_quit_source, kCFRunLoopCommonModes);
#endif

   RARCH_LOG("[BTstack]: Turning on...\n");
   bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON);

   RARCH_LOG("BTstack: Thread running...\n");
#ifdef __APPLE__
   CFRunLoopRun();
#endif

   RARCH_LOG("[BTstack]: Thread done.\n");

#ifdef __APPLE__
   CFRunLoopSourceInvalidate(btstack_quit_source);
   CFRelease(btstack_quit_source);
#endif
}
Пример #4
0
void CFMessagePortInvalidate(CFMessagePortRef ms) {
    __CFGenericValidateType(ms, __kCFMessagePortTypeID);
    if (!__CFMessagePortIsDeallocing(ms)) {
	CFRetain(ms);
    }
    __CFMessagePortLock(ms);
    if (__CFMessagePortIsValid(ms)) {
	CFMessagePortInvalidationCallBack callout = ms->_icallout;
	CFRunLoopSourceRef source = ms->_source;
	CFMachPortRef replyPort = ms->_replyPort;
	CFMachPortRef port = ms->_port;
	CFStringRef name = ms->_name;
	void *info = NULL;

	__CFMessagePortUnsetValid(ms);
	if (!__CFMessagePortIsRemote(ms)) {
	    info = ms->_context.info;
	    ms->_context.info = NULL;
	}
	ms->_source = NULL;
	ms->_replyPort = NULL;
	__CFMessagePortUnlock(ms);

	__CFSpinLock(&__CFAllMessagePortsLock);
	if (NULL != (__CFMessagePortIsRemote(ms) ? __CFAllRemoteMessagePorts : __CFAllLocalMessagePorts)) {
	    CFDictionaryRemoveValue(__CFMessagePortIsRemote(ms) ? __CFAllRemoteMessagePorts : __CFAllLocalMessagePorts, name);
	}
	__CFSpinUnlock(&__CFAllMessagePortsLock);
	if (NULL != callout) {
	    callout(ms, info);
	}
	// We already know we're going invalid, don't need this callback
	// anymore; plus, this solves a reentrancy deadlock; also, this
	// must be done before the deallocate of the Mach port, to
	// avoid a race between the notification message which could be
	// handled in another thread, and this NULL'ing out.
	CFMachPortSetInvalidationCallBack(port, NULL);
	// For hashing and equality purposes, cannot get rid of _port here
	if (!__CFMessagePortIsRemote(ms) && NULL != ms->_context.release) {
	    ms->_context.release(info);
	}
	if (NULL != source) {
	    CFRunLoopSourceInvalidate(source);
	    CFRelease(source);
	}
	if (NULL != replyPort) {
	    CFMachPortInvalidate(replyPort);
	    CFRelease(replyPort);
	}
	if (__CFMessagePortIsRemote(ms)) {
	    // Get rid of our extra ref on the Mach port gotten from bs server
	    mach_port_deallocate(mach_task_self(), CFMachPortGetPort(port));
	}
    } else {
	__CFMessagePortUnlock(ms);
    }
    if (!__CFMessagePortIsDeallocing(ms)) {
	CFRelease(ms);
    }
}
Пример #5
0
__private_extern__
void
do_close(int argc, char **argv)
{
	if (notifyRls != NULL) {
		if (doDispatch) {
			(void) SCDynamicStoreSetDispatchQueue(store, NULL);
		} else {
			CFRunLoopSourceInvalidate(notifyRls);
			CFRelease(notifyRls);
		}
		notifyRls = NULL;
	}

	if (notifyRl != NULL) {
		CFRunLoopStop(notifyRl);
		notifyRl  = NULL;
	}

	if (store != NULL) {
		CFRelease(store);
		store = NULL;
		CFRelease(watchedKeys);
		watchedKeys = NULL;
		CFRelease(watchedPatterns);
		watchedPatterns = NULL;
	}

	cache_close();

	return;
}
Пример #6
0
static void* btstack_thread_func(void* data)
{
   RARCH_LOG("BTstack: Thread started");

   if (bt_open_ptr())
   {
      RARCH_LOG("BTstack: bt_open() failed\n");
      return 0;
   }

   CFRunLoopSourceContext ctx = { 0, 0, 0, 0, 0, 0, 0, 0, 0, btstack_thread_stop };
   btstack_quit_source = CFRunLoopSourceCreate(0, 0, &ctx);
   CFRunLoopAddSource(CFRunLoopGetCurrent(), btstack_quit_source, kCFRunLoopCommonModes);

   RARCH_LOG("BTstack: Turning on\n");
   bt_send_cmd_ptr(btstack_set_power_mode_ptr, HCI_POWER_ON);

   RARCH_LOG("BTstack: Running\n");
   CFRunLoopRun();
   
   RARCH_LOG("BTstack: Done\n");

   CFRunLoopSourceInvalidate(btstack_quit_source);
   CFRelease(btstack_quit_source);
   return 0;
}
Пример #7
0
/*
    Removes the loop source for the given socket from the current run loop.
*/
void qt_mac_remove_socket_from_runloop(const CFSocketRef socket, CFRunLoopSourceRef runloop)
{
    Q_ASSERT(runloop);
    CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop, kCFRunLoopCommonModes);
    CFSocketDisableCallBacks(socket, kCFSocketReadCallBack);
    CFSocketDisableCallBacks(socket, kCFSocketWriteCallBack);
    CFRunLoopSourceInvalidate(runloop);
}
Пример #8
0
/*
 * Wait until a console user logs in (or don't wait if one is already logged in).
 */
static bool
wait_for_console_user(char *devname)
{
	CFStringRef             key;
	CFMutableArrayRef       keys;
	Boolean                 ok;
	SCDynamicStoreRef       store = NULL;
	CFRunLoopSourceRef      rls;
	CFStringRef             user;
	uid_t                   uid;
	gid_t                   gid;
	bool                    ret = false;

	store = SCDynamicStoreCreate(NULL, CFSTR("com.apple.nofs"),
	    console_user_changed_cb, NULL);
	if (store == NULL) {
		return ret;
	}

	/* check if a console user is already logged in */
	user = SCDynamicStoreCopyConsoleUser(store, &uid, &gid);
	if (user != NULL) {
		CFRelease(user);
		ret = true;
		goto out;
	}

	/* wait for a notification that a console user logged in */
	keys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
	key = SCDynamicStoreKeyCreateConsoleUser(NULL);
	CFArrayAppendValue(keys, key);
	CFRelease(key);
	ok = SCDynamicStoreSetNotificationKeys(store, keys, NULL);
	CFRelease(keys);
	if (!ok) {
		syslog(LOG_ERR, "nofs: SCDynamicStoreSetNotificationKeys() failed");
		goto out;
	}
	rls = SCDynamicStoreCreateRunLoopSource(NULL, store, -1);
	if (rls == NULL) {
		syslog(LOG_ERR, "nofs: SCDynamicStoreCreateRunLoopSource() failed");
		goto out;
	}

	CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
	CFRunLoopRun();
	CFRunLoopSourceInvalidate(rls);
	CFRelease(rls);

	ret = true;

out:
	if (store) {
		CFRelease(store);
	}
	return ret;
}
Пример #9
0
/* extern */ void
_CFTypeInvalidate(CFTypeRef obj) {

	CFTypeID t = CFGetTypeID(obj);

	/* Invalidate according to type of object. */
	if (t == CFRunLoopSourceGetTypeID()) {
		CFRunLoopSourceInvalidate((CFRunLoopSourceRef)obj);
	}

	else if (t == CFMachPortGetTypeID()) {
		CFMachPortInvalidate((CFMachPortRef)obj);
	}

	else if (t == CFSocketGetTypeID()) {
		CFSocketInvalidate((CFSocketRef)obj);
	}

	/* For scheduled types of objects, it is invalidated by setting the client to NULL. */
	else if (t == CFReadStreamGetTypeID()) {
		CFReadStreamSetClient((CFReadStreamRef)obj, kCFStreamEventNone, NULL, NULL);
	}

	else if (t == CFWriteStreamGetTypeID()) {
		CFWriteStreamSetClient((CFWriteStreamRef)obj, kCFStreamEventNone, NULL, NULL);
	}

	else if (t == CFHostGetTypeID()) {
		CFHostSetClient((CFHostRef)obj, NULL, NULL);
	}

	else if (t == SCNetworkReachabilityGetTypeID()) {
		SCNetworkReachabilitySetCallback((SCNetworkReachabilityRef)obj, NULL, NULL);
	}

	else if (t == CFRunLoopTimerGetTypeID()) {
		CFRunLoopTimerInvalidate((CFRunLoopTimerRef)obj);
	}

	else if (t == CFNetServiceGetTypeID()) {
		CFNetServiceSetClient((CFNetServiceRef)obj, NULL, NULL);
	}

	else if (t == CFNetServiceBrowserGetTypeID()) {
		CFNetServiceBrowserInvalidate((CFNetServiceBrowserRef)obj);
	}

	else if (t == CFNetServiceMonitorGetTypeID()) {
		CFNetServiceMonitorInvalidate((CFNetServiceMonitorRef)obj);
	}

	else if (t == SCNetworkReachabilityGetTypeID()) {
		SCNetworkConnectionStop((SCNetworkConnectionRef)obj, FALSE);
	}
}
Пример #10
0
Boolean
SCDynamicStoreNotifyCancel(SCDynamicStoreRef store)
{
	SCDynamicStorePrivateRef	storePrivate = (SCDynamicStorePrivateRef)store;
	kern_return_t			status;
	int				sc_status;

	if (store == NULL) {
		/* sorry, you must provide a session */
		_SCErrorSet(kSCStatusNoStoreSession);
		return FALSE;
	}

	switch (storePrivate->notifyStatus) {
		case NotifierNotRegistered :
			/* if no notifications have been registered */
			return TRUE;
		case Using_NotifierInformViaRunLoop :
			CFRunLoopSourceInvalidate(storePrivate->rls);
			storePrivate->rls = NULL;
			return TRUE;
		case Using_NotifierInformViaDispatch :
			(void) SCDynamicStoreSetDispatchQueue(store, NULL);
			return TRUE;
		default :
			break;
	}

	if (storePrivate->server == MACH_PORT_NULL) {
		/* sorry, you must have an open session to play */
		sc_status = kSCStatusNoStoreServer;
		goto done;
	}

	status = notifycancel(storePrivate->server, (int *)&sc_status);

	if (__SCDynamicStoreCheckRetryAndHandleError(store,
						     status,
						     &sc_status,
						     "SCDynamicStoreNotifyCancel notifycancel()")) {
		sc_status = kSCStatusOK;
	}

    done :

	/* set notifier inactive */
	storePrivate->notifyStatus = NotifierNotRegistered;

	if (sc_status != kSCStatusOK) {
		_SCErrorSet(sc_status);
		return FALSE;
	}

	return TRUE;
}
Пример #11
0
void SocketStreamHandle::removePACRunLoopSource()
{
    ASSERT(m_pacRunLoopSource);

    CFRunLoopSourceInvalidate(m_pacRunLoopSource.get());
#if PLATFORM(WIN)
    CFRunLoopRemoveSource(loaderRunLoop(), m_pacRunLoopSource.get(), kCFRunLoopDefaultMode);
#else
    CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_pacRunLoopSource.get(), kCFRunLoopCommonModes);
#endif
    m_pacRunLoopSource = 0;
}
Пример #12
0
void
COSXScreen::watchSystemPowerThread(void*)
{
	io_object_t				notifier;
	IONotificationPortRef	notificationPortRef;
	CFRunLoopSourceRef		runloopSourceRef = 0;

	m_pmRunloop = CFRunLoopGetCurrent();
	// install system power change callback
	m_pmRootPort = IORegisterForSystemPower(this, &notificationPortRef,
											powerChangeCallback, &notifier);
	if (m_pmRootPort == 0) {
		LOG((CLOG_WARN "IORegisterForSystemPower failed"));
	}
	else {
		runloopSourceRef =
			IONotificationPortGetRunLoopSource(notificationPortRef);
		CFRunLoopAddSource(m_pmRunloop, runloopSourceRef,
								kCFRunLoopCommonModes);
	}
	
	// thread is ready
	{
		CLock lock(m_pmMutex);
		*m_pmThreadReady = true;
		m_pmThreadReady->signal();
	}

	// if we were unable to initialize then exit.  we must do this after
	// setting m_pmThreadReady to true otherwise the parent thread will
	// block waiting for it.
	if (m_pmRootPort == 0) {
		return;
	}

	// start the run loop
	LOG((CLOG_DEBUG "started watchSystemPowerThread"));
	CFRunLoopRun();
	
	// cleanup
	if (notificationPortRef) {
		CFRunLoopRemoveSource(m_pmRunloop,
								runloopSourceRef, kCFRunLoopDefaultMode);
		CFRunLoopSourceInvalidate(runloopSourceRef);
		CFRelease(runloopSourceRef);
	}

	CLock lock(m_pmMutex);
	IODeregisterForSystemPower(&notifier);
	m_pmRootPort = 0;
	LOG((CLOG_DEBUG "stopped watchSystemPowerThread"));
}
Пример #13
0
void DestroyMessageQueue()
{
    if (runLoopSource) {
        CFRunLoopSourceInvalidate(runLoopSource);
        CFRelease(runLoopSource);
        runLoopSource = NULL;
    }

    if (queueArray) {
        pthread_mutex_destroy(&queueLock);
        CFRelease(queueArray);
    }
}
Пример #14
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopSourceInvalidate(rwsched_tasklet_ptr_t sched_tasklet,
        rwsched_CFRunLoopSourceRef source)
{
    // 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_CF_TYPE_VALIDATE(source, rwsched_CFRunLoopSourceRef);

    // Call the native CFRunLoop function
    CFRunLoopSourceInvalidate(source->cf_object);
}
Пример #15
0
/*
	druErase
	
	Called to do a erase. Pass in the device and a flag to indicate a full or quick erase.
*/
int
druErase(DRDeviceRef device, int fullErase)
{
	DREraseRef					erase = NULL;
	DRNotificationCenterRef		notificationCenter = NULL;
	CFRunLoopSourceRef			source = NULL;
	druBurnStatus				status = {0, NULL, NULL, NULL, {0}, 0};
	CFMutableDictionaryRef		properties;

	erase = DREraseCreate(device);

	if (erase != NULL)
	{
		/* Create a progress bar. */
		status.progressBar = druProgressBarCreate();
		
		/* Sign up for notifications from the erase object. */
		notificationCenter = DRNotificationCenterCreate();
		source = DRNotificationCenterCreateRunLoopSource(notificationCenter);
		CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
		DRNotificationCenterAddObserver(notificationCenter,&status,druProgressCallback,kDREraseStatusChangedNotification, erase);
		
		/* setup erase properties for type of erase to be performed */
		properties = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks);
		if (fullErase)
			CFDictionaryAddValue(properties,kDREraseTypeKey,kDREraseTypeComplete);
		else
			CFDictionaryAddValue(properties,kDREraseTypeKey,kDREraseTypeQuick);
		DREraseSetProperties(erase, properties);
		
		/* Okay, start the erase. */
		DREraseStart(erase);
		
		/* Enter a runloop until the burn finishes. */
		CFRunLoopRun();
		
		/* Clean up memory and exit. */
		CFRunLoopSourceInvalidate(source);
		if (notificationCenter != NULL)	CFRelease(notificationCenter);
		if (source != NULL)				CFRelease(source);
		if (status.progressBar != NULL)	druProgressBarDispose(status.progressBar,status.success);
		CFRelease(erase);
	}
	if (status.success)
		printf("Erase completed.\n");
	else
		druPrintFailureMessage("Erase", status.completionStatus);
	if (status.completionStatus != NULL)	CFRelease(status.completionStatus);
	
	return status.success;
}
Пример #16
0
WatcherData::~WatcherData()
{
    // stop the thread;
    {
        std::lock_guard<std::mutex> locker(mutex);
        flags |= Stop;
        CFRunLoopSourceSignal(source);
        CFRunLoopWakeUp(loop);
    }
    thread.join();

    CFRunLoopSourceInvalidate(source);
    CFRelease(source);
}
Пример #17
0
void QCFSocketNotifier::removeSocketNotifiers()
{
    // Remove CFSockets from the runloop.
    for (MacSocketHash::ConstIterator it = macSockets.constBegin(); it != macSockets.constEnd(); ++it) {
        MacSocketInfo *socketInfo = (*it);
        if (CFSocketIsValid(socketInfo->socket)) {
            qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop);
            CFRunLoopSourceInvalidate(socketInfo->runloop);
            CFRelease(socketInfo->runloop);
            CFSocketInvalidate(socketInfo->socket);
            CFRelease(socketInfo->socket);
        }
    }
}
Пример #18
0
/*
    Unregister QSocketNotifer. The CFSocket correspoding to this notifier is
    removed from the runloop of this is the last notifier that users
    that CFSocket.
*/
void QEventDispatcherMac::unregisterSocketNotifier(QSocketNotifier *notifier)
{
    Q_ASSERT(notifier);
    int nativeSocket = notifier->socket();
    int type = notifier->type();
#ifndef QT_NO_DEBUG
    if (nativeSocket < 0 || nativeSocket > FD_SETSIZE) {
        qWarning("QSocketNotifier: Internal error");
        return;
    } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
        qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");
        return;
    }
#endif

    Q_D(QEventDispatcherMac);
    QEventDispatcherUNIX::unregisterSocketNotifier(notifier);

    if (type == QSocketNotifier::Exception) {
        qWarning("QSocketNotifier::Exception is not supported on Mac OS X");
        return;
    }
    MacSocketInfo *socketInfo = d->macSockets.value(nativeSocket);
    if (!socketInfo) {
        qWarning("QEventDispatcherMac::unregisterSocketNotifier: Tried to unregister a not registered notifier");
        return;
    }

    // Decrement read/write counters and disable callbacks if necessary.
    if (type == QSocketNotifier::Read) {
        if (--socketInfo->read == 0)
            CFSocketDisableCallBacks(socketInfo->socket, kCFSocketReadCallBack);
    } else if (type == QSocketNotifier::Write) {
        if (--socketInfo->write == 0)
            CFSocketDisableCallBacks(socketInfo->socket, kCFSocketWriteCallBack);
    }

    // Remove CFSocket from runloop if this was the last QSocketNotifier.
    if (socketInfo->read <= 0 && socketInfo->write <= 0) {
        if (CFSocketIsValid(socketInfo->socket))
            qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop);
        CFRunLoopSourceInvalidate(socketInfo->runloop);
        CFRelease(socketInfo->runloop);
        CFSocketInvalidate(socketInfo->socket);
        CFRelease(socketInfo->socket);
        delete socketInfo;
        d->macSockets.remove(nativeSocket);
    }
}
Пример #19
0
/**
 * @brief Destroy a CFMIDIRunLoopSource instance.
 * Free all resources occupied by the runloop soruce and release all referenced objects.
 * @public @memberof CFMIDIRunLoopSource
 * @param source The runloop source.
 */
void CFMIDIRunLoopSourceDestroy( struct CFMIDIRunLoopSource * source ) {
  int i;
  MIDIPrecondReturn( source != NULL, EFAULT, (void)0 );
  if( source->cfrlt != NULL ) {
    CFRunLoopTimerInvalidate( source->cfrlt );
    CFRelease( source->cfrlt );
  }
  for( i=0; i<source->length; i++ ) {
    if( source->cfrls[i] != NULL ) {
      CFRunLoopSourceInvalidate( source->cfrls[i] );
      CFRelease( source->cfrls[i] );
    }
  }
  free( source );
}
Пример #20
0
/* static */ void
_BrowserCancel(__CFNetServiceBrowser* browser) {

	CFNetServiceBrowserClientCallBack cb = NULL;
	CFStreamError error;
	void* info = NULL;

	// Retain here to guarantee safety really after the browser release,
	// but definitely before the callback.
	CFRetain(browser);

	// Lock the browser
	__CFSpinLock(&browser->_lock);

	// If the browse canceled, don't need to do any of this.
	if (browser->_trigger) {

		// Save the callback if there is one at this time.
		cb = browser->_callback;

		// Save the error and client information for the callback
		memmove(&error, &(browser->_error), sizeof(error));
		info = browser->_client.info;

		// Remove the trigger from run loops and modes
		_CFTypeUnscheduleFromMultipleRunLoops(browser->_trigger, browser->_schedules);

		// Invalidate the run loop source that got here
		CFRunLoopSourceInvalidate((CFRunLoopSourceRef)(browser->_trigger));

		// Release the trigger now.
		CFRelease(browser->_trigger);
		browser->_trigger = NULL;
	}

	// Unlock the browser so the callback can be made safely.
	__CFSpinUnlock(&browser->_lock);

	// If there is a callback, inform the client of the finish.
	if (cb)
		cb((CFNetServiceBrowserRef)browser, 0, NULL, &error, info);

	// Go ahead and release now that the callback is done.
	CFRelease(browser);
}
Пример #21
0
static void
watchQuietDisable()
{
	if ((initKey == NULL) || (initRls == NULL)) {
		return;
	}

	(void) SCDynamicStoreSetNotificationKeys(store, NULL, NULL);

	CFRunLoopSourceInvalidate(initRls);
	CFRelease(initRls);
	initRls = NULL;

	CFRelease(initKey);
	initKey = NULL;

	return;
}
Пример #22
0
static void
DisposeRegistration(void *context)
{
	if (gNameMonitorSource) {
		CFRunLoopSourceInvalidate(gNameMonitorSource);
		CFRelease(gNameMonitorSource);
		gNameMonitorSource = NULL;
	}

	if (gServiceRegistration) {
		MyDNSServiceFree(gServiceRegistration);
		gServiceRegistration = NULL;
	}
	
	if (gCurrentWorkstationName) {
		CFRelease(gCurrentWorkstationName);
		gCurrentWorkstationName = NULL;
	}
}
Пример #23
0
static void
Alert_response(CFUserNotificationRef alert, CFOptionFlags response_flags)
{
    Alert *	alert_p;

    alert_p = Alert_find(alert);
    if (alert_p == NULL) {
	EAPLOG_FL(LOG_NOTICE, "Alert_find failed");
	return;
    }
    if (alert_p->rls) {
	CFRunLoopSourceInvalidate(alert_p->rls);
	my_CFRelease(&alert_p->rls);
    }
    if (alert_p->notif) {
	my_CFRelease(&alert_p->notif);
    }
    (*alert_p->func)(alert_p->arg1, alert_p->arg2);
    return;
}
Пример #24
0
static DWORD WINAPI MIDIIn_MessageThread(LPVOID p)
{
    CFMessagePortRef local;
    CFRunLoopSourceRef source;
    Boolean info;

    local = CFMessagePortCreateLocal(kCFAllocatorDefault, MIDIInThreadPortName, &MIDIIn_MessageHandler, NULL, &info);

    source = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, local, 0);
    CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);

    CFRunLoopRun();

    CFRunLoopSourceInvalidate(source);
    CFRelease(source);
    CFRelease(local);
    CFRelease(MIDIInThreadPortName);
    MIDIInThreadPortName = NULL;

    return 0;
}
Пример #25
0
void CFWindowsMessageQueueInvalidate(CFWindowsMessageQueueRef wmq) {
    __CFGenericValidateType(wmq, __kCFWindowsMessageQueueTypeID);
    CFRetain(wmq);
    __CFWindowsMessageQueueLock(wmq);
    if (__CFWindowsMessageQueueIsValid(wmq)) {
	SInt32 idx;
	__CFWindowsMessageQueueUnsetValid(wmq);
	for (idx = CFArrayGetCount(wmq->_runLoops); idx--;) {
	    CFRunLoopWakeUp((CFRunLoopRef)CFArrayGetValueAtIndex(wmq->_runLoops, idx));
	}
	CFRelease(wmq->_runLoops);
	wmq->_runLoops = NULL;
	if (NULL != wmq->_source) {
	    CFRunLoopSourceInvalidate(wmq->_source);
	    CFRelease(wmq->_source);
	    wmq->_source = NULL;
	}
    }
    __CFWindowsMessageQueueUnlock(wmq);
    CFRelease(wmq);
}
Пример #26
0
void
Alert_free(Alert * * alert_p_p)
{
    Alert * alert_p = *alert_p_p;

    if (alert_p) {
	LIST_REMOVE(alert_p, entries);
	if (alert_p->rls) {
	    CFRunLoopSourceInvalidate(alert_p->rls);
	    my_CFRelease(&alert_p->rls);
	}
	if (alert_p->notif) {
	    (void)CFUserNotificationCancel(alert_p->notif);
	    my_CFRelease(&alert_p->notif);
	}
	bzero(alert_p, sizeof(*alert_p));
	free(alert_p);
    }
    *alert_p_p = NULL;
    return;
}
Пример #27
0
QEventDispatcherMac::~QEventDispatcherMac()
{
    Q_D(QEventDispatcherMac);
    //timer cleanup
    d->zero_timer_count = 0;
    if(d->macTimerList) {
        for (int i = 0; i < d->macTimerList->size(); ++i) {
            const MacTimerInfo &t = d->macTimerList->at(i);
            if (t.mac_timer) {
                RemoveEventLoopTimer(t.mac_timer);
                if (t.pending) {
                    EventComparatorUPP fnc = NewEventComparatorUPP(find_timer_event);
                    FlushSpecificEventsFromQueue(GetMainEventQueue(), fnc, (void *)&t);
                    DisposeEventComparatorUPP(fnc);
                }
            }
        }
        delete d->macTimerList;
        d->macTimerList = 0;
    }
    if(timerUPP) {
        DisposeEventLoopTimerUPP(timerUPP);
        timerUPP = 0;
    }

    // Remove CFSockets from the runloop.
    for (MacSocketHash::ConstIterator it = d->macSockets.constBegin(); it != d->macSockets.constEnd(); ++it) {
        MacSocketInfo *socketInfo = (*it);
        if (CFSocketIsValid(socketInfo->socket)) {
            qt_mac_remove_socket_from_runloop(socketInfo->socket, socketInfo->runloop);
            CFRunLoopSourceInvalidate(socketInfo->runloop);
            CFRelease(socketInfo->runloop);
            CFSocketInvalidate(socketInfo->socket);
            CFRelease(socketInfo->socket);
        }
    }
    CFRunLoopRemoveSource(runLoopForCarbonLoop(GetMainEventLoop()), d->postedEventsSource, kCFRunLoopCommonModes);
    CFRelease(d->postedEventsSource);
    d->postedEventsSource = 0;
}
void
stop(CFRunLoopSourceRef stopRls)
{
	// cleanup

	if (storeRls != NULL) {
		CFRunLoopSourceInvalidate(storeRls);
		CFRelease(storeRls);
		storeRls = NULL;
	}

	if (store != NULL) {
		CFRelease(store);
		store = NULL;
		CFRelease(curGlobals);
		CFRelease(curConfigFile);
		CFRelease(curDefaults);
		CFRelease(curStartup);
	}

	CFRunLoopSourceSignal(stopRls);
	return;
}
/* PsychHIDReceiveReportsCleanup(void) -- Called at PsychHID shutdown time:

1. one must call CFRunLoopSourceInvalidate to kill the callback established by setInterruptReportHandlerCallback 
 before calling HIDReleaseDeviceList.

2. after calling setInterruptReportHandlerCallback to enable the callback and CFRunLoopSourceInvalidate to disable 
it, it is then impossible to re-enable the callback with that source. To later re-enable, simply remove the source, instead of
invalidating it. Once i've called CFRunLoopSourceInvalidate it appears that my only option is to release the interface by calling 
 HIDReleaseDeviceList and start over.

*/
PsychError PsychHIDReceiveReportsCleanup(void) 
{
	int deviceIndex;
	
	//printf("Clean up before PsychHID is flushed.\n");
	for(deviceIndex=0;deviceIndex<MAXDEVICEINDEXS;deviceIndex++) if(source[deviceIndex]!=NULL) {
        CheckRunLoopSource(deviceIndex,"PsychHIDReceiveReportsCleanup",__LINE__);
		CFRunLoopRemoveSource(CFRunLoopGetCurrent(),source[deviceIndex],myRunLoopMode);// kCFRunLoopDefaultMode
        if (optionsPrintCrashers) printf("%d: CFRunLoopSourceInvalidate\n",deviceIndex);
        CFRunLoopSourceInvalidate(source[deviceIndex]);
        if(optionsPrintCrashers) printf("%d: source %4.4lx validity %d, CFRunLoopContainsSource is %d.\n",deviceIndex,(unsigned long)source[deviceIndex]
                                           ,CFRunLoopSourceIsValid(source[deviceIndex])
                                           ,CFRunLoopContainsSource(CFRunLoopGetCurrent(),source[deviceIndex],myRunLoopMode));
        ready[deviceIndex]=0;
        CheckRunLoopSource(deviceIndex,"PsychHIDReceiveReportsCleanup",__LINE__);
        source[deviceIndex]=NULL;
	}
    
    // Release all report linked lists, memory buffers etc.:
    PsychHIDReleaseAllReportMemory();

	return 0;
}
/*
1. one must call CFRunLoopSourceInvalidate to kill the callback established by setInterruptReportHandlerCallback 
 before calling HIDReleaseDeviceList.

2. after calling setInterruptReportHandlerCallback to enable the callback and CFRunLoopSourceInvalidate to disable 
it, it is then impossible to re-enable the callback with that source. To later re-enable, simply remove the source, instead of
invalidating it. Once i've called CFRunLoopSourceInvalidate it appears that my only option is to release the interface by calling 
 HIDReleaseDeviceList and start over.
*/
PsychError PsychHIDReceiveReportsCleanup(void) 
{
// On a hunch, we now do both: remove the source and invalidate it. Alas, it makes no difference. I still get the CLEAR MEX crash.
	int deviceIndex;
	
	//printf("Clean up before PsychHID is flushed.\n");
	for(deviceIndex=0;deviceIndex<MAXDEVICEINDEXS;deviceIndex++) if(source[deviceIndex]!=NULL) {
                CheckRunLoopSource(deviceIndex,"PsychHIDReceiveReportsCleanup",__LINE__);
		CFRunLoopRemoveSource(CFRunLoopGetCurrent(),source[deviceIndex],myRunLoopMode);// kCFRunLoopDefaultMode
		if(0 && optionsPrintCrashers)printf("%d: source %4.4lx validity %d, CFRunLoopContainsSource is %d.\n",deviceIndex,(unsigned long)source[deviceIndex]
					,CFRunLoopSourceIsValid(source[deviceIndex])
					,CFRunLoopContainsSource(CFRunLoopGetCurrent(),source[deviceIndex],myRunLoopMode));
		if(optionsPrintCrashers)printf("%d: CFRunLoopSourceInvalidate\n",deviceIndex);
		CFRunLoopSourceInvalidate(source[deviceIndex]);
		if(optionsPrintCrashers)printf("%d: source %4.4lx validity %d, CFRunLoopContainsSource is %d.\n",deviceIndex,(unsigned long)source[deviceIndex]
					,CFRunLoopSourceIsValid(source[deviceIndex])
					,CFRunLoopContainsSource(CFRunLoopGetCurrent(),source[deviceIndex],myRunLoopMode));
		ready[deviceIndex]=0;
		CheckRunLoopSource(deviceIndex,"PsychHIDReceiveReportsCleanup",__LINE__);
		source[deviceIndex]=NULL;
	}			
	return 0;
}