Remove ca_mutex_trylock and associated unit test
authorDavid Antler <david.a.antler@intel.com>
Wed, 9 Mar 2016 19:44:26 +0000 (11:44 -0800)
committerJon A. Cruz <jon@joncruz.org>
Tue, 15 Mar 2016 08:47:48 +0000 (08:47 +0000)
ca_mutex_trylock is not used anywhere. Implementation of this function
presents challenges for porting to additional platforms where an
easily-wrappable implementation might not be available, such as on
Windows.

Change-Id: I7727c5f9a6c97a53dda15007cdfd74043ab03a7b
Signed-off-by: David Antler <david.a.antler@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5645
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/common/inc/camutex.h
resource/csdk/connectivity/common/src/camutex_noop.c
resource/csdk/connectivity/common/src/camutex_pthreads.c
resource/csdk/connectivity/test/camutex_tests.cpp

index 29d42d8..5a1c00f 100644 (file)
@@ -64,16 +64,6 @@ ca_mutex ca_mutex_new(void);
 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.
index 2250cb3..d725980 100644 (file)
@@ -70,11 +70,6 @@ void ca_mutex_lock(ca_mutex mutex)
     return;
 }
 
-bool ca_mutex_trylock(ca_mutex mutex)
-{
-    return true;
-}
-
 void ca_mutex_unlock(ca_mutex mutex)
 {
     return;
index bc0dc28..834886c 100644 (file)
@@ -152,37 +152,6 @@ void ca_mutex_lock(ca_mutex mutex)
     }
 }
 
-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;
index 24fcf06..1c3f34e 100644 (file)
@@ -87,30 +87,6 @@ TEST(MutexTests, TC_01_CREATE)
     }
 }
 
-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;