diff --git a/src/Makefile b/src/Makefile index e7f48fdd..cdca7211 100644 --- a/src/Makefile +++ b/src/Makefile @@ -237,6 +237,7 @@ ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) TARGET_SYS= PS3 TARGET_ARCH+= -D__CELLOS_LV2__ TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC + TARGET_XLIBS+= -lpthread endif ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) TARGET_ARCH+= -DLUAJIT_NO_UNWIND diff --git a/src/lj_arch.h b/src/lj_arch.h index ccb54270..7ded0143 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -371,7 +371,10 @@ #elif LJ_TARGET_POSIX #define LJ_HASPROFILE 1 #define LJ_PROFILE_SIGPROF 1 -#elif LJ_TARGET_WINDOWS +#elif LJ_TARGET_PS3 +#define LJ_HASPROFILE 1 +#define LJ_PROFILE_PTHREAD 1 +#elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360 #define LJ_HASPROFILE 1 #define LJ_PROFILE_WTHREAD 1 #else diff --git a/src/lj_profile.c b/src/lj_profile.c index a58aefc8..c7bc6168 100644 --- a/src/lj_profile.c +++ b/src/lj_profile.c @@ -30,6 +30,10 @@ #elif LJ_PROFILE_PTHREAD #include +#include +#if LJ_TARGET_PS3 +#include +#endif #elif LJ_PROFILE_WTHREAD @@ -54,9 +58,11 @@ typedef struct ProfileState { pthread_t thread; /* Timer thread. */ int abort; /* Abort timer thread. */ #elif LJ_PROFILE_WTHREAD +#if LJ_TARGET_WINDOWS HINSTANCE wmm; /* WinMM library handle. */ WMM_TPFUNC wmm_tbp; /* WinMM timeBeginPeriod function. */ WMM_TPFUNC wmm_tep; /* WinMM timeEndPeriod function. */ +#endif HANDLE thread; /* Timer thread. */ int abort; /* Abort timer thread. */ #endif @@ -144,11 +150,17 @@ static void profile_timer_stop(ProfileState *ps) static void *profile_thread(ProfileState *ps) { int interval = ps->interval; +#if !LJ_TARGET_PS3 struct timespec ts; ts.tv_sec = interval / 1000; ts.tv_nsec = (interval % 1000) * 1000000; +#endif while (1) { +#if LJ_TARGET_PS3 + sys_timer_usleep(interval * 1000); +#else nanosleep(&ts, NULL); +#endif if (ps->abort) break; profile_trigger(ps); } @@ -176,19 +188,24 @@ static DWORD WINAPI profile_thread(void *psx) { ProfileState *ps = (ProfileState *)psx; int interval = ps->interval; - ps->wmm_tbp(1); +#if LJ_TARGET_WINDOWS + ps->wmm_tbp(interval); +#endif while (1) { Sleep(interval); if (ps->abort) break; profile_trigger(ps); } - ps->wmm_tep(1); +#if LJ_TARGET_WINDOWS + ps->wmm_tep(interval); +#endif return 0; } /* Start profiling timer thread. */ static void profile_timer_start(ProfileState *ps) { +#if LJ_TARGET_WINDOWS if (!ps->wmm) { /* Load WinMM library on-demand. */ ps->wmm = LoadLibraryA("winmm.dll"); if (ps->wmm) { @@ -200,6 +217,7 @@ static void profile_timer_start(ProfileState *ps) } } } +#endif ps->abort = 0; ps->thread = CreateThread(NULL, 0, profile_thread, ps, 0, NULL); }