From 85018547508ae2adb331aa74139acac91f24ff42 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 17 Nov 2017 15:28:39 +0100 Subject: [PATCH] src/utils_ovs.c: Don't set pthread_t to -1, use pthread_equal() to compare. The assumption that pthread_t is a scalar is not portable. --- src/utils_ovs.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 63cb94c4..e9e841e8 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -902,7 +902,7 @@ static void *ovs_event_worker(void *arg) { /* Initialize EVENT thread */ static int ovs_db_event_thread_init(ovs_db_t *pdb) { - pdb->event_thread.tid = (pthread_t)-1; + pdb->event_thread.tid = (pthread_t){0}; /* init event thread condition variable */ if (pthread_cond_init(&pdb->event_thread.cond, NULL)) { return -1; @@ -936,9 +936,10 @@ static int ovs_db_event_thread_init(ovs_db_t *pdb) { /* Destroy EVENT thread */ static int ovs_db_event_thread_destroy(ovs_db_t *pdb) { - if (pdb->event_thread.tid == (pthread_t)-1) + if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) { /* already destroyed */ return 0; + } ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE); if (pthread_join(pdb->event_thread.tid, NULL) != 0) return -1; @@ -949,13 +950,13 @@ static int ovs_db_event_thread_destroy(ovs_db_t *pdb) { pthread_mutex_unlock(&pdb->event_thread.mutex); pthread_mutex_destroy(&pdb->event_thread.mutex); pthread_cond_destroy(&pdb->event_thread.cond); - pdb->event_thread.tid = (pthread_t)-1; + pdb->event_thread.tid = (pthread_t){0}; return 0; } /* Initialize POLL thread */ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { - pdb->poll_thread.tid = (pthread_t)-1; + pdb->poll_thread.tid = (pthread_t){0}; /* init event thread mutex */ if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) { return -1; @@ -974,9 +975,10 @@ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { /* Destroy POLL thread */ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { - if (pdb->poll_thread.tid == (pthread_t)-1) + if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) { /* already destroyed */ return 0; + } /* change thread state */ pthread_mutex_lock(&pdb->poll_thread.mutex); pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING; @@ -985,7 +987,7 @@ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { if (pthread_join(pdb->poll_thread.tid, NULL) != 0) return -1; pthread_mutex_destroy(&pdb->poll_thread.mutex); - pdb->poll_thread.tid = (pthread_t)-1; + pdb->poll_thread.tid = (pthread_t){0}; return 0; } -- 2.30.2