mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
fix some threading crashes
This commit is contained in:
parent
507f578dbb
commit
10ead40b5d
3 changed files with 31 additions and 27 deletions
|
|
@ -18,7 +18,7 @@ struct LoadingSegment {
|
|||
extern struct LoadingSegment gCurrLoadingSegment;
|
||||
|
||||
#define LOADING_SCREEN_MUTEX(...) \
|
||||
if (!gCLIOpts.hideLoadingScreen && gLoadingThread.state != INVALID) { \
|
||||
if (!gCLIOpts.hideLoadingScreen && gLoadingThread.state == RUNNING) { \
|
||||
pthread_mutex_lock(&gLoadingThread.mutex); \
|
||||
__VA_ARGS__; \
|
||||
pthread_mutex_unlock(&gLoadingThread.mutex); \
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ int init_thread(struct ThreadHandle *handle, void *(*entry)(void *), void *arg,
|
|||
int join_thread(struct ThreadHandle *handle) {
|
||||
assert(handle != NULL);
|
||||
|
||||
handle->state = STOPPED;
|
||||
|
||||
// Join the thread and wait for it to finish.
|
||||
return pthread_join(handle->thread, NULL);
|
||||
}
|
||||
|
|
@ -68,6 +70,8 @@ int join_thread(struct ThreadHandle *handle) {
|
|||
int detach_thread(struct ThreadHandle *handle) {
|
||||
assert(handle != NULL);
|
||||
|
||||
handle->state = STOPPED;
|
||||
|
||||
// Detach the thread, it will no longer be joinable afterwards.
|
||||
return pthread_detach(handle->thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#include "types.h"
|
||||
|
||||
// Macros
|
||||
#define MUTEX_LOCK(handle) if (handle.state != INVALID) { lock_mutex(&handle); }
|
||||
#define MUTEX_UNLOCK(handle) if (handle.state != INVALID) { unlock_mutex(&handle); }
|
||||
#define MUTEX_LOCK(handle) if (handle.state == RUNNING) { lock_mutex(&handle); }
|
||||
#define MUTEX_UNLOCK(handle) if (handle.state == RUNNING) { unlock_mutex(&handle); }
|
||||
|
||||
// Types
|
||||
enum ThreadState {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue