Don't use CA thread pool in sample app
authorDan Mihai <Daniel.Mihai@microsoft.com>
Sat, 15 Apr 2017 01:14:12 +0000 (18:14 -0700)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Tue, 25 Apr 2017 18:19:43 +0000 (18:19 +0000)
The CA thread pool APIs are not intended to be Public.

Change-Id: Ic212c453c82e639be9f611b4b16a712054475de6
Signed-off-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18987
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
resource/csdk/security/provisioning/sample/cloud/cloudCommon.c

index a0ed58d..50613fe 100644 (file)
@@ -59,7 +59,7 @@
 
 static bool fExit = false;
 
-static ca_thread_pool_t g_threadPoolHandle = NULL;
+static oc_thread g_requestsThread = NULL;
 static OCDevAddr endPoint;
 static char token[1024] = "";
 static char authProvider[1024] = DEFAULT_AUTH_PROVIDER;
@@ -400,12 +400,12 @@ static void wrongRequest()
     printf(">> Entered Wrong Menu Number. Please Enter Again\n\n");
 }
 
-static void userRequests(void *data)
+static void *userRequests(void *data)
 {
     if (NULL == data)
     {
         OIC_LOG(ERROR, TAG, "Received NULL data");
-        return;
+        return NULL;
     }
 
     OCMode mode = *(OCMode*)data;
@@ -609,6 +609,8 @@ static void userRequests(void *data)
             }
         }
     }
+
+    return NULL;
 }
 
 FILE* server_fopen(const char *path, const char *mode)
@@ -679,20 +681,15 @@ OCStackResult initPersistentStorage()
 
 OCStackResult startRequestsThread(OCMode *mode)
 {
-    CAResult_t res = ca_thread_pool_init(1, &g_threadPoolHandle);
-    if (CA_STATUS_OK != res)
-    {
-        OIC_LOG(ERROR, TAG, "thread pool initialize error.");
-        return res;
-    }
+    OCThreadResult_t res = oc_thread_new(&g_requestsThread, userRequests, mode);
 
-    res = ca_thread_pool_add_task(g_threadPoolHandle, userRequests, mode);
-    if (CA_STATUS_OK != res)
+    if (OC_THREAD_SUCCESS != res)
     {
-        OIC_LOG(ERROR, TAG, "thread pool add task error.");
-        ca_thread_pool_free(g_threadPoolHandle);
+        OIC_LOG_V(ERROR, TAG, "oc_thread_new failed - error %u", res);
+        return OC_STACK_NO_MEMORY;
     }
-    return res;
+
+    return OC_STACK_OK;
 }
 
 OCStackResult initProcess(OCMode mode)
@@ -719,8 +716,22 @@ void startProcess()
 
 void freeThreadResources()
 {
-    if (g_threadPoolHandle)
+    if (g_requestsThread)
     {
-        ca_thread_pool_free(g_threadPoolHandle);
+        OCThreadResult_t res = oc_thread_wait(g_requestsThread);
+
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "oc_thread_wait failed - error %u", res);
+        }
+
+        res = oc_thread_free(g_requestsThread);
+
+        if (OC_THREAD_SUCCESS != res)
+        {
+            OIC_LOG_V(ERROR, TAG, "oc_thread_free failed - error %u", res);
+        }
+
+        g_requestsThread = NULL;
     }
 }