Windows build fixes.

This commit is contained in:
Roger Light
2021-10-20 11:25:35 +01:00
parent 4b7ce2d670
commit 92f3db92d7
4 changed files with 12 additions and 4 deletions

View File

@@ -117,7 +117,10 @@ struct mosquitto *mosquitto_new(const char *id, bool clean_start, void *userdata
if(mosq){
mosq->sock = INVALID_SOCKET;
#ifdef WITH_THREADING
# ifndef WIN32
/* Windows doesn't have pthread_cancel, so no need to record self */
mosq->thread_id = pthread_self();
# endif
#endif
mosq->sockpairR = INVALID_SOCKET;
mosq->sockpairW = INVALID_SOCKET;
@@ -217,7 +220,11 @@ int mosquitto_reinitialise(struct mosquitto *mosq, const char *id, bool clean_st
pthread_mutex_init(&mosq->msgs_in.mutex, NULL);
pthread_mutex_init(&mosq->msgs_out.mutex, NULL);
pthread_mutex_init(&mosq->mid_mutex, NULL);
#ifdef WIN32
mosq->thread_id = NULL;
#else
mosq->thread_id = pthread_self();
#endif
#endif
if(mosq->disable_socketpair == false){
/* This must be after pthread_mutex_init(), otherwise the log mutex may be

View File

@@ -329,11 +329,7 @@ struct mosquitto {
pthread_mutex_t out_packet_mutex;
pthread_mutex_t state_mutex;
pthread_mutex_t mid_mutex;
#ifdef WIN32
int thread_id;
#else
pthread_t thread_id;
#endif
#endif
bool clean_start;
time_t session_expiry_time;

View File

@@ -87,7 +87,11 @@ int mosquitto_loop_stop(struct mosquitto *mosq, bool force)
}
#endif
pthread_join(mosq->thread_id, NULL);
#ifdef WIN32
mosq->thread_id = NULL;
#else
mosq->thread_id = pthread_self();
#endif
mosq->threaded = mosq_ts_none;
return MOSQ_ERR_SUCCESS;

View File

@@ -33,6 +33,7 @@ typedef void pthread_condattr_t;
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
int pthread_join(pthread_t thread, void **retval);
int pthread_self(void);
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_lock(pthread_mutex_t *mutex);