コード例 #1
0
ファイル: ipc.c プロジェクト: wayling/Jiny-Kernel
uint32_t sys_arch_sem_wait(sys_sem_t sem, uint32_t timeout_arg) {
	unsigned long flags;
	unsigned long timeout;

	timeout=timeout_arg*100;
	while (1) {
		if (sem->count <= 0 )
		{
			timeout=sc_wait(&(sem->wait_queue), timeout);
		}
		if (timeout_arg == 0) timeout=100;
		spin_lock_irqsave(&(sem->sem_lock), flags);
		/* Atomically check that we can proceed */
		if (sem->count > 0 || (timeout <= 0))
			break;
	    spin_unlock_irqrestore(&(sem->sem_lock), flags);
	}

	if (sem->count > 0) {
		sem->count--;
	    spin_unlock_irqrestore(&(sem->sem_lock), flags);
		return 1;
	}

    spin_unlock_irqrestore(&(sem->sem_lock), flags);
	return IPC_TIMEOUT;
}
コード例 #2
0
ファイル: agents.c プロジェクト: Prichy/SoundDesk
bool
init_agents()
/*
 * Here we create all of the individual agents
 */
{
	bool	ok;				 /* Status of last operation  */

	agents_sc = sc_init();			 /* Create sync controller    */

	if(!agents_sc)				 /* Failed ?		      */
		return FALSE;

	sc_begin(agents_sc);			 /* Start synchronisation     */

#ifdef DEBUG
	ok = try_each_obj(qsheets, (t_try_obj)db_new_agent,
			GINT_TO_POINTER(atype_cue))
		&& new_agent(NULL, GINT_TO_POINTER(atype_dek), "Decks")
		&& new_agent(NULL, GINT_TO_POINTER(atype_mxr), "Mixers");
#else
	ok = try_each_obj(qsheets, (t_try_obj)new_agent,
			GINT_TO_POINTER(atype_cue))
		&& new_agent(NULL, GINT_TO_POINTER(atype_dek))
		&& new_agent(NULL, GINT_TO_POINTER(atype_mxr));
#endif

	new_am_pool();				 /* Create pool of msg args   */

	sc_ready(agents_sc);			 /* Signal we are ready	      */

	if(ok)					 /* Everything OK?	      */
		sc_wait(agents_sc);		 /* Wait for agents to start  */
	else
	{
		E("Startup failed, killing agents...");
		sc_wait(agents_sc);		 /* Wait for agents to start  */
		term_agents();			 /* Terminate all agents      */
	}

	sc_reset(agents_sc);			 /* Kill sync controller      */

	return ok;
}						 /* init_agents()	      */