コード例 #1
0
mama_status
wombatThrottle_allocate (wombatThrottle *throttle)
{
    wombatThrottleImpl *impl =
        (wombatThrottleImpl*) malloc (sizeof (wombatThrottleImpl));

    if (impl == NULL)
        return (MAMA_STATUS_NOMEM); 
    
    memset (impl, 0, sizeof (wombatThrottleImpl));

    impl->mMsgQueue = list_create (sizeof (MsgProperties));
   
    impl->mInterval = 0.1;

    /* Create the timer lock. */
    impl->mTimerLock = wlock_create ();

    /* dispatchThread wait ()s immediately after creation because 
     * mRate == 0.0  Call setRate () last to signal () it.  
     * setRate () effectively toggles throttle on and off */
    wombatThrottle_setRate (impl, WOMBAT_THROTTLE_DEFAULT_RATE);
    
    *throttle = (wombatThrottle)impl;

    return MAMA_STATUS_OK;
}
コード例 #2
0
 LockImpl ()
     : mLock     (wlock_create ())
     , mIsLocked (false)
 {}
コード例 #3
0
ファイル: wviewctl.c プロジェクト: jemos/wicom
/*
   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);
}