Пример #1
0
mama_status avisTransportBridge_start(avisTransportBridge* transportBridge)
{
    /* stop Avis event loop */
    int rc;

    CHECK_TRANSPORT(transportBridge); 

    if (1 == wInterlocked_read (&transportBridge->mDispatching))
    {
        mama_log (MAMA_LOG_LEVEL_WARN, "avisTransportBridge_start(): "
                                       "Avis already dispatching");
        log_avis_error (MAMA_LOG_LEVEL_WARN, transportBridge->mAvis);
        return MAMA_STATUS_OK;
    }

    wInterlocked_set (1, &transportBridge->mDispatching);

    rc = wthread_create (&transportBridge->mThreadId, NULL, 
                        avisDispatchThread, transportBridge);

    if (0 != rc)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "wthread_create returned %d", rc);
        return MAMA_STATUS_SYSTEM_ERROR;
    }

    return MAMA_STATUS_OK;   
}
Пример #2
0
mama_status
mamaDispatcher_create (mamaDispatcher *result,
                       mamaQueue      queue)
{
    mamaQueueImpl*      qImpl   = (mamaQueueImpl*)queue;
    mamaDispatcherImpl* impl    = NULL;

    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_WARN, "mamaDispatcher_create(): NULL queue.");
        return MAMA_STATUS_INVALID_ARG;
    }

    if (!result)
    {
        mama_log (MAMA_LOG_LEVEL_WARN, "mamaDispatcher_create(): Invalid "
                                        "address");
        return MAMA_STATUS_NULL_ARG;
    }

    *result = NULL;

    /*A queue can only have a single dispatcher.*/
    if (qImpl->mDispatcher)
        return MAMA_STATUS_TOO_MANY_DISPATCHERS;

    impl = (mamaDispatcherImpl*)calloc( 1, sizeof(mamaDispatcherImpl) );
    if (impl == NULL)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaDispatcher_create(): Could not "
                                         "allocate dispatcher.");
        return MAMA_STATUS_NOMEM;
    }

    wInterlocked_initialize(&impl->mIsDispatching);
    wInterlocked_set(0, &impl->mIsDispatching);

    impl->mQueue = queue;
    if (wthread_create(&impl->mThread, NULL, dispatchThreadProc, impl))
    {
        free (impl);
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaDispatcher_create(): Could not "
                                        "create dispatch thread.");
        return MAMA_STATUS_SYSTEM_ERROR;
    }

    qImpl->mDispatcher = (mamaDispatcher)impl;
    *result = (mamaDispatcher)impl;

    return MAMA_STATUS_OK;
}
Пример #3
0
/* Utility file scoped method used to start the single instance
 * monitoring thread.
 *
 * NB! At the moment this is not thread safe.  However all instances
 * are currently being created on a single thread.  Revisit
 * implementation if this changes. */
static void startThread(void)
{
    /* start the thread scanning the vector of TimeZones. */
    int                 status = 0;

    /* Start the thread scanning the vector of TimeZones. */
     sThreadStarted = 1;

    if ((status = wthread_create(&sThread, NULL, updateTimeZones, NULL) != 0))
    {
        printf ("TZ debug: failed to successfully create thread: "
                "%d\n", status);
	    sThreadStarted = 0;
    }
}
Пример #4
0
/*
   wvctl_load

   This function loads the module, that will create the worker thread
   which will play with the wview interface. This module depends on
   configuration module, since it does have configuration parameters
   like the window size and position. Create/initialize the callback
   lists and their associated synchronization objects.
*/
wstatus
wvctl_load(wvctl_load_t load)
{
	struct _jmlist_params jmlp;
	jmlist_status jmls;
	wstatus ws;

	dbgprint(MOD_WVIEWCTL,__func__,"called with load.exit_routine = %p",load.exit_routine);

	if( wvctl_loaded ) {
		dbgprint(MOD_WVIEWCTL,__func__,"module was already loaded");
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	jmlp.flags = JMLIST_LINKED;
	dbgprint(MOD_WVIEWCTL,__func__,"creating jmlist for keyboard callback list");
	jmls = jmlist_create(&keyboard_cbl,&jmlp);
	if( jmls != JMLIST_ERROR_SUCCESS ) {
		/* something went wrong with list creation */
		dbgprint(MOD_WVIEWCTL,__func__,"failed to create jmlist (status=%d)",jmls);
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	dbgprint(MOD_WVIEWCTL,__func__,"created jmlist for keyboard callback list successfully (jml=%p)",keyboard_cbl);
	dbgprint(MOD_WVIEWCTL,__func__,"creating wlock for keyboard callback list");

	/* create lock for the list */
	ws = wlock_create(&keyboard_cbl_lock);
	if( ws != WSTATUS_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"wlock creation failed for keyboard callback list");

		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	dbgprint(MOD_WVIEWCTL,__func__,"created lock for keyboard callback list successfully");

	jmlp.flags = JMLIST_LINKED;
	dbgprint(MOD_WVIEWCTL,__func__,"creating jmlist for mouse callback list");
	jmls = jmlist_create(&mouse_cbl,&jmlp);
	if( jmls != JMLIST_ERROR_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"failed to create jmlist (status=%d)",jmls);
		
		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		wvctl_free_keyboard_cbl_lock();
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	dbgprint(MOD_WVIEWCTL,__func__,"created jmlist for mouse callback list successfully (jml=%p)",mouse_cbl);
	dbgprint(MOD_WVIEWCTL,__func__,"creating wlock for mouse callback list");

	ws = wlock_create(&mouse_cbl_lock);
	if( ws != WSTATUS_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"wlock creation failed for mouse callback list");

		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		wvctl_free_keyboard_cbl_lock();
		wvctl_free_mouse_cbl();
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	jmlp.flags = JMLIST_LINKED;
	dbgprint(MOD_WVIEWCTL,__func__,"creating jmlist for draw callback list");
	jmls = jmlist_create(&draw_cbl,&jmlp);
	if( jmls != JMLIST_ERROR_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"failed to create jmlist (status=%d)",jmls);
		
		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		wvctl_free_keyboard_cbl_lock();
		wvctl_free_mouse_cbl();
		wvctl_free_mouse_cbl_lock();
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	dbgprint(MOD_WVIEWCTL,__func__,"created jmlist for draw callback list successfully (jml=%p)",mouse_cbl);
	dbgprint(MOD_WVIEWCTL,__func__,"creating wlock for draw callback list");

	ws = wlock_create(&draw_cbl_lock);
	if( ws != WSTATUS_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"wlock creation failed for draw callback list");

		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		wvctl_free_keyboard_cbl_lock();
		wvctl_free_mouse_cbl();
		wvctl_free_mouse_cbl_lock();
		wvctl_free_draw_cbl();
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	/* if the load structure is not initialized, it might cause a crash when unloading
	   this module... */
	dbgprint(MOD_WVIEWCTL,__func__,"setting up the exit routine to %p",load.exit_routine);
	exit_routine = load.exit_routine;

	/* Now that the objects are created, create the working thread, wait for it to initialize
	and then return success or failure depending on thread's initialization return status.
	A small hack is used to wait for thread initialization, we loop until a flag is set. */
	thread_init_status tis;
	tis.init_finished_flag = false;
	tis.init_finished_status = 0;
	ws = wthread_create(&wvctl_worker_routine,&tis,&worker_thread);

	if( ws != WSTATUS_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"failed to create working thread");
free_all:
		/* if this has failed, we should free the rest of the objects that were created
		 since the module will have unloaded state. */
		wvctl_free_keyboard_cbl();
		wvctl_free_keyboard_cbl_lock();
		wvctl_free_mouse_cbl();
		wvctl_free_mouse_cbl_lock();
		wvctl_free_draw_cbl();
		wvctl_free_draw_cbl_lock();
		exit_routine = 0; /* cleanup the exit routine */
		DBGRET_FAILURE(MOD_WVIEWCTL);
	}

	dbgprint(MOD_WVIEWCTL,__func__,"working thread was created, waiting for its initialization");

	/* wait for the working thread to initialize */
	while( !tis.init_finished_flag ) sleep(0);

	if( tis.init_finished_status != WSTATUS_SUCCESS ) {
		dbgprint(MOD_WVIEWCTL,__func__,"working thread failed to initialize");
		goto free_all;
	}

	dbgprint(MOD_WVIEWCTL,__func__,"working thread initialized successfully");

	dbgprint(MOD_WVIEWCTL,__func__,"changing module state to 'loaded'");
	wvctl_loaded = true;

	dbgprint(MOD_WVIEWCTL,__func__,"reseting unloading flag to false");
	wvctl_unloading = false;

	/* all went OK */
	DBGRET_SUCCESS(MOD_WVIEWCTL);
}