/** * Validate that we can enter/exit a RWMutex for write */ TEST(RWMutex, RWWriteEnterExitTest) { intptr_t result; omrthread_rwmutex_t handle; uintptr_t flags = 0; const char *mutexName = "test_mutex"; result = omrthread_rwmutex_init(&handle, flags, mutexName); ASSERT_TRUE(0 == result); result = omrthread_rwmutex_enter_write(handle); ASSERT_TRUE(0 == result); result = omrthread_rwmutex_exit_write(handle); ASSERT_TRUE(0 == result); result = omrthread_rwmutex_try_enter_write(handle); ASSERT_TRUE(0 == result); result = omrthread_rwmutex_exit_write(handle); ASSERT_TRUE(0 == result); /* clean up */ result = omrthread_rwmutex_destroy(handle); ASSERT_TRUE(0 == result); }
/** * This method is called to create a SupportThreadInfo for a test. It will populate the monitor and * rwmutex being used and zero out the counter * * @param functionsToRun an array of functions pointers. Each function will be run one in sequence synchronized * using the monitor within the SupporThreadInfo * @param numberFunctions the number of functions in the functionsToRun array * @returns a pointer to the newly created SupporThreadInfo */ SupportThreadInfo * createSupportThreadInfo(omrthread_entrypoint_t *functionsToRun, uintptr_t numberFunctions) { OMRPORT_ACCESS_FROM_OMRPORT(omrTestEnv->getPortLibrary()); SupportThreadInfo *info = (SupportThreadInfo *)omrmem_allocate_memory(sizeof(SupportThreadInfo), OMRMEM_CATEGORY_THREADS); info->readCounter = 0; info->writeCounter = 0; info->functionsToRun = functionsToRun; info->numberFunctions = numberFunctions; info->done = FALSE; omrthread_rwmutex_init((omrthread_rwmutex_t *)&info->handle, 0, "supportThreadInfo rwmutex"); omrthread_monitor_init_with_name(&info->synchronization, 0, "supportThreadAInfo monitor"); return info; }
/** * validate that we can create a reate/write mutex successfully */ TEST(RWMutex, CreateTest) { intptr_t result; omrthread_rwmutex_t handle; uintptr_t flags = 0; const char *mutexName = "test_mutex"; result = omrthread_rwmutex_init(&handle, flags, mutexName); ASSERT_TRUE(0 == result); /* clean up */ result = omrthread_rwmutex_destroy(handle); ASSERT_TRUE(0 == result); }
/** * Validate that is_writelocked return true in writing state */ TEST(RWMutex, IsWriteLockedTest) { intptr_t result; omrthread_rwmutex_t handle; uintptr_t flags = 0; BOOLEAN ret; const char *mutexName = "test_mutex"; result = omrthread_rwmutex_init(&handle, flags, mutexName); ASSERT_TRUE(0 == result); ret = omrthread_rwmutex_is_writelocked(handle); ASSERT_TRUE(FALSE == ret); result = omrthread_rwmutex_enter_read(handle); ASSERT_TRUE(0 == result); ret = omrthread_rwmutex_is_writelocked(handle); ASSERT_TRUE(FALSE == ret); result = omrthread_rwmutex_exit_read(handle); ASSERT_TRUE(0 == result); result = omrthread_rwmutex_enter_write(handle); ASSERT_TRUE(0 == result); ret = omrthread_rwmutex_is_writelocked(handle); ASSERT_TRUE(TRUE == ret); result = omrthread_rwmutex_exit_write(handle); ASSERT_TRUE(0 == result); /* clean up */ result = omrthread_rwmutex_destroy(handle); ASSERT_TRUE(0 == result); }
CRWMutex::CRWMutex(uintptr_t flags, const char *pName) { if (omrthread_rwmutex_init(&m_monitor, flags, pName)) { } }