void ca_mutex_lock(ca_mutex mutex);
/**
- * Checks if the mutex can be locked.
- *
- * @param mutex The mutex to be locked.
- *
- * @return true if the mutex is not locked currently, otherwise false.
- *
- */
-bool ca_mutex_trylock(ca_mutex mutex);
-
-/**
* Unlock the mutex.
*
* @param mutex The mutex to be unlocked.
return;
}
-bool ca_mutex_trylock(ca_mutex mutex)
-{
- return true;
-}
-
void ca_mutex_unlock(ca_mutex mutex)
{
return;
}
}
-bool ca_mutex_trylock(ca_mutex mutex)
-{
- if (NULL == mutex)
- {
- OIC_LOG_V(ERROR, TAG, "%s Invalid mutex !", __func__);
- return false;
- }
-
- bool bRet = false;
-
- ca_mutex_internal *mutexInfo = (ca_mutex_internal*) mutex;
-
- int result = pthread_mutex_trylock(&mutexInfo->mutex);
-
- switch (result)
- {
- case 0:
- // Success
- bRet = true;
- break;
- case EINVAL:
- OIC_LOG_V(ERROR, TAG, "%s: Invalid mutex !", __func__);
- break;
- case EBUSY:
- default:
- break;
- }
-
- return bRet;
-}
-
void ca_mutex_unlock(ca_mutex mutex)
{
ca_mutex_internal *mutexInfo = (ca_mutex_internal*) mutex;
}
}
-TEST(MutexTests, TC_02_TRY_LOCK)
-{
- ca_mutex mymutex = ca_mutex_new();
-
- EXPECT_TRUE(mymutex != NULL);
- if (mymutex != NULL)
- {
- EXPECT_TRUE(ca_mutex_trylock(mymutex)); // acquire it
-
- ca_mutex_unlock(mymutex); // release it
-
- ca_mutex_lock(mymutex); // acquire it
-
- EXPECT_FALSE(ca_mutex_trylock(mymutex)); // he should be lock
-
- EXPECT_FALSE(ca_mutex_trylock(NULL));
-
- ca_mutex_unlock(mymutex); // release it
- ca_mutex_free(mymutex);
-
- EXPECT_FALSE(ca_mutex_trylock(NULL));
- }
-}
-
typedef struct _tagFunc1
{
ca_mutex mutex;