//--------------------------------------------------------------------------- static void Mutex_Profiling() { K_USHORT i; Mutex_t stMutex; for (i = 0; i < 10; i++) { ProfileTimer_Start( &stMutexInitTimer ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); Mutex_Init( &stMutex ); ProfileTimer_Stop( &stMutexInitTimer ); } for (i = 0; i < 100; i++) { ProfileTimer_Start( &stMutexClaimTimer ); Mutex_Claim( &stMutex ); ProfileTimer_Stop( &stMutexClaimTimer ); ProfileTimer_Start( &stMutexReleaseTimer ); Mutex_Release( &stMutex ); ProfileTimer_Stop( &stMutexReleaseTimer ); } }
void a_main(){ mut1 = Mutex_Init(); mut2 = Mutex_Init(); Task_Create(Task_P1, 1, 0); Task_Create(Task_P2, 2, 0); Task_Create(Task_P3, 3, 0); }
static void TestSuite_RunNamed (TestSuite *suite, /* IN */ const char *testname) /* IN */ { Mutex mutex; char name[128]; Test *test; int count = 1; ASSERT (suite); ASSERT (testname); Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (0 == strcmp (name, testname)) { TestSuite_RunTest (suite, test, &mutex, &count); } } TestSuite_PrintJsonFooter (stdout); if (suite->outfile) { TestSuite_PrintJsonFooter (suite->outfile); } Mutex_Destroy (&mutex); }
void a_main(int parameter) { /* //Place these as necessary to display output if not already doing so inside the RTOS //initialize pins DDRB |= (1<<PB1); //pin 52 DDRB |= (1<<PB2); //pin 51 DDRB |= (1<<PB3); //pin 50 PORTB |= (1<<PB1); //pin 52 on PORTB |= (1<<PB2); //pin 51 on PORTB |= (1<<PB3); //pin 50 on PORTB &= ~(1<<PB1); //pin 52 off PORTB &= ~(1<<PB2); //pin 51 off PORTB &= ~(1<<PB3); //pin 50 off */ mut = Mutex_Init(); evt = Event_Init(); Task_Create(Task_P1, 1, 0); Task_Create(Task_P2, 2, 0); pid = Task_Create(Task_P3, 3, 0); }
static int TestSuite_RunSerial (TestSuite *suite) /* IN */ { Test *test; Mutex mutex; int count = 0; int status = 0; Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { count++; } for (test = suite->tests; test; test = test->next) { status += TestSuite_RunTest (suite, test, &mutex, &count); count--; } TestSuite_PrintJsonFooter (stdout); if (suite->outfile) { TestSuite_PrintJsonFooter (suite->outfile); } Mutex_Destroy (&mutex); return status; }
static void TestSuite_RunSerial (TestSuite *suite) /* IN */ { Test *test; Mutex mutex; int count = 0; Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { count++; } for (test = suite->tests; test; test = test->next) { TestSuite_RunTest (suite, test, &mutex, &count); count--; } TestSuite_PrintJsonFooter (stdout); if (suite->outfile && !suite->generatexmlreport) { TestSuite_PrintJsonFooter (suite->outfile); } Mutex_Destroy (&mutex); }
/* * Create a cache of filesystem buffers. */ struct FS_Buffer_Cache *Create_FS_Buffer_Cache(struct Block_Device *dev, uint_t fsBlockSize) { struct FS_Buffer_Cache *cache; KASSERT(dev != 0); KASSERT(dev->inUse); /* * Currently, we don't allow filesystem blocks * larger than the hardware page size. */ KASSERT(fsBlockSize <= PAGE_SIZE); cache = (struct FS_Buffer_Cache *)Malloc(sizeof(*cache)); if (cache == 0) return 0; cache->dev = dev; cache->fsBlockSize = fsBlockSize; cache->numCached = 0; Clear_FS_Buffer_List(&cache->bufferList); Mutex_Init(&cache->lock); Cond_Init(&cache->cond); return cache; }
int Create_Semaphore(char* name, int ival) { struct Semaphore* sema = (&s_semaphoreList)->head; static ulong_t sid = 1; //find sem by sname while (sema != 0) { if (strcmp(sema->name, name) == 0) { //Print("exist sema->name: %s, %d\n", sema->name, sema->sid); return sema->sid; } sema = Get_Next_In_Semaphore_List(sema); } //if there is no sem, create sem sema = (struct Semaphore*)Malloc(sizeof(struct Semaphore)); sema->sid = sid++; memcpy(sema->name, name, 25); sema->count = ival; //sema->refCount = 1; Mutex_Init(&(sema->mutex)); Cond_Init(&(sema->cond)); Add_To_Back_Of_Semaphore_List(&s_semaphoreList, sema); //Print("new sema->name: %s, %d\n", sema->name, sema->sid); return sema->sid; }
VOID ITaskQ_Init (ITaskQ *pThis, String pSigName, String pSemName, UINT16 nNumQNodes) { Signal_Init(&pThis->oWrite, pSigName); Mutex_Init(&pThis->oLock, pSemName, 1); FIFO_Init(&pThis->oQ, nNumQNodes); pThis->pRead = &pThis->oWrite; }
void a_main(){ DDRB = 0xF0; PORTB = 0x00; mut = Mutex_Init(); evt = Event_Init(); _delay_ms(4000); Task_Create(Task_P1, 1, 0); Task_Create(Task_P2, 2, 0); Task_Create(Task_P3, 3, 0); Task_Create(Task_P4, 10, 0); }
static void TestSuite_RunParallel (TestSuite *suite) /* IN */ { ParallelInfo *info; Thread *threads; Mutex mutex; Test *test; int count = 0; int i; ASSERT (suite); Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { count++; } threads = calloc (count, sizeof *threads); Memory_Barrier (); for (test = suite->tests, i = 0; test; test = test->next, i++) { info = calloc (1, sizeof *info); info->suite = suite; info->test = test; info->count = &count; info->mutex = &mutex; Thread_Create (&threads [i], TestSuite_ParallelWorker, info); } for (test = suite->tests, i = 0; test; test = test->next, i++) { Thread_Join(threads [i]); } /*if (timeout < 0 || timeout > 600) { timeout = 60; } #ifdef _WIN32 Sleep (timeout * 1000); #else sleep (timeout); #endif */ //fprintf (stderr, "Timed out, aborting!\n"); //abort (); }
/** **************************************************** * \fn void TPOS_Init(void) **************************************************** */ void TPOS_Init(void) { Thread *th; uint16_t i; Thread_Current()->next = NULL; EV_Init(&Thread_Current()->wakeEvent,TPos_ThreadWake,Thread_Current()); for(i = 1; i < THREAD_POOL_SIZE; i++) { th = Thread_Alloc(); Thread_Init(th,EV_Loop); th->next = unusedqHead; unusedqHead = th; EV_Init(&th->wakeEvent,TPos_ThreadWake,th); } Mutex_Init(&testRSema); }
//--------------------------------------------------------------------------- int main(void) { // See the annotations in previous labs for details on init. Kernel_Init(); Thread_Init( &stApp1Thread, awApp1Stack, APP1_STACK_SIZE, 1, App1Main, 0); Thread_Init( &stApp2Thread, awApp2Stack, APP2_STACK_SIZE, 1, App2Main, 0); Thread_Start( &stApp1Thread ); Thread_Start( &stApp2Thread ); // Initialize the mutex used in this example. Mutex_Init( &stMyMutex ); Kernel_Start(); return 0; }
void a_main() { mut1 = Mutex_Init(); Task_Create(Task_P1, 1, 0); Task_Create(Task_P2, 2, 0); Task_Create(Idle, MINPRIORITY, 0); disable_LED(PORTL0); disable_LED(PORTL2); disable_LED(PORTL5); disable_LED(PORTL6); enable_LED(PORTL0); disable_LED(PORTL0); Task_Terminate(); }
static int TestSuite_RunNamed (TestSuite *suite, /* IN */ const char *testname) /* IN */ { Mutex mutex; char name[128]; Test *test; int count = 1; bool star = strlen (testname) && testname[strlen (testname) - 1] == '*'; bool match; int status = 0; ASSERT (suite); ASSERT (testname); Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (star) { /* e.g. testname is "/Client*" and name is "/Client/authenticate" */ match = (0 == strncmp (name, testname, strlen (testname) - 1)); } else { match = (0 == strcmp (name, testname)); } if (match) { status += TestSuite_RunTest (suite, test, &mutex, &count); } } TestSuite_PrintJsonFooter (stdout); if (suite->outfile) { TestSuite_PrintJsonFooter (suite->outfile); } Mutex_Destroy (&mutex); return status; }
static void TestSuite_RunParallel (TestSuite *suite) /* IN */ { ParallelInfo *info; Thread *threads; Mutex mutex; Test *test; int count = 0; int i; ASSERT (suite); Mutex_Init (&mutex); for (test = suite->tests; test; test = test->next) { count++; } threads = (Thread *)calloc (count, sizeof *threads); Memory_Barrier (); for (test = suite->tests, i = 0; test; test = test->next, i++) { info = (ParallelInfo *)calloc (1, sizeof *info); info->suite = suite; info->test = test; info->count = &count; info->mutex = &mutex; Thread_Create (&threads [i], TestSuite_ParallelWorker, info); } #ifdef _WIN32 Sleep (30000); #else sleep (30); #endif _Print_StdErr ("Timed out, aborting!\n"); abort (); }
void a_main() { mut = Mutex_Init(); evt = Event_Init(); Task_Create(Task_P1, 1, 0); Task_Create(Task_P2, 2, 0); Task_Create(Task_P3, 3, 0); Task_Create(Idle, 10, 0); disable_LED(PORTL0); disable_LED(PORTL2); disable_LED(PORTL5); disable_LED(PORTL6); enable_LED(PORTL0); disable_LED(PORTL0); Task_Terminate(); }
/* * Mount function for PFAT filesystem. */ static int PFAT_Mount(struct Mount_Point *mountPoint) { struct PFAT_Instance *instance = 0; bootSector *fsinfo; void *bootSect = 0; int rootDirSize; int rc; int i; /* Allocate instance. */ instance = (struct PFAT_Instance*) Malloc(sizeof(*instance)); if (instance == 0) goto memfail; memset(instance, '\0', sizeof(*instance)); fsinfo = &instance->fsinfo; Debug("Created instance object\n"); /* * Allocate buffer to read bootsector, * which contains metainformation about the PFAT filesystem. */ bootSect = Malloc(SECTOR_SIZE); if (bootSect == 0) goto memfail; /* Read boot sector */ if ((rc = Block_Read(mountPoint->dev, 0, bootSect)) < 0) goto fail; Debug("Read boot sector\n"); /* Copy filesystem parameters from boot sector */ memcpy(&instance->fsinfo, ((char*)bootSect) + PFAT_BOOT_RECORD_OFFSET, sizeof(bootSector)); Debug("Copied boot record\n"); /* Does magic number match? */ if (fsinfo->magic != PFAT_MAGIC) { Print("Bad magic number (%x) for PFAT filesystem\n", fsinfo->magic); goto invalidfs; } Debug("Magic number is good!\n"); /* Do filesystem params look reasonable? */ if (fsinfo->fileAllocationOffset <= 0 || fsinfo->fileAllocationLength <= 0 || fsinfo->rootDirectoryCount < 0 || fsinfo->rootDirectoryOffset <= 0) { Print("Invalid parameters for PFAT filesystem\n"); goto invalidfs; } Debug("PFAT filesystem parameters appear to be good!\n"); /* Allocate in-memory FAT */ instance->fat = (int*) Malloc(fsinfo->fileAllocationLength * SECTOR_SIZE); if (instance->fat == 0) goto memfail; /* Read the FAT */ for (i = 0; i < fsinfo->fileAllocationLength; ++i) { int blockNum = fsinfo->fileAllocationOffset + i; char *p = ((char*)instance->fat) + (i * SECTOR_SIZE); if ((rc = Block_Read(mountPoint->dev, blockNum, p)) < 0) goto fail; } Debug("Read FAT successfully!\n"); /* Allocate root directory */ rootDirSize = Round_Up_To_Block(sizeof(directoryEntry) * fsinfo->rootDirectoryCount); instance->rootDir = (directoryEntry*) Malloc(rootDirSize); /* Read the root directory */ Debug("Root directory size = %d\n", rootDirSize); for (i = 0; i < rootDirSize; i += SECTOR_SIZE) { int blockNum = fsinfo->rootDirectoryOffset + i; if ((rc = Block_Read(mountPoint->dev, blockNum, instance->rootDir + (i*SECTOR_SIZE))) < 0) goto fail; } Debug("Read root directory successfully!\n"); /* Create the fake root directory entry. */ memset(&instance->rootDirEntry, '\0', sizeof(directoryEntry)); instance->rootDirEntry.readOnly = 1; instance->rootDirEntry.directory = 1; instance->rootDirEntry.fileSize = instance->fsinfo.rootDirectoryCount * sizeof(directoryEntry); /* Initialize instance lock and PFAT_File list. */ Mutex_Init(&instance->lock); Clear_PFAT_File_List(&instance->fileList); /* Attempt to register a paging file */ PFAT_Register_Paging_File(mountPoint, instance); /* * Success! * This mount point is now ready * to handle file accesses. */ mountPoint->ops = &s_pfatMountPointOps; mountPoint->fsData = instance; return 0; memfail: rc = ENOMEM; goto fail; invalidfs: rc = EINVALIDFS; goto fail; fail: if (instance != 0) { if (instance->fat != 0) Free(instance->fat); if (instance->rootDir != 0) Free(instance->rootDir); Free(instance); } if (bootSect != 0) Free(bootSect); return rc; }
/* * Get a PFAT_File object representing the file whose directory entry * is given. */ static struct PFAT_File *Get_PFAT_File(struct PFAT_Instance *instance, directoryEntry *entry) { ulong_t numBlocks; struct PFAT_File *pfatFile = 0; char *fileDataCache = 0; struct Bit_Set *validBlockSet = 0; KASSERT(entry != 0); KASSERT(instance != 0); Mutex_Lock(&instance->lock); /* * See if this file has already been opened. * If so, use the existing PFAT_File object. */ for (pfatFile = Get_Front_Of_PFAT_File_List(&instance->fileList); pfatFile != 0; pfatFile = Get_Next_In_PFAT_File_List(pfatFile)) { if (pfatFile->entry == entry) break; } if (pfatFile == 0) { /* Determine size of data block cache for file. */ numBlocks = Round_Up_To_Block(entry->fileSize) / SECTOR_SIZE; /* * Allocate File object, PFAT_File object, file block data cache, * and valid cache block bitset */ if ((pfatFile = (struct PFAT_File *) Malloc(sizeof(*pfatFile))) == 0 || (fileDataCache = Malloc(numBlocks * SECTOR_SIZE)) == 0 || (validBlockSet = Create_Bit_Set(numBlocks)) == 0) { goto memfail; } /* Populate PFAT_File */ pfatFile->entry = entry; pfatFile->numBlocks = numBlocks; pfatFile->fileDataCache = fileDataCache; pfatFile->validBlockSet = validBlockSet; Mutex_Init(&pfatFile->lock); /* Add to instance's list of PFAT_File objects. */ Add_To_Back_Of_PFAT_File_List(&instance->fileList, pfatFile); KASSERT(pfatFile->nextPFAT_File_List == 0); } /* Success! */ goto done; memfail: if (pfatFile != 0) Free(pfatFile); if (fileDataCache != 0) Free(fileDataCache); if (validBlockSet != 0) Free(validBlockSet); done: Mutex_Unlock(&instance->lock); return pfatFile; }
static void global_mutex_init() { Mutex_Init(&mutex); }