// ------------------------------------------------------------------------------------------------- void fjm_Start ( void ) // ------------------------------------------------------------------------------------------------- { LE_TEST_INFO("FJM TESTS START"); memset(TestResults, 0, sizeof(TestResults)); Counter = 0; // Compute the expected ending counter value. ExpectedCounterValue = GetExpectedCounterValue(); // Create semaphore to trigger CounterSemRef = le_sem_Create("CounterSem", 0); // Create the mutex. MutexRef = le_mutex_CreateNonRecursive("fork-join-mutex-test"); // Create the Context Pool. if (ContextPoolRef == NULL) { LE_TEST_INFO("Initializing FJM-ContextPool"); ContextPoolRef = le_mem_CreatePool("FJM-ContextPool", sizeof(Context_t)); le_mem_ExpandPool(ContextPoolRef, ExpectedCounterValue); } // Spawn the first child thread. SpawnChildren(1); }
// This is testing if Mutex_t.waitingList is displayed correctly. // Thread1 successfully locks mutexes 1, 2, and 3, and then Thread 2 and 3 tries to lock mutex 1, and // Thread 4 and 5 tries to lock mutex 3. // Therefore the expected result is that Mutex1's waiting list has Thread2 and 3, Mutex2's waiting // list is empty, and Mutex3's waiting list has Thread4 and 5. void testWaitingList ( void ) { le_mutex_Ref_t mutex1Ref = le_mutex_CreateNonRecursive("Mutex1"); le_mutex_Ref_t mutex2Ref = le_mutex_CreateNonRecursive("Mutex2"); le_mutex_Ref_t mutex3Ref = le_mutex_CreateNonRecursive("Mutex3"); // create mutex arrays to be passed to each thread. le_mutex_Ref_t mutexRefArray1[3] = {mutex1Ref, mutex2Ref, mutex3Ref}; le_mutex_Ref_t mutexRefArray2[1] = {mutex1Ref}; le_mutex_Ref_t mutexRefArray3[1] = {mutex3Ref}; // put the arrays in a data struct containing size MutexRefArray_t mra1 = {NUM_ARRAY_MEMBERS(mutexRefArray1), mutexRefArray1}; MutexRefArray_t mra2 = {NUM_ARRAY_MEMBERS(mutexRefArray2), mutexRefArray2}; MutexRefArray_t mra3 = {NUM_ARRAY_MEMBERS(mutexRefArray3), mutexRefArray3}; // create thread refs le_thread_Ref_t thread1Ref = le_thread_Create("Thread1", LockMutex, (void*)&mra1); le_thread_Ref_t thread2Ref = le_thread_Create("Thread2", LockMutex, (void*)&mra2); le_thread_Ref_t thread3Ref = le_thread_Create("Thread3", LockMutex, (void*)&mra2); le_thread_Ref_t thread4Ref = le_thread_Create("Thread4", LockMutex, (void*)&mra3); le_thread_Ref_t thread5Ref = le_thread_Create("Thread5", LockMutex, (void*)&mra3); // start the threads le_thread_Start(thread1Ref); // Do not proceed untiil Thread1 has gotten all the mutex locks le_sem_Wait(SemaRef); le_thread_Start(thread2Ref); le_thread_Start(thread3Ref); le_thread_Start(thread4Ref); le_thread_Start(thread5Ref); // Threads 2, 3, 4, and 5 are mutex-locked and therefore can't get to Post. The function needs // to hang around for a bit for the mutex refs to be available for the threads. le_sem_Wait(SemaRef); LE_INFO("++++++++++++++++++ END OF testWaitingList (shouldn't get here) +++++++++++++++++++++"); }
static void Init ( void ) { // mutex for accessing the sem index variable. SemIndexMutexRef = le_mutex_CreateNonRecursive("SemIndexMutex"); // syncrhonizing among threads for waiting/posting semas. SemaRef = le_sem_Create("semaphoreFluxSemaphore", 0); // Initializing the array storing thread refs. ThreadRefArray = malloc(ThreadNum * sizeof(le_thread_Ref_t)); // Initializing the array storing sem refs. SemRefArray = malloc(ThreadNum * sizeof(SemRef_t)); }
static void Init ( void ) { // Create the key for thread specific data; ie. mutex refs. (void) pthread_key_create(&TsdMutexRefKey, NULL); // mutex for accessing the mutex index variable. MutexIndexMutexRef = le_mutex_CreateNonRecursive("MutexIndexMutex"); // syncrhonizing among threads for locking/unlocking mutexes SemaRef = le_sem_Create("MutexFluxSemaphore", 0); // Initializing the array storing thread refs. ThreadRefArray = malloc(ThreadNum * sizeof(le_thread_Ref_t)); }
// ------------------------------------------------------------------------------------------------- void fjm_Start ( void* completionObjPtr ///< [in] Pointer to the object whose reference count is used to signal /// the completion of the test. ) // ------------------------------------------------------------------------------------------------- { // Compute the expected ending counter value. ExpectedCounterValue = GetExpectedCounterValue(); // Create the mutex. MutexRef = le_mutex_CreateNonRecursive("fork-join-mutex-test"); LE_INFO("completionObjPtr = %p.", completionObjPtr); // Create the Context Pool. ContextPoolRef = le_mem_CreatePool("FJM-ContextPool", sizeof(Context_t)); le_mem_ExpandPool(ContextPoolRef, ExpectedCounterValue); // Spawn the first child thread. SpawnChildren(1, completionObjPtr); }
// A thread "main" function which creates a series of mutexes. static void* ThreadCreateMutex ( void* context ) { long mutexCount = (long)context; char mutexNameBuffer[MAX_NAME_BYTES] = {0}; MutexRefArray_t mra; mra.size = mutexCount; mra.mutexRefArray = malloc(mutexCount * sizeof(le_mutex_Ref_t)); LE_INFO("Thread [%s] has started. Creating %ld mutexes.", le_thread_GetMyName(), mutexCount); le_mutex_Lock(MutexIndexMutexRef); long cnt = 0; while (cnt < mutexCount) { snprintf(mutexNameBuffer, MAX_NAME_BYTES, "[%s]Mutex%ld", le_thread_GetMyName(), MutexCreateIdx); mra.mutexRefArray[cnt] = le_mutex_CreateNonRecursive(mutexNameBuffer); le_mutex_Lock(mra.mutexRefArray[cnt]); MutexCreateIdx++; cnt++; } le_mutex_Unlock(MutexIndexMutexRef); // Save the list of mutex refs in the thread's local storage. (void) pthread_setspecific(TsdMutexRefKey, &mra); le_sem_Post(SemaRef); le_event_RunLoop(); return NULL; }
//-------------------------------------------------------------------------------------------------- void _le_test_Init ( void ) { Mutex = le_mutex_CreateNonRecursive("UnitTestMutex"); NumFailures = 0; PassThrough = false; int i = le_arg_NumArgs() - 1; for (; i >= 0; i--) { char buf[sizeof(PassThroughArgLongForm)]; // Check the command line arguments for the PassThroughArgs strings. if ( (le_arg_GetArg(i, buf, sizeof(PassThroughArgLongForm)) == LE_OK) && ((strcmp(buf, PassThroughArg) == 0) || (strcmp(buf, PassThroughArgLongForm) == 0)) ) { PassThrough = true; } } }