testcase/mqtt: fix mqtt utc signal issue
sometimes callback from mqtt stack is called before utc waits it.
so instead of pthread_cond_signal utc for mqtt calls semaphore.
#endif
#define UTC_MQTT_WAIT_SIGNAL \
do { \
- pthread_mutex_lock(&g_ocfmutex); \
- pthread_cond_wait(&g_ocfcond, &g_ocfmutex); \
- pthread_mutex_unlock(&g_ocfmutex); \
+ sem_wait(&g_mqtt_signal); \
} while (0)
#define UTC_MQTT_SEND_SIGNAL \
do { \
- pthread_mutex_lock(&g_ocfmutex); \
- pthread_cond_signal(&g_ocfcond); \
- pthread_mutex_unlock(&g_ocfmutex); \
+ sem_post(&g_mqtt_signal); \
} while (0)
static char g_mqtt_msg[] = UTC_MQTT_MESSAGE;
-static pthread_mutex_t g_ocfmutex = PTHREAD_MUTEX_INITIALIZER;;
-static pthread_cond_t g_ocfcond;
static mqtt_client_t *g_mqtt_pub_handle = NULL;
static mqtt_client_t *g_mqtt_sub_handle = NULL;
-
+static sem_t g_mqtt_signal;
/**
* Private Functions
*/
@@ -68,25 +62,20 @@ static int _utc_mqtt_init(void)
{
g_mqtt_sub_handle = g_mqtt_pub_handle = NULL;
- int res = pthread_mutex_init(&g_ocfmutex, NULL);
- if (res != 0) {
- UTC_MQTT_LOGE;
- return -1;
- }
- res = pthread_cond_init(&g_ocfcond, NULL);
- if (res != 0) {
+ int ret = sem_init(&g_mqtt_signal, 0, 0);
+ if (ret != OK) {
UTC_MQTT_LOGE;
return -1;
}
-
return 0;
}
static void _utc_mqtt_deinit(void)
{
- pthread_mutex_destroy(&g_ocfmutex);
- pthread_cond_destroy(&g_ocfcond);
-
+ int ret = sem_destroy(&g_mqtt_signal);
+ if (ret < 0) {
+ UTC_MQTT_LOGE;
+ }
return;
}
