示例#1
0
文件: thread.cpp 项目: nclack/chan
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);
}
示例#2
0
void Task_P2()
{
    Mutex_Lock(mut1);
    Task_Sleep(20);
    Mutex_Lock(mut2);
    Task_Sleep(10);
    Mutex_Unlock(mut2);
    Mutex_Unlock(mut1);
    for(;;);
}
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);
}
示例#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;
}
示例#6
0
文件: tcp.c 项目: Agueeva/bert100
INLINE void
_TCB_Lock(Tcb * tcb, uint32_t line)
{
	tcb->tryLockLine = line;
	Mutex_Lock(&tcb->lock);
	tcb->hasLockLine = line;
} 
示例#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;
}
void Task_P2()
{    
    Mutex_Lock(mut1);

    for(;;){
    }
}
示例#9
0
文件: test2.c 项目: cdalong/Project2
void Task_P3(int parameter)
{
	Mutex_Lock(mut);
	Task_Suspend(pid);
	Mutex_Unlock(mut);
    for(;;);
}
示例#10
0
文件: vfs.c 项目: sinabeuro/geekos5
/*
 * 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;
}
示例#11
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(;;);
}
示例#13
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;
}
示例#14
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;
}
// 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;
}
示例#16
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;
}
示例#17
0
文件: mtask.c 项目: skyritsis/tinyos
/*
   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;
}
示例#18
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;
}
示例#19
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;
}
示例#20
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;
}
示例#21
0
文件: tpos.c 项目: Agueeva/bert100
/**
 *********************************************************************************
 * \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);
}
示例#22
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);
}
示例#23
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
}
示例#24
0
文件: thread.cpp 项目: nclack/chan
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;
}
示例#25
0
文件: tpos.c 项目: Agueeva/bert100
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);
	}
}
示例#26
0
文件: tcp.c 项目: Agueeva/bert100
INLINE bool
_TCB_TryLock(Tcb * tcb, uint32_t line)
{
	if (!Mutex_Locked(&tcb->lock)) {
		tcb->tryLockLine = line;
		Mutex_Lock(&tcb->lock);
		tcb->hasLockLine = line;
		return true;
	} else {
		return false;
	}
}
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;


}
示例#28
0
void
Mksck_CloseCommon(Mksck *mksck)
{
	Mksck_DisconnectPeer(mksck);

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

	mksck->shutDown = MKSCK_SHUT_WR | MKSCK_SHUT_RD;
	Mutex_UnlWake(&mksck->mutex, MutexModeEX, MKSCK_CVAR_ROOM, true);

	Mksck_DecRefc(mksck);
}
示例#29
0
void
mt_add_tasks(unsigned int num_tasks, AsyncFun pFun, void *taskData, gpointer linked)
{
    unsigned int i;
    {
#ifdef DEBUG_MULTITHREADED
        char buf[20];
        sprintf(buf, "add %u tasks", num_tasks);
        Mutex_Lock(td.queueLock, buf);
#else
        Mutex_Lock(td.queueLock, NULL);
#endif
    }
    for (i = 0; i < num_tasks; i++) {
        Task *pt = (Task *) malloc(sizeof(Task));
        pt->fun = pFun;
        pt->data = taskData;
        pt->pLinkedTask = linked;
        MT_AddTask(pt, FALSE);
    }
    multi_debug("add many release: lock");
    Mutex_Release(td.queueLock);
}
示例#30
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(;;);
}