summaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-11-29 17:01:50 +0100
committerSven Gothel <[email protected]>2011-11-29 17:01:50 +0100
commit02e5b9b0040deb9f6c11ae305a23213d006f0d40 (patch)
tree6f53170ba4c4026c634e9e01b1b6a2e7cc9cee89 /src/newt
parentdaf11ad8174a1b4471eaa0b59c8350b4175baae2 (diff)
NEWTMacWindow:View: Make lock recursive ..
Attempt to fix the shared-context-multithreading bug (eg. TestSharedContextVBOES2NEWT2) via proper locking .. but seems not to be sufficient (yet).
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/native/NewtMacWindow.h6
-rw-r--r--src/newt/native/NewtMacWindow.m35
2 files changed, 26 insertions, 15 deletions
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index 17c9416d9..eaece2cf8 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -54,8 +54,8 @@
JavaVM *jvmHandle;
int jvmVersion;
- BOOL destroyNotifySent;
- BOOL softLocked;
+ volatile BOOL destroyNotifySent;
+ volatile BOOL softLocked;
pthread_mutex_t softLockSync;
NSTrackingRectTag ptrTrackingTag;
@@ -89,7 +89,7 @@
- (BOOL) needsDisplay;
- (void) displayIfNeeded;
-- (void) viewWillDraw;
+- (void) display;
- (void) drawRect:(NSRect)dirtyRect;
- (void) viewDidHide;
- (void) viewDidUnhide;
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 7c59aebc9..1018633b1 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -104,7 +104,11 @@ static jmethodID windowRepaintID = NULL;
jvmVersion = 0;
destroyNotifySent = NO;
softLocked = NO;
- pthread_mutex_init(&softLockSync, NULL); // fast non-recursive
+
+ pthread_mutexattr_t softLockSyncAttr;
+ pthread_mutexattr_init(&softLockSyncAttr);
+ pthread_mutexattr_settype(&softLockSyncAttr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init(&softLockSync, &softLockSyncAttr); // recursive
ptrTrackingTag = 0;
@@ -122,7 +126,7 @@ static jmethodID windowRepaintID = NULL;
- (void) dealloc
{
if(softLocked) {
- fprintf(stderr, "*** Warning: softLock still hold @ dealloc!\n"); fflush(NULL);
+ NSLog(@"NewtView::dealloc: softLock still hold @ dealloc!\n");
}
pthread_mutex_destroy(&softLockSync);
[super dealloc];
@@ -195,13 +199,17 @@ static jmethodID windowRepaintID = NULL;
- (BOOL) softLock
{
+ // DBG_PRINT("*************** softLock.0: %p\n", (void*)pthread_self());
+ // NSLog(@"NewtView::softLock: %@",[NSThread callStackSymbols]);
pthread_mutex_lock(&softLockSync);
softLocked = YES;
+ // DBG_PRINT("*************** softLock.X: %p\n", (void*)pthread_self());
return softLocked;
}
- (void) softUnlock
{
+ // DBG_PRINT("*************** softUnlock: %p\n", (void*)pthread_self());
softLocked = NO;
pthread_mutex_unlock(&softLockSync);
}
@@ -213,22 +221,25 @@ static jmethodID windowRepaintID = NULL;
- (void) displayIfNeeded
{
- [self softLock];
- if( NO == destroyNotifySent ) {
+ if( YES == [self needsDisplay] ) {
+ [self softLock];
[super displayIfNeeded];
+ [self softUnlock];
}
- [self softUnlock];
}
-- (void) viewWillDraw
+- (void) display
{
- DBG_PRINT("*************** viewWillDraw: 0x%p\n", javaWindowObject);
- [super viewWillDraw];
+ if( NO == destroyNotifySent ) {
+ [self softLock];
+ [super display];
+ [self softUnlock];
+ }
}
- (void) drawRect:(NSRect)dirtyRect
{
- DBG_PRINT("*************** dirtyRect: 0x%p %lf/%lf %lfx%lf\n",
+ DBG_PRINT("*************** dirtyRect: %p %lf/%lf %lfx%lf\n",
javaWindowObject, dirtyRect.origin.x, dirtyRect.origin.y, dirtyRect.size.width, dirtyRect.size.height);
int shallBeDetached = 0;
@@ -240,7 +251,7 @@ static jmethodID windowRepaintID = NULL;
NSRect viewFrame = [self frame];
- (*env)->CallVoidMethod(env, javaWindowObject, windowRepaintID, JNI_FALSE,
+ (*env)->CallVoidMethod(env, javaWindowObject, windowRepaintID, JNI_TRUE, // defer ..
dirtyRect.origin.x, viewFrame.size.height - dirtyRect.origin.y,
dirtyRect.size.width, dirtyRect.size.height);
@@ -823,7 +834,7 @@ static jint mods2JavaMods(NSUInteger mods)
if( false == [view getDestroyNotifySent] ) {
jobject javaWindowObject = [view getJavaWindowObject];
- DBG_PRINT( "*************** windowWillClose.0: 0x%p\n", (void *)(intptr_t)javaWindowObject);
+ DBG_PRINT( "*************** windowWillClose.0: %p\n", (void *)(intptr_t)javaWindowObject);
if (javaWindowObject == NULL) {
DBG_PRINT("windowWillClose: null javaWindowObject\n");
return;
@@ -847,7 +858,7 @@ static jint mods2JavaMods(NSUInteger mods)
if (shallBeDetached) {
(*jvmHandle)->DetachCurrentThread(jvmHandle);
}
- DBG_PRINT( "*************** windowWillClose.X: 0x%p\n", (void *)(intptr_t)javaWindowObject);
+ DBG_PRINT( "*************** windowWillClose.X: %p\n", (void *)(intptr_t)javaWindowObject);
} else {
DBG_PRINT( "*************** windowWillClose (skip)\n");
}