beginning port to osx

This commit is contained in:
David Rose 2009-06-11 16:36:55 +00:00
parent c36c100def
commit e10d398afd
10 changed files with 91 additions and 8 deletions

View File

@ -38,7 +38,7 @@
interrogatedb:c dconfig:c dtoolconfig:m \
express:c pandaexpress:m \
prc:c pstatclient:c pandabase:c linmath:c putil:c \
pipeline:c panda:m
pipeline:c event:c nativenet:c panda:m
#define SOURCES \
handleStream.cxx handleStream.h handleStream.I \
@ -57,7 +57,7 @@
#define OTHER_LIBS \
prc:c dtoolutil:c dtoolbase:c dtool:m \
interrogatedb:c dconfig:c dtoolconfig:m \
express:c pandaexpress:m \
express:c downloader:c pandaexpress:m \
pstatclient:c pandabase:c linmath:c putil:c \
pipeline:c panda:m \
pystub

View File

@ -31,6 +31,9 @@ P3DInstanceManager() {
_request_seq = 0;
#ifdef _WIN32
_request_ready = CreateEvent(NULL, false, false, NULL);
#else
INIT_LOCK(_request_ready_lock);
pthread_cond_init(&_request_ready_cvar, NULL);
#endif
}
@ -41,6 +44,13 @@ P3DInstanceManager() {
////////////////////////////////////////////////////////////////////
P3DInstanceManager::
~P3DInstanceManager() {
// Actually, the destructor is never called.
#ifdef _WIN32
CloseHandle(_request_ready);
#else
DESTROY_LOCK(_request_ready_lock);
pthread_cond_destroy(&_request_ready_cvar);
#endif
}
////////////////////////////////////////////////////////////////////
@ -163,7 +173,11 @@ wait_request() {
// No pending requests; go to sleep.
if (seq == _request_seq) {
#ifdef _WIN32
WaitForSingleObject(_request_ready, INFINITE);
#else
pthread_cond_wait(&_request_ready_cvar, &_request_ready_lock);
#endif
}
seq = _request_seq;
}
@ -194,6 +208,10 @@ signal_request_ready() {
++_request_seq;
#ifdef _WIN32
SetEvent(_request_ready);
#else
ACQUIRE_LOCK(_request_ready_lock);
pthread_cond_signal(&_request_ready_cvar);
RELEASE_LOCK(_request_ready_lock);
#endif
}

View File

@ -73,8 +73,10 @@ private:
volatile int _request_seq;
#ifdef _WIN32
HANDLE _request_ready;
#else
LOCK _request_ready_lock;
pthread_cond_t _request_ready_cvar;
#endif
static P3DInstanceManager *_global_ptr;
};

View File

@ -234,6 +234,12 @@ spawn_read_thread() {
_read_thread_continue = true;
#ifdef _WIN32
_read_thread = CreateThread(NULL, 0, &win_rt_thread_run, this, 0, NULL);
#else
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_create(&_read_thread, &attr, &posix_rt_thread_run, (void *)this);
pthread_attr_destroy(&attr);
#endif
}
@ -253,6 +259,9 @@ join_read_thread() {
WaitForSingleObject(_read_thread, INFINITE);
CloseHandle(_read_thread);
_read_thread = NULL;
#else
void *return_val;
pthread_join(_read_thread, &return_val);
#endif
cerr << "done waiting for thread\n";
}
@ -289,7 +298,10 @@ start_instance(P3DCInstance *inst) {
inst->_win_x, inst->_win_y,
inst->_win_width, inst->_win_height,
#ifdef _WIN32
(int)(inst->_parent_window._hwnd)
(long)(inst->_parent_window._hwnd)
#endif
#ifdef __APPLE__
(long)(inst->_parent_window._nswindow)
#endif
);
if (result == NULL) {
@ -405,6 +417,19 @@ win_rt_thread_run(LPVOID data) {
}
#endif
#ifndef _WIN32
////////////////////////////////////////////////////////////////////
// Function: P3DPython::win_rt_thread_run
// Access: Private, Static
// Description: The Posix flavor of the thread callback function.
////////////////////////////////////////////////////////////////////
void *P3DPythonRun::
posix_rt_thread_run(void *data) {
((P3DPythonRun *)data)->rt_thread_run();
return NULL;
}
#endif
////////////////////////////////////////////////////////////////////
// Function: main

View File

@ -79,6 +79,8 @@ private:
void rt_thread_run();
#ifdef _WIN32
static DWORD WINAPI win_rt_thread_run(LPVOID data);
#else
static void *posix_rt_thread_run(void *data);
#endif
private:
@ -111,6 +113,8 @@ private:
bool _program_continue;
#ifdef _WIN32
HANDLE _read_thread;
#else
pthread_t _thread;
#endif
};

View File

@ -17,8 +17,6 @@
#include "p3dInstanceManager.h"
#include <tinyxml.h>
#include <malloc.h>
////////////////////////////////////////////////////////////////////
// Function: P3DSession::Constructor
// Access: Public

View File

@ -19,12 +19,32 @@
// mutex locks.
#ifdef _WIN32
// Windows case
#define LOCK CRITICAL_SECTION
#define INIT_LOCK(lock) InitializeCriticalSection(&(lock))
#define ACQUIRE_LOCK(lock) EnterCriticalSection(&(lock))
#define RELEASE_LOCK(lock) LeaveCriticalSection(&(lock))
#define DESTROY_LOCK(lock) DeleteCriticalSection(&(lock))
#endif
#else // _WIN32
// Posix case
#include <pthread.h>
#define LOCK pthread_mutex_t
#define INIT_LOCK(lock) { \
pthread_mutexattr_t attr; \
pthread_mutexattr_init(&attr); \
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); \
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))
#define DESTROY_LOCK(lock) pthread_mutex_destroy(&(lock))
#endif // _WIN32
#endif

View File

@ -111,6 +111,9 @@ typedef struct {
#ifdef _WIN32
HWND _hwnd;
#endif
#ifdef __APPLE__
void *_nswindow;
#endif
} P3D_window_handle;
/* This enum lists the different kinds of window types that may be

View File

@ -298,6 +298,17 @@ make_parent_window(P3D_window_handle &parent_window,
}
#endif // _WIN32
#ifdef __APPLE__
void
make_parent_window(P3D_window_handle &parent_window,
int win_width, int win_height) {
// TODO.
assert(false);
}
#endif // __APPLE__
void
usage() {
cerr
@ -426,6 +437,7 @@ main(int argc, char *argv[]) {
make_parent_window(parent_window, win_width, win_height);
// Center the child window(s) within the parent window.
#ifdef _WIN32
RECT rect;
GetClientRect(parent_window._hwnd, &rect);
@ -433,6 +445,7 @@ main(int argc, char *argv[]) {
win_y = (int)(rect.bottom * 0.1);
win_width = (int)(rect.right * 0.8);
win_height = (int)(rect.bottom * 0.8);
#endif
// Subdivide the window into num_x_spans * num_y_spans sub-windows.
int num_y_spans = int(sqrt((double)num_instances));

View File

@ -57,7 +57,7 @@ elif sys.platform == 'darwin':
compileObj = "gcc -fPIC -c -o %(basename)s.o -O2 -arch i386 -arch ppc -I %(pythonIPath)s %(filename)s"
linkExe = "gcc -o %(basename)s %(basename)s.o -framework Python"
linkDll = "gcc -shared -o %(basename)s.so %(basename)s.o -framework Python"
linkDll = "gcc -dynamiclib -o %(basename)s.so %(basename)s.o -framework Python"
else:
# Linux