diff options
Diffstat (limited to 'src/nativewindow')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java | 6 | ||||
-rw-r--r-- | src/nativewindow/native/win32/GDImisc.c | 104 |
2 files changed, 110 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java index 31e85dcee..c409b6a39 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java +++ b/src/nativewindow/classes/jogamp/nativewindow/windows/GDIUtil.java @@ -128,6 +128,10 @@ public class GDIUtil implements ToolkitProperties { return IsChild0(win); } + public static void SetProcessThreadsAffinityMask(final long affinityMask, final boolean verbose) { + SetProcessThreadsAffinityMask0(affinityMask, verbose); + } + private static final void dumpStack() { Thread.dumpStack(); } // Callback for JNI /** Creates WNDCLASSEX instance */ @@ -142,6 +146,8 @@ public class GDIUtil implements ToolkitProperties { private static native boolean IsChild0(long win); private static native boolean IsUndecorated0(long win); + private static native void SetProcessThreadsAffinityMask0(long affinityMask, boolean verbose); + private static native long CreateDummyWindow0(long hInstance, String className, long dispThreadCtx, String windowName, int x, int y, int width, int height); private static native boolean DestroyWindow0(long dispThreadCtx, long win); } diff --git a/src/nativewindow/native/win32/GDImisc.c b/src/nativewindow/native/win32/GDImisc.c index bec1d4922..677c71025 100644 --- a/src/nativewindow/native/win32/GDImisc.c +++ b/src/nativewindow/native/win32/GDImisc.c @@ -572,3 +572,107 @@ JNIEXPORT jboolean JNICALL Java_jogamp_nativewindow_windows_GDIUtil_IsUndecorate return bIsUndecorated ? JNI_TRUE : JNI_FALSE; } +#if 0 + +#include <tlhelp32.h> +#include <tchar.h> + +static void printError( TCHAR* msg ) +{ + DWORD eNum; + TCHAR sysMsg[256]; + TCHAR* p; + + eNum = GetLastError( ); + FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, eNum, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + sysMsg, 256, NULL ); + + // Trim the end of the line and terminate it with a null + p = sysMsg; + while( ( *p > 31 ) || ( *p == 9 ) ) + ++p; + do { *p-- = 0; } while( ( p >= sysMsg ) && + ( ( *p == '.' ) || ( *p < 33 ) ) ); + + // Display the message + _ftprintf(stderr, TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg ); +} + +static BOOL SetProcessThreadsAffinityMask( DWORD dwOwnerPID, DWORD_PTR newTAffinity, BOOL verbose ) +{ + HANDLE hThreadSnap = INVALID_HANDLE_VALUE; + THREADENTRY32 te32; + DWORD_PTR preTAffinity; + HANDLE threadHandle; + + // Take a snapshot of all running threads + hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 ); + if( hThreadSnap == INVALID_HANDLE_VALUE ) + return( FALSE ); + + // Fill in the size of the structure before using it. + te32.dwSize = sizeof(THREADENTRY32 ); + + // Retrieve information about the first thread, + // and exit if unsuccessful + if( !Thread32First( hThreadSnap, &te32 ) ) + { + if( verbose ) { + printError( TEXT("Thread32First") ); // Show cause of failure + } + CloseHandle( hThreadSnap ); // Must clean up the snapshot object! + return( FALSE ); + } + + // Now walk the thread list of the system, + // and display information about each thread + // associated with the specified process + do + { + if( te32.th32OwnerProcessID == dwOwnerPID ) + { + if( verbose ) { + _ftprintf(stderr, TEXT("\n THREAD ID = 0x%08X, %d"), te32.th32ThreadID, te32.th32ThreadID); + _ftprintf(stderr, TEXT("\n base priority = %d"), te32.tpBasePri ); + _ftprintf(stderr, TEXT("\n delta priority = %d"), te32.tpDeltaPri ); + } + threadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, te32.th32ThreadID); + if( NULL != threadHandle ) { + preTAffinity = SetThreadAffinityMask(threadHandle, newTAffinity); + CloseHandle(threadHandle); + if( verbose ) { + _ftprintf(stderr, TEXT("\n affinity %p -> %p"), preTAffinity, newTAffinity); + } + } else { + if( verbose ) { + _ftprintf(stderr, TEXT("\n OpenThread failed %d"), (int)GetLastError()); + } + } + } + } while( Thread32Next(hThreadSnap, &te32 ) ); + + if( verbose ) { + _ftprintf(stderr, TEXT("\n")); + } + +// Don't forget to clean up the snapshot object. + CloseHandle( hThreadSnap ); + return( TRUE ); +} + +JNIEXPORT void JNICALL Java_jogamp_nativewindow_windows_GDIUtil_SetProcessThreadsAffinityMask0 + (JNIEnv *env, jclass unused, long affinityMask, jboolean verbose) +{ + SetProcessThreadsAffinityMask( GetCurrentProcessId(), (DWORD_PTR)(intptr_t)affinityMask, (BOOL)verbose ); +} + +#else + +JNIEXPORT void JNICALL Java_jogamp_nativewindow_windows_GDIUtil_SetProcessThreadsAffinityMask0 + (JNIEnv *env, jclass unused, long affinityMask, jboolean verbose) +{ +} + +#endif |