Esempio n. 1
0
void Task_P2()
{
    Mutex_Lock(mut1);
    Task_Sleep(20);
    Mutex_Lock(mut2);
    Task_Sleep(10);
    Mutex_Unlock(mut2);
    Mutex_Unlock(mut1);
    for(;;);
}
Esempio n. 2
0
static int
MksckBindGeneric(struct sock *sk,
		 Mksck_Address addr)
{
	int err;
	Mksck *mksck;
	struct MksckPage *mksckPage;

	if (sk->sk_protinfo != NULL)
		return -EISCONN;

	if (addr.vmId == MKSCK_VMID_UNDEF) {
		mksckPage = MksckPage_GetFromTgidIncRefc();
	} else {
		pr_err("MksckBind: host bind called on vmid 0x%X\n", addr.vmId);
		mksckPage = MksckPage_GetFromVmIdIncRefc(addr.vmId);
	}

	if (mksckPage == NULL) {
		pr_err("MksckBind: no mksckPage for vm 0x%X\n", addr.vmId);
		return -ENETUNREACH;
	}
	addr.vmId = mksckPage->vmId;

	err = Mutex_Lock(&mksckPage->mutex, MutexModeEX);
	if (err < 0)
		goto outDec;

	addr.port = MksckPage_GetFreePort(mksckPage, addr.port);
	if (addr.port == MKSCK_PORT_UNDEF) {
		err = -EINVAL;
		goto outUnlockDec;
	}

	mksck = MksckPage_AllocSocket(mksckPage, addr);
	if (mksck == NULL) {
		err = -EMFILE;
		goto outUnlockDec;
	}

	Mutex_Unlock(&mksckPage->mutex, MutexModeEX);

	sk->sk_protinfo = mksck;

	PRINTK("MksckBind: socket bound to %08X\n",
	       mksck->addr.addr);

	return 0;

outUnlockDec:
	Mutex_Unlock(&mksckPage->mutex, MutexModeEX);
outDec:
	MksckPage_DecRefc(mksckPage);
	return err;
}
void Task_P1()
{
    Mutex_Lock(mut1);
    Mutex_Lock(mut1);
    
    Task_Sleep(5);

    Mutex_Unlock(mut1);
    Mutex_Unlock(mut1);

    Task_Sleep(5);

    for(;;){
    }
}
//#pragma CODE_SECTION(ITaskQ_Write,".textDDR")
VOID ITaskQ_Write(ITaskQ *pThis, VOID *pVal)
{
	Mutex_Lock(&pThis->oLock);
	FIFO_Put(&pThis->oQ, pVal);
	Signal_Post(&pThis->oWrite);
	Mutex_Unlock(&pThis->oLock);
}
Esempio n. 5
0
void* listenerThreadFunc(void* data) {
	char filepath[1000], uuidStr[36], filetype[40], line[1100];
	struct FileDefinition * f;
	uuid_t uuid;
	char c;

	while (true) {
		memset(filepath, '\0', 1000);
		memset(uuidStr, '\0', 36);
		memset(filetype, '\0', 40);
		memset(line, '\0', 1100);


		if (fgets(line, 1100, stdin) != NULL) {
			sscanf(line, "--uuid=%s --type=%s --file=%s\n", uuidStr, filetype, filepath);
			//printf("GOT: line=%s PARSED TO: --uuid=%s --type=%s --file=%s\n", line, uuidStr, filetype, filepath);
		}
		if ( strlen(filepath) > 0 ) {
			if (strcmp(uuidStr, "none") != 0)
				 uuid_parse(uuidStr, uuid);
			else if (strcmp(filetype, "none") != 0)
				 UUID_Get_UUID(filetype, UUID_TYPE_DATA_TYPE, uuid);
			else
				uuid_parse("0", uuid);

			f = createFileDefinition(filepath, uuid);
			Mutex_Lock(mutex);
			pushFileList(f);
			Mutex_Unlock(mutex);
		} else {
			usleep(500000);
		}
	}
	return NULL;
}
/**
 * @brief Unlock the mutex and prepare to sleep on a kernel polling table
 *        given as anonymous parameters for poll_wait
 * @param mutex as passed to Mutex_Lock()
 * @param mode  as passed to Mutex_Lock()
 * @param cvi   which condition variable to sleep on
 * @param filp  which file to poll_wait upon
 * @param wait  which poll_table to poll_wait upon
 */
void
Mutex_UnlPoll(Mutex *mutex,
	      MutexMode mode,
	      uint32 cvi,
	      void *filp,
	      void *wait)
{
	ASSERT(cvi < MUTEX_CVAR_MAX);

	 /* poll_wait is done with mutex locked to prevent any wake that comes
	 * and defer them just after we unlock the mutex but before kernel
	 * polling tables are used. Note that the kernel is probably avoiding
	 * an exclusive wait in that case and also increments the usage for
	 * the file given in filp.
	 */
	poll_wait(filp, (wait_queue_head_t *)mutex->cvarWaitQs[cvi], wait);

	/*
	 * Tell anyone who might try to wake us that they need to actually call
	 * WAKEUP***(). This is done in putting ourselves in a "noisy" mode
	 * since there is no guaranty that we would really sleep, or if we
	 * would be wakening the sleeping thread with that socket or condition.
	 * This is done using a POLL_IN_PROGRESS_FLAG, but unfortunately it
	 * has to be a per-cvi flag, in case we would poll independently on
	 * different cvi.
	 */
	DMB();
	ATOMIC_ORO(mutex->waiters, (POLL_IN_PROGRESS_FLAG << cvi));

	/*
	 * Release the mutex, someone can wake us up now.
	 * They will see mutex->waiters non-zero so will actually do the wake.
	 */
	Mutex_Unlock(mutex, mode);
}
Esempio n. 7
0
/*
 * Destroy a filesystem buffer cache.
 * None of the buffers in the cache must be in use.
 * The cache must not be used after this function returns!
 */
int Destroy_FS_Buffer_Cache(struct FS_Buffer_Cache *cache) {
    int rc;
    struct FS_Buffer *buf;

    Mutex_Lock(&cache->lock);

    /* Flush all contents back to disk. */
    rc = Sync_Cache(cache);

    /* Free all of the buffers. */
    buf = Get_Front_Of_FS_Buffer_List(&cache->bufferList);
    while (buf != 0) {
        struct FS_Buffer *next = Get_Next_In_FS_Buffer_List(buf);
        Free_Buffer(buf);
        buf = next;
    }
    Clear_FS_Buffer_List(&cache->bufferList);

    Mutex_Unlock(&cache->lock);

    /* Free the cache object itself. */
    Free(cache);

    return rc;
}
Esempio n. 8
0
void Task_P3(int parameter)
{
	Mutex_Lock(mut);
	Task_Suspend(pid);
	Mutex_Unlock(mut);
    for(;;);
}
Esempio n. 9
0
/*
 * Register a filesystem.
 * This should only be called from Main(), before
 * any processes are started.
 * Params:
 *   fsName - name of the filesystem type, e.g. "pfat", "gosfs"
 *   fsOps - the Filesystem_Ops for the filesystem
 * Returns true if successful, false if not.
 */
bool Register_Filesystem(const char *fsName, struct Filesystem_Ops *fsOps)
{
    struct Filesystem *fs;

    KASSERT(fsName != 0);
    KASSERT(fsOps != 0);
    KASSERT(fsOps->Mount != 0);

    Debug("Registering %s filesystem type\n", fsName);

    /* Allocate Filesystem struct */
    fs = (struct Filesystem*) Malloc(sizeof(*fs));
    if (fs == 0)
	return false;

    /* Copy filesystem name and vtable. */
    fs->ops = fsOps;
    strncpy(fs->fsName, fsName, VFS_MAX_FS_NAME_LEN);
    fs->fsName[VFS_MAX_FS_NAME_LEN] = '\0';

    /* Add the filesystem to the list */
    Mutex_Lock(&s_vfsLock);
    Add_To_Back_Of_Filesystem_List(&s_filesystemList, fs);
    Mutex_Unlock(&s_vfsLock);

    return true;
}
Esempio n. 10
0
void Task_P1()
{
    Task_Sleep(30);
    Mutex_Lock(mut1);
    Mutex_Unlock(mut1);
    for(;;);
}
void Task_P3(int parameter)
{
    Mutex_Lock(mut);
    Event_Wait(evt);
    Mutex_Unlock(mut);
    for(;;);
}
Esempio n. 12
0
int P(int sid)
{
	struct Semaphore* sema = (&s_semaphoreList)->head;
	struct Mutex* mutex;
	struct Condition* cond;

	//find sem by sid
	while (sema != 0)
	{
		if (sema->sid == sid)
		{
			mutex = &(sema->mutex); // important
			cond = &(sema->cond);

			Enable_Interrupts();
			Mutex_Lock(mutex);
			while(sema->count <= 0)
			{
				Cond_Wait(cond, mutex);
				//Print("WAKE UP!");
			}
			sema->count--;
			Mutex_Unlock(mutex);
			Disable_Interrupts();
			
			return 0;
		}
		sema = Get_Next_In_Semaphore_List(sema);
	}
	
	return -1;
}
Esempio n. 13
0
int V(int sid)
{
	struct Semaphore* sema = (&s_semaphoreList)->head;
	struct Mutex* mutex;
	struct Condition* cond;

	//find sem by sid
	while (sema != 0)
	{
		if (sema->sid == sid)
		{
			mutex = &(sema->mutex);
			cond = &(sema->cond);
			
			Enable_Interrupts();
			Mutex_Lock(mutex);
			sema->count = sema->count + 1;
			//Print("wait queue : %d", cond->waitQueue);
			Cond_Broadcast(cond);
			Mutex_Unlock(mutex);
			Disable_Interrupts();
			
			return 0;
		}
		sema = Get_Next_In_Semaphore_List(sema);
	}
	
	return -1;
}
Esempio n. 14
0
TEST(MutexTest,RecursiveLockFails)
{ Mutex *m = Mutex_Alloc();
  ASSERT_NE(m,(void*)NULL);
  Mutex_Lock(m);
  ASSERT_DEATH(Mutex_Lock(m),"Detected an attempt to recursively acquire a mutex.*");
  Mutex_Unlock(m);
  Mutex_Free(m);
}
// return NULL data if data is not available
VOID *ITaskQ_ReadNoBlock( ITaskQ *pThis )
{
	VOID *pVal;
	Mutex_Lock(&pThis->oLock);
	pVal = FIFO_Get(&pThis->oQ);
	Mutex_Unlock(&pThis->oLock);
	return pVal;
}
/**
 * @brief Unlock the mutex and sleep.  Also does a data barrier before
 *        unlocking so any modifications made before the lock gets released
 *        will be completed before the lock is released.
 * @param mutex as passed to Mutex_Lock()
 * @param mode  as passed to Mutex_Lock()
 * @param cvi   which condition variable to sleep on
 * @param test  sleep only if null or pointed atomic value mismatches mask
 * @param mask  bitfield to check test against before sleeping
 * @param file the file of the caller code
 * @param line the line number of the caller code
 * @return rc = 0: successfully waited<br>
 *            < 0: error waiting
 */
int
Mutex_UnlSleepTestLine(Mutex *mutex,
		       MutexMode mode,
		       uint32 cvi,
		       AtmUInt32 *test,
		       uint32 mask,
		       const char *file,
		       int line)
{
	DEFINE_WAIT(waiter);

	MutexCheckSleep(file, line);

	ASSERT(cvi < MUTEX_CVAR_MAX);

	/*
	 * Tell anyone who might try to wake us that they need to actually call
	 * WAKEUP***().
	 */
	ATOMIC_ADDV(mutex->waiters, 1);

	/*
	 * Be sure to catch any wake that comes along just after we unlock the
	 * mutex but before we call schedule().
	 */
	prepare_to_wait_exclusive((wait_queue_head_t *)mutex->cvarWaitQs[cvi],
				  &waiter,
				  TASK_INTERRUPTIBLE);

	/*
	 * Release the mutex, someone can wake us up now.
	 * They will see mutex->waiters non-zero so will actually do the wake.
	 */
	Mutex_Unlock(mutex, mode);

	/*
	 * Wait to be woken or interrupted.
	 */
	if (test == NULL || (ATOMIC_GETO(*test) & mask) == 0)
		schedule();
	finish_wait((wait_queue_head_t *)mutex->cvarWaitQs[cvi], &waiter);

	/*
	 * Done waiting, don't need a wake any more.
	 */
	ATOMIC_SUBV(mutex->waiters, 1);

	/*
	 * If interrupted, return error status.
	 */
	if (signal_pending(current))
		return -ERESTARTSYS;

	/*
	 * Wait completed, return success status.
	 */
	return 0;
}
Esempio n. 17
0
/*
 * Synchronize contents of cache with the disk
 * by writing out all dirty buffers.
 */
int Sync_FS_Buffer_Cache(struct FS_Buffer_Cache *cache) {
    int rc;

    Mutex_Lock(&cache->lock);
    rc = Sync_Cache(cache);
    Mutex_Unlock(&cache->lock);

    return rc;
}
/**
 * @brief Unlock the semaphore and wake sleeping threads.  Also does a data
 *        barrier before unlocking so any modifications made before the lock
 *        gets released will be completed before the lock is released.
 * @param mutex as passed to Mutex_Lock()
 * @param mode  as passed to Mutex_Lock()
 * @param cvi   which condition variable to signal
 * @param all   false: wake a single thread<br>
 *              true: wake all threads
 */
void
Mutex_UnlWake(Mutex *mutex,
	      MutexMode mode,
	      uint32 cvi,
	      _Bool all)
{
	Mutex_Unlock(mutex, mode);
	Mutex_CondSig(mutex, cvi, all);
}
Esempio n. 19
0
/*
   PROGRAM:  Philosopher
   A program that simulates a philosopher participating in a dining philosophers'
   symposium. Each philosopher will join the symposium, alternating between
   thinking, going hungry and eating a bite, for a number of bites. After he
   has eaten the last bite, he leaves.
*/
int Philosopher(int argl, void* args)
{
    int i,j;
    int bites;			/* Number of bites (mpoykies) */

    assert(argl == sizeof(int[2]));
    i = ((int*)args)[0];
    bites = ((int*)args)[1];

    Mutex_Lock(&mx);		/* Philosopher arrives in thinking state */
    state[i] = THINKING;
    print_state("     %d has arrived\n",i);
    Mutex_Unlock(&mx);

    for(j=0; j<bites; j++) {

        think(i);			/* THINK */

        Mutex_Lock(&mx);		/* GO HUNGRY */
        state[i] = HUNGRY;
        trytoeat(i);		/* This may not succeed */
        while(state[i]==HUNGRY) {
            print_state("     %d waits hungry\n",i);
            Cond_Wait(&mx, &(hungry[i])); /* If hungry we sleep. trytoeat(i) will wake us. */
        }
        assert(state[i]==EATING);
        Mutex_Unlock(&mx);

        eat(i);			/* EAT */

        Mutex_Lock(&mx);
        state[i] = THINKING;	/* We are done eating, think again */
        print_state("     %d is thinking\n",i);
        trytoeat(LEFT(i));		/* Check if our left and right can eat NOW. */
        trytoeat(RIGHT(i));
        Mutex_Unlock(&mx);
    }
    Mutex_Lock(&mx);
    state[i] = NOTHERE;		/* We are done (eaten all the bites) */
    print_state("     %d is leaving\n",i);
    Mutex_Unlock(&mx);

    return i;
}
Esempio n. 20
0
/*
 * Get a buffer for given filesystem block.
 */
int Get_FS_Buffer(struct FS_Buffer_Cache *cache, ulong_t fsBlockNum,
                  struct FS_Buffer **pBuf) {
    int rc;

    Mutex_Lock(&cache->lock);
    rc = Get_Buffer(cache, fsBlockNum, pBuf);
    Mutex_Unlock(&cache->lock);

    return rc;
}
Esempio n. 21
0
/*
 * Explicitly synchronize given buffer with its on-disk storage,
 * without releasing the buffer.
 */
int Sync_FS_Buffer(struct FS_Buffer_Cache *cache, struct FS_Buffer *buf) {
    int rc;

    KASSERT(buf->flags & FS_BUFFER_INUSE);

    Mutex_Lock(&cache->lock);
    rc = Sync_Buffer(cache, buf);
    Mutex_Unlock(&cache->lock);

    return rc;
}
Esempio n. 22
0
/**
 *********************************************************************************
 * \fn static void RSema_Test(void);
 *
 *********************************************************************************
 */
static void
RSema_Test(void) 
{
	Timer_Start(&tmrRSemaToggle,0);
	SleepMs(100);
	Timer_Start(&tmrRSemaToggle,4000);
	Con_Printf_P("Trying to lock rsema\n");
	Mutex_Lock(&testRSema);
	Con_Printf_P("Success, Unlocking rsema\n");
	Mutex_Unlock(&testRSema);
}
Esempio n. 23
0
void output_report(TestSuite *suite)
{
    pthread_once(&global_mutxt_once, global_mutex_init);
    Mutex_Lock(&mutex);
    if (suite->outfile) {
        if (suite->generatexmlreport){
            TestSuite_PrintXmlFooter (suite, suite->outfile);
            suite->generatexmlreport = false;
         }
    }
    Mutex_Unlock(&mutex);
}
Esempio n. 24
0
/*
 * client_init handles multiple threaded connects. It creates
 * a listener object if either the dual test or tradeoff were
 * specified. It also creates settings structures for all the
 * threads and arranges them so they can be managed and started
 * via the one settings structure that was passed in.
 */
void client_init( thread_Settings *clients ) {
    thread_Settings *itr = NULL;
    thread_Settings *list = NULL;
    thread_Settings *next = NULL;

    // Set the first thread to report Settings (except cli side Reverse)
    setReport( clients );
    if (clients->mMode == kTest_Reverse && !isOnServer(clients)) {
      unsetReport( clients );
    }
    itr = clients;

    // See if we need to start a listener as well
    Settings_GenerateListenerSettings( clients, &list );

    // Create a multiple report header to handle reporting the
    // sum of multiple client threads
    Mutex_Lock( &groupCond );
    groupID--;
    clients->multihdr = InitMulti( clients, groupID );
    Mutex_Unlock( &groupCond );

#ifdef HAVE_THREAD
    if ( list != NULL && !isNAT(list)) {
        // We have threads and we need to start a listener so
        // have it ran before the client is launched (unless behind NAT)
        itr->runNow = list;
        itr = list;
    }
#endif
    // For each of the needed threads create a copy of the
    // provided settings, unsetting the report flag and add
    // to the list of threads to start
    for (int i = 1; i < clients->mThreads; i++) {
        Settings_Copy( clients, &next );
        unsetReport( next );
        itr->runNow = next;
        itr = next;
    }
#ifndef HAVE_THREAD
    if ( list != NULL ) {
        // We don't have threads and we need to start a listener so
        // have it ran after the client is finished
        itr->runNext = list;
    }
#else
    if ( list != NULL && isNAT(list) ) {
        // We have threads and we need to start a listener so
        // have it ran after the client is launched (when behind NAT)
        itr->runNext = list;
    }
#endif
}
Esempio n. 25
0
void* inc(void *a)
{ counter *c=(counter*)a;
  int v;
  Mutex_Lock(c->lock);
  v=c->n;
  v++;
  pause_random_10ms(NULL);  
  pause_random_10ms(NULL);
  c->n = v;
	Mutex_Unlock(c->lock);
  return 0;
}
Esempio n. 26
0
static void
RSemaTestEvProc(void *evData) 
{
	static uint8_t toggle = false;
	toggle = !toggle;
	Con_Printf_P("RSemaTestTimer %08lx %d\n",Thread_Current(),toggle);
	if(toggle == true) {
		Mutex_Lock(&testRSema);
	} else {
		Mutex_Unlock(&testRSema);
	}
}
VOID *ITaskQ_Read( ITaskQ *pThis )
{

	VOID *pVal;
	Mutex_Lock(&pThis->oLock);
	pVal = FIFO_Get(&pThis->oQ);
	
	while( pVal == NULL )
	{
		Mutex_Unlock(&pThis->oLock);
		Signal_Pend(pThis->pRead);
		Mutex_Lock(&pThis->oLock);
		pVal = FIFO_Get(&pThis->oQ);
		
	}
	
	Mutex_Unlock(&pThis->oLock);
	return pVal;


}
Esempio n. 28
0
void
Mksck_DecRefc(Mksck *mksck)
{
	uint32 oldRefc;

	DMB();
	do {
		while ((oldRefc = ATOMIC_GETO(mksck->refCount)) == 1) {
			MksckPage *mksckPage = Mksck_ToSharedPage(mksck);


			while (Mutex_Lock(&mksckPage->mutex, MutexModeEX) < 0)
				;

			if (ATOMIC_SETIF(mksck->refCount, 0, 1)) {
#if 0
				KNOWN_BUG(MVP-1349);
				PRINTK("Mksck_DecRefc: %08X " \
				       "shutDown %u, foundEmpty %u, " \
				       "foundFull %u, blocked %u\n",
				       mksck->addr.addr, mksck->shutDown,
				       mksck->foundEmpty, mksck->foundFull,
				       ATOMIC_GETO(mksck->mutex.blocked));
#endif

				ASSERT(mksck->peer == 0);

				Mutex_Unlock(&mksckPage->mutex, MutexModeEX);
				MksckPage_DecRefc(mksckPage);
				return;
			}

			Mutex_Unlock(&mksckPage->mutex, MutexModeEX);
		}

		 ASSERT(oldRefc != 0);
	} while (!ATOMIC_SETIF(mksck->refCount, oldRefc - 1, oldRefc));
}
Esempio n. 29
0
void Task_P3(){
    PORTB   = 0x40;
    _delay_ms(10);
    PORTB   = 0x00;

    Mutex_Lock(mut);
    Event_Wait(evt);

    PORTB   = 0x40;
    _delay_ms(10);
    PORTB   = 0x00;

    Mutex_Unlock(mut);
    for(;;);
}
Esempio n. 30
0
/*
 * Look up given filesystem type.
 * Params:
 *   fstype - name of the filesystem type
 * Returns: the Filesystem object for the filesystem, or null
 *   if no such filesystem exists.
 */
static struct Filesystem *Lookup_Filesystem(const char *fstype)
{
    struct Filesystem *fs;

    Mutex_Lock(&s_vfsLock);
    fs = Get_Front_Of_Filesystem_List(&s_filesystemList);
    while (fs != 0) {
	if (strcmp(fs->fsName, fstype) == 0)
	    break;
	fs = Get_Next_In_Filesystem_List(fs);
    }
    Mutex_Unlock(&s_vfsLock);

    return fs;
}