Ejemplo n.º 1
0
void AddToMessageQueue(CFTypeRef objectToAdd)
{
    int pthreadError;
    
    // take the lock on the message queue
    pthreadError = pthread_mutex_lock(&queueLock);
    if (pthreadError) {
#if DEBUG
        printf("AddToMessageQueue: pthread_mutex_lock failed (%d)\n", pthreadError);
#endif
        return;        
    }
    
    // add the object to the queue
    CFArrayAppendValue(queueArray, objectToAdd);

    // release the lock
    pthreadError = pthread_mutex_unlock(&queueLock);
    if (pthreadError) {
#if DEBUG
        printf("AddToMessageQueue: pthread_mutex_unlock failed (%d)\n", pthreadError);
#endif
        return;
    }
    
    // signal the run loop source, so it runs
    CFRunLoopSourceSignal(runLoopSource);
    // and make sure the run loop wakes up right away (otherwise it may take a few seconds)
    CFRunLoopWakeUp(mainThreadRunLoop);
}
void WatcherThread::stop()
{
    MutexLocker locker(&mutex);
    flags |= Stop;
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
}
static void
rlsCallback(CFMachPortRef port, void *msg, CFIndex size, void *info)
{
	mach_no_senders_notification_t	*buf		= msg;
	mach_msg_id_t			msgid		= buf->not_header.msgh_id;
	SCDynamicStoreRef		store		= (SCDynamicStoreRef)info;
	SCDynamicStorePrivateRef	storePrivate	= (SCDynamicStorePrivateRef)store;

	if (msgid == MACH_NOTIFY_NO_SENDERS) {
		/* the server died, disable additional callbacks */
#ifdef	DEBUG
		SCLog(_sc_verbose, LOG_INFO, CFSTR("  rlsCallback(), notifier port closed"));
#endif	/* DEBUG */

#ifdef	DEBUG
		if (port != storePrivate->rlsNotifyPort) {
			SCLog(_sc_verbose, LOG_DEBUG, CFSTR("rlsCallback(), why is port != rlsNotifyPort?"));
		}
#endif	/* DEBUG */

		/* re-establish notification and inform the client */
		(void)__SCDynamicStoreReconnectNotifications(store);
	}

	/* signal the real runloop source */
	if (storePrivate->rls != NULL) {
		CFRunLoopSourceSignal(storePrivate->rls);
	}
	return;
}
Ejemplo n.º 4
0
/*
 * rend_pipe_monitor
 */
void *rend_pipe_monitor(void* arg) {
    fd_set rset;
    int result;


    while(1) {
	DPRINTF(E_DBG,L_REND,"Waiting for data\n");
	FD_ZERO(&rset);
	FD_SET(rend_pipe_to[RD_SIDE],&rset);

	/* sit in a select spin until there is data on the to fd */
	while(((result=select(rend_pipe_to[RD_SIDE] + 1,&rset,NULL,NULL,NULL)) != -1) &&
	    errno != EINTR) {
	    if(FD_ISSET(rend_pipe_to[RD_SIDE],&rset)) {
		DPRINTF(E_DBG,L_REND,"Received a message from daap server\n");
		CFRunLoopSourceSignal(rend_rls);
		CFRunLoopWakeUp(rend_runloop);
		sleep(1);  /* force a reschedule, hopefully */
	    }
	}

	DPRINTF(E_DBG,L_REND,"Select error!\n");
	/* should really bail here */
    }
}
void WatcherThread::clear()
{
    MutexLocker locker(&mutex);
    flags |= Clear;
    paths.clear();
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
}
Ejemplo n.º 6
0
void WatcherData::clear()
{
    std::lock_guard<std::mutex> lock(mutex);

    flags |= Clear;
    paths.clear();
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
}
Ejemplo n.º 7
0
void wxApp::WakeUpIdle()
{
#ifdef __WXMAC_OSX__
    if (m_macEventPosted)
    {
        CFRunLoopSourceSignal(m_macEventPosted);
    }
#endif
    wxMacWakeUp() ;
}
bool WatcherThread::unwatch(const Path& path)
{
    MutexLocker locker(&mutex);
    if (paths.remove(path)) {
        CFRunLoopSourceSignal(source);
        CFRunLoopWakeUp(loop);
        return true;
    }
    return false;
}
Ejemplo n.º 9
0
void WatcherData::watch(const Path& path)
{
    std::lock_guard<std::mutex> lock(mutex);

    assert(!paths.contains(path));

    paths.insert(path);
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
}
bool WatcherThread::watch(const Path& path)
{
    MutexLocker locker(&mutex);
    if (isWatching(path))
        return false;
    paths.insert(path);
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
    return true;
}
Ejemplo n.º 11
0
static void
CFSocketDispatchWriteEvent(void* p)
{
  CFSocketRef socket = (CFSocketRef) p;
  CFRunLoopSourceRef src = socket->_source;
  
  socket->_writeFired = true;
  
  if (src != NULL)
    CFRunLoopSourceSignal(src);
}
Ejemplo n.º 12
0
void HostDnsServiceDarwin::monitorThreadShutdown()
{
    ALock l(this);
    if (!m->m_fStop)
    {
        CFRunLoopSourceSignal(m->m_Stopper);
        CFRunLoopWakeUp(m->m_RunLoopRef);

        RTSemEventWait(m->m_evtStop, RT_INDEFINITE_WAIT);
    }
}
Ejemplo n.º 13
0
bool WatcherData::unwatch(const Path& path)
{
    std::lock_guard<std::mutex> lock(mutex);

    auto p = paths.find(path);
    if (p == paths.end())
        return false;

    paths.erase(p);
    CFRunLoopSourceSignal(source);
    CFRunLoopWakeUp(loop);
    return true;
}
Ejemplo n.º 14
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);
}
Ejemplo n.º 15
0
void
Tcl_AlertNotifier(
    ClientData clientData)
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) clientData;

    LOCK_NOTIFIER;
    if (tsdPtr->runLoop) {
	tsdPtr->eventReady = 1;
	CFRunLoopSourceSignal(tsdPtr->runLoopSource);
	CFRunLoopWakeUp(tsdPtr->runLoop);
    }
    UNLOCK_NOTIFIER;
}
Ejemplo n.º 16
0
static void hid_removal_callback(void *ctx, IOReturn result, void *sender)
{
    _HS_UNUSED(result);
    _HS_UNUSED(sender);

    hs_port *port = ctx;

    pthread_mutex_lock(&port->u.hid->mutex);
    port->u.hid->device_removed = true;
    CFRunLoopSourceSignal(port->u.hid->shutdown_source);
    pthread_mutex_unlock(&port->u.hid->mutex);

    fire_device_event(port);
}
Ejemplo n.º 17
0
void btstack_set_poweron(bool on)
{
   if (!btstack_try_load())
      return;

   if (on && !btstack_thread)
      pthread_create(&btstack_thread, 0, btstack_thread_func, 0);
   else if (!on && btstack_thread && btstack_quit_source)
   {
      CFRunLoopSourceSignal(btstack_quit_source);
      pthread_join(btstack_thread, 0);
      btstack_thread = 0;
   }
}
Ejemplo n.º 18
0
void DAStageSignal( void )
{
    /*
     * Signal DAStage.
     */

    if ( gDAIdle )
    {
        ___vproc_transaction_begin( );
    }

    gDAIdle = FALSE;

    CFRunLoopSourceSignal( __gDAStageRunLoopSource );
}
Ejemplo n.º 19
0
static void btstack_set_poweron(bool on)
{
   if (!btstack_try_load())
      return;

   if (on && !btstack_thread)
      btstack_thread = sthread_create(btstack_thread_func, NULL);
   else if (!on && btstack_thread && btstack_quit_source)
   {
#ifdef __APPLE__
      CFRunLoopSourceSignal(btstack_quit_source);
#endif
      sthread_join(btstack_thread);
      btstack_thread = NULL;
   }
}
Ejemplo n.º 20
0
void DeviceManagerThread::Shutdown()
{
    // Push for thread shutdown *WITH NO WAIT*.
    // This will have the following effect:
    //  - Exit command will get enqueued, which will be executed later on the thread itself.
    //  - Beyond this point, this DeviceManager object may be deleted by our caller.
    //  - Other commands, such as CreateDevice, may execute before ExitCommand, but they will
    //    fail gracefully due to pLock->pManager == 0. Future commands can't be enqued
    //    after pManager is null.
    //  - Once ExitCommand executes, ThreadCommand::Run loop will exit and release the last
    //    reference to the thread object.
    PushExitCommand(false);

    // make sure CFRunLoopRunInMode is woken up
    CFRunLoopSourceSignal(CommandQueueSource);
    CFRunLoopWakeUp(RunLoop);
}
Ejemplo n.º 21
0
void HID_API_EXPORT hid_close(hid_device *dev)
{
	if ( !dev )
	{
		return;
	}

	/* Disconnect the report callback before close. */
	if (!dev->disconnected) {
		IOHIDDeviceRegisterInputReportCallback(
			dev->device_handle, dev->input_report_buf, dev->max_input_report_len,
			NULL, dev);
		IOHIDManagerRegisterDeviceRemovalCallback(hid_mgr, NULL, dev);
		IOHIDDeviceUnscheduleFromRunLoop(dev->device_handle, dev->run_loop, dev->run_loop_mode);
		IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetMain(), kCFRunLoopDefaultMode);
	}
	
	/* Cause read_thread() to stop. */
	dev->shutdown_thread = 1;
	
	/* Wake up the run thread's event loop so that the thread can exit. */
	CFRunLoopSourceSignal(dev->source);
	CFRunLoopWakeUp(dev->run_loop);
	
	/* Notify the read thread that it can shut down now. */
	pthread_barrier_wait(&dev->shutdown_barrier);

	/* Wait for read_thread() to end. */
	pthread_join(dev->thread, NULL);

	/* Close the OS handle to the device, but only if it's not
	   been unplugged. If it's been unplugged, then calling
	   IOHIDDeviceClose() will crash. */
	if (!dev->disconnected) {
		IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
	}
	
	/* Clear out the queue of received reports. */
	pthread_mutex_lock(&dev->mutex);
	while (dev->input_reports) {
		return_data(dev, NULL, 0);
	}
	pthread_mutex_unlock(&dev->mutex);

	free_hid_device(dev);
}
Ejemplo n.º 22
0
void fxQueuePromiseJobs(txMachine* the)
{
#if mxMacOSX
	CFRunLoopSourceContext context;
#endif
	txJob* job = malloc(sizeof(txJob));
	job->the = the;
	job->moduleID = XS_NO_ID;
#if mxMacOSX
	memset(&context, 0, sizeof(context));
	context.info = job;
	context.perform = fxPerformJob;
    job->source = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
	CFRunLoopAddSource(CFRunLoopGetCurrent(), job->source, gxRunLoopMode);
	CFRunLoopSourceSignal(job->source);
#endif
}
Ejemplo n.º 23
0
InputHandler_MacOSX_HID::~InputHandler_MacOSX_HID()
{
	FOREACH( HIDDevice *, m_vDevices, i )
		delete *i;
	if( PREFSMAN->m_bThreadedInput )
	{
		CFRunLoopSourceSignal( m_SourceRef );
		CFRunLoopWakeUp( m_LoopRef );
		m_InputThread.Wait();
		CFRelease( m_SourceRef );
		CFRelease( m_LoopRef );
		LOG->Trace( "Input handler thread shut down." );
	}

	FOREACH( io_iterator_t, m_vIters, i )
		IOObjectRelease( *i );
	IONotificationPortDestroy( m_NotifyPort );
}
Ejemplo n.º 24
0
static void mailstream_low_cfstream_cancel(mailstream_low * s)
{
#if HAVE_CFNETWORK
  struct mailstream_cfstream_data * cfstream_data;
  
  cfstream_data = (struct mailstream_cfstream_data *) s->data;
  
  pthread_mutex_lock(&cfstream_data->runloop_lock);
  
  if (cfstream_data->cancelSource != NULL) {
    CFRunLoopSourceSignal(cfstream_data->cancelSource);
  }
  if (cfstream_data->runloop != NULL) {
    CFRunLoopWakeUp(cfstream_data->runloop);
  }
  
  pthread_mutex_unlock(&cfstream_data->runloop_lock);
#endif
}
Ejemplo n.º 25
0
void uv__cf_loop_signal(uv_loop_t* loop, cf_loop_signal_cb cb, void* arg) {
  uv__cf_loop_signal_t* item;

  item = malloc(sizeof(*item));
  /* XXX: Fail */
  if (item == NULL)
    abort();

  item->arg = arg;
  item->cb = cb;

  uv_mutex_lock(&loop->cf_mutex);
  QUEUE_INSERT_TAIL(&loop->cf_signals, &item->member);
  uv_mutex_unlock(&loop->cf_mutex);

  assert(loop->cf_loop != NULL);
  CFRunLoopSourceSignal(loop->cf_cb);
  CFRunLoopWakeUp(loop->cf_loop);
}
void mailstream_cfstream_interrupt_idle(mailstream * s)
{
#if HAVE_CFNETWORK
  struct mailstream_cfstream_data * cfstream_data;
  
  cfstream_data = (struct mailstream_cfstream_data *) s->low->data;
  
  pthread_mutex_lock(&cfstream_data->runloop_lock);
  
  if (cfstream_data->idleInterruptedSource != NULL) {
    CFRunLoopSourceSignal(cfstream_data->idleInterruptedSource);
  }
  if (cfstream_data->runloop != NULL) {
    CFRunLoopWakeUp(cfstream_data->runloop);
  }
  
  pthread_mutex_unlock(&cfstream_data->runloop_lock);
#endif
}
Ejemplo n.º 27
0
/*******************************************************************************
* This function is executed in the main thread after its run loop gets
* kicked by a client request.
*******************************************************************************/
kern_return_t _kextmanager_user_did_log_in(
    mach_port_t server,
    int euid,
    AuthorizationExternalForm authref)
{
    kern_return_t result = KERN_SUCCESS;

    logged_in_uid = euid;

#ifndef NO_CFUserNotification
    CFRunLoopSourceSignal(gNotificationQueueRunLoopSource);
    CFRunLoopWakeUp(gMainRunLoop);
#endif NO_CFUserNotification

//finish:

    gClientUID = -1;

    return result;
}
Ejemplo n.º 28
0
void kextd_handle_finished_notification(CFUserNotificationRef userNotification,
    CFOptionFlags responseFlags)
{

    if (gCurrentNotification) {
        CFRelease(gCurrentNotification);
        gCurrentNotification = NULL;
    }

    if (gCurrentNotificationRunLoopSource) {
        CFRunLoopRemoveSource(gMainRunLoop, gCurrentNotificationRunLoopSource,
            kCFRunLoopDefaultMode);
        CFRelease(gCurrentNotificationRunLoopSource);
        gCurrentNotificationRunLoopSource = NULL;
    }

    CFRunLoopSourceSignal(gNotificationQueueRunLoopSource);
    CFRunLoopWakeUp(gMainRunLoop);

    return;
}
Ejemplo n.º 29
0
kern_return_t _kextmanager_record_nonsecure_kextload(
    mach_port_t server,
    char * load_data,
    int load_data_length)
{
    kern_return_t result = KERN_SUCCESS;
#ifndef NO_CFUserNotification
    CFStringRef kextPath = NULL; // must release

    kextPath = CFStringCreateWithCString(kCFAllocatorDefault, load_data,
        kCFStringEncodingMacRoman);
    if (!kextPath) {
        result = KERN_FAILURE;
        goto finish;
    }

    if (!CFDictionaryGetValue(gNotifiedNonsecureKextPaths, kextPath)) {
        CFArrayAppendValue(gPendedNonsecureKextPaths, kextPath);
        CFDictionarySetValue(gNotifiedNonsecureKextPaths, kextPath,
            kCFBooleanTrue);
    }

    if (logged_in_uid != -1) {
        CFRunLoopSourceSignal(gNotificationQueueRunLoopSource);
        CFRunLoopWakeUp(gMainRunLoop);
    }

#else
    result = KERN_FAILURE;
#endif /* NO_CFUserNotification */


finish:

#ifndef NO_CFUserNotification
    if (kextPath) CFRelease(kextPath);
#endif /* NO_CFUserNotification */
    gClientUID = -1;
    return result;
}
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;
}