diff --git a/direct/src/plugin/p3dOsxSplashWindow.cxx b/direct/src/plugin/p3dOsxSplashWindow.cxx index ec4c597a8b..fda48dbc40 100644 --- a/direct/src/plugin/p3dOsxSplashWindow.cxx +++ b/direct/src/plugin/p3dOsxSplashWindow.cxx @@ -527,8 +527,8 @@ paint_progress_bar(CGContextRef context) { CGPoint end_point = CGContextGetTextPosition(context); float text_width = end_point.x; - int text_x = (_win_width - text_width) / 2; - int text_y = bar_y - text_height * 1.5; + int text_x = (int)(_win_width - text_width) / 2; + int text_y = (int)(bar_y - text_height * 1.5); // Clear the rectangle behind the text to white. CGRect text_rect = { { text_x - 2, text_y - 2 }, { text_width + 4, text_height + 4 } }; diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index cda5f6da11..d497ab630b 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -1128,7 +1128,7 @@ set_failed() { //////////////////////////////////////////////////////////////////// void P3DSession:: spawn_read_thread() { - assert(!_read_thread_continue); + assert(!_started_read_thread && !_read_thread_continue); _read_thread_continue = true; SPAWN_THREAD(_read_thread, rt_thread_run, this); diff --git a/direct/src/plugin/p3d_lock.h b/direct/src/plugin/p3d_lock.h index 12073600c5..915bf06fe6 100755 --- a/direct/src/plugin/p3d_lock.h +++ b/direct/src/plugin/p3d_lock.h @@ -46,23 +46,25 @@ public: // Threads. #define THREAD HANDLE #define INIT_THREAD(thread) (thread) = NULL; -#define SPAWN_THREAD(thread, callback_function, this) \ +#define SPAWN_THREAD(thread, callback_function, this) \ (thread) = CreateThread(NULL, 0, &win_ ## callback_function, (this), 0, NULL) -#define JOIN_THREAD(thread) \ - assert((thread) != NULL); \ - WaitForSingleObject((thread), INFINITE); \ - CloseHandle((thread)); \ - (thread) = NULL; +#define JOIN_THREAD(thread) \ + { \ + assert((thread) != NULL); \ + WaitForSingleObject((thread), INFINITE); \ + CloseHandle((thread)); \ + (thread) = NULL; \ + } // Declare this macro within your class declaration. This implements // the callback function wrapper necessary to hook into the above // SPAWN_THREAD call. The wrapper will in turn call the method // function you provide. #define THREAD_CALLBACK_DECLARATION(class, callback_function) \ - static DWORD WINAPI \ - win_ ## callback_function(LPVOID data) { \ - ((class *)data)->callback_function(); \ - return 0; \ + static DWORD WINAPI \ + win_ ## callback_function(LPVOID data) { \ + ((class *)data)->callback_function(); \ + return 0; \ } @@ -75,12 +77,12 @@ public: // request_ready call from within the API, which in turn is allowed to // call back into the API. #define LOCK pthread_mutex_t -#define INIT_LOCK(lock) { \ - pthread_mutexattr_t attr; \ - pthread_mutexattr_init(&attr); \ +#define INIT_LOCK(lock) { \ + pthread_mutexattr_t attr; \ + pthread_mutexattr_init(&attr); \ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \ - int result = pthread_mutex_init(&(lock), &attr); \ - pthread_mutexattr_destroy(&attr); \ + int result = pthread_mutex_init(&(lock), &attr); \ + pthread_mutexattr_destroy(&attr); \ } #define ACQUIRE_LOCK(lock) pthread_mutex_lock(&(lock)) #define RELEASE_LOCK(lock) pthread_mutex_unlock(&(lock)) @@ -88,25 +90,34 @@ public: #define THREAD pthread_t #define INIT_THREAD(thread) (thread) = 0; -#define SPAWN_THREAD(thread, callback_function, this) \ - pthread_attr_t attr; \ - pthread_attr_init(&attr); \ - pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); \ - pthread_create(&(thread), &attr, &posix_ ## callback_function, (void *)(this)); \ - pthread_attr_destroy(&attr); +#define SPAWN_THREAD(thread, callback_function, this) \ + { \ + pthread_attr_t attr; \ + pthread_attr_init(&attr); \ + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); \ + pthread_create(&(thread), &attr, &posix_ ## callback_function, (void *)(this)); \ + pthread_attr_destroy(&attr); \ + } -#define JOIN_THREAD(thread) \ - assert((thread) != 0); \ - void *return_val; \ -pthread_join((thread), &return_val); \ - (thread) = 0; +#define JOIN_THREAD(thread) \ + { \ + assert((thread) != 0); \ + void *return_val; \ + int success = pthread_join((thread), &return_val); \ + (thread) = 0; \ + if (success != 0) { \ + nout << "Failed to join: " << success << "\n"; \ + } else { \ + nout << "Successfully joined thread: " << return_val << "\n"; \ + } \ + } // As above, declare this macro within your class declaration. #define THREAD_CALLBACK_DECLARATION(class, callback_function) \ static void * \ - posix_ ## callback_function(void *data) { \ - ((class *)data)->callback_function(); \ - return NULL; \ + posix_ ## callback_function(void *data) { \ + ((class *)data)->callback_function(); \ + return NULL; \ } #endif // _WIN32