aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-10-27 02:49:28 +0200
committerSven Gothel <[email protected]>2011-10-27 02:49:28 +0200
commit33335e6149f2d6f6ebdad64588d9fba2f0ebb49b (patch)
treeb2889dde373d0f68247a09e4ac5ec77ca3fb9144 /src
parent6b857b7826cf29fe0a588d06aade217f47edfae0 (diff)
NEWT/OSX NewtView: Add 'soft' pthread locking impacts: needsDisplay/displayIfNeeded, ..
- Add 'soft' pthread locking (blockin) - impacts: needsDisplay/displayIfNeeded, .. - needsDisplay/displayIfNeeded also respects destroyNotifySend (ignore action if set)
Diffstat (limited to 'src')
-rw-r--r--src/newt/native/NewtMacWindow.h16
-rw-r--r--src/newt/native/NewtMacWindow.m76
2 files changed, 78 insertions, 14 deletions
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index 945948291..cb256e71f 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -32,6 +32,7 @@
*/
#import <AppKit/AppKit.h>
+#import <pthread.h>
#import "jni.h"
#include "NewtCommon.h"
@@ -53,6 +54,8 @@
int jvmVersion;
BOOL destroyNotifySent;
+ BOOL softLocked;
+ pthread_mutex_t softLockSync;
NSTrackingRectTag ptrTrackingTag;
NSRect ptrRect;
@@ -60,8 +63,7 @@
}
- (id)initWithFrame:(NSRect)frameRect;
-
-- (NSCursor *) cursor;
+- (void) dealloc;
/* Set during event dispatching cycle */
- (void) setJVMHandle: (JavaVM*) vm;
@@ -74,12 +76,18 @@
- (void) setJavaWindowObject: (jobject) javaWindowObj;
- (jobject) getJavaWindowObject;
+- (void) rightMouseDown: (NSEvent*) theEvent;
+- (void) resetCursorRects;
+- (NSCursor *) cursor;
+
- (void) setDestroyNotifySent: (BOOL) v;
- (BOOL) getDestroyNotifySent;
-- (void) rightMouseDown: (NSEvent*) theEvent;
-- (void) resetCursorRects;
+- (BOOL) softLock;
+- (void) softUnlock;
+- (BOOL) needsDisplay;
+- (void) displayIfNeeded;
- (void) viewWillDraw;
- (void) drawRect:(NSRect)dirtyRect;
- (void) viewDidHide;
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 43e66506c..1f74742ec 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -103,6 +103,8 @@ static jmethodID windowRepaintID = NULL;
jvmHandle = NULL;
jvmVersion = 0;
destroyNotifySent = NO;
+ softLocked = NO;
+ pthread_mutex_init(&softLockSync, NULL); // fast non-recursive
ptrTrackingTag = 0;
@@ -117,6 +119,15 @@ static jmethodID windowRepaintID = NULL;
return [super initWithFrame:frameRect];
}
+- (void) dealloc
+{
+ if(softLocked) {
+ fprintf(stderr, "*** Warning: softLock still hold @ dealloc!\n"); fflush(NULL);
+ }
+ pthread_mutex_destroy(&softLockSync);
+ [super dealloc];
+}
+
- (void) setJVMHandle: (JavaVM*) vm
{
jvmHandle = vm;
@@ -146,16 +157,6 @@ static jmethodID windowRepaintID = NULL;
return javaWindowObject;
}
-- (void) setDestroyNotifySent: (BOOL) v
-{
- destroyNotifySent = v;
-}
-
-- (BOOL) getDestroyNotifySent
-{
- return destroyNotifySent;
-}
-
- (void) rightMouseDown: (NSEvent*) theEvent
{
NSResponder* next = [self nextResponder];
@@ -182,6 +183,61 @@ static jmethodID windowRepaintID = NULL;
return myCursor;
}
+- (void) setDestroyNotifySent: (BOOL) v
+{
+ destroyNotifySent = v;
+}
+
+- (BOOL) getDestroyNotifySent
+{
+ return destroyNotifySent;
+}
+
+#define SOFT_LOCK_BLOCKING 1
+
+- (BOOL) softLock
+{
+ pthread_mutex_lock(&softLockSync);
+ softLocked = YES;
+#ifndef SOFT_LOCK_BLOCKING
+ pthread_mutex_unlock(&softLockSync);
+#endif
+ return softLocked;
+}
+
+- (void) softUnlock
+{
+#ifndef SOFT_LOCK_BLOCKING
+ pthread_mutex_lock(&softLockSync);
+#endif
+ softLocked = NO;
+ pthread_mutex_unlock(&softLockSync);
+}
+
+- (BOOL) needsDisplay
+{
+#ifndef SOFT_LOCK_BLOCKING
+ return NO == softLocked && NO == destroyNotifySent && [super needsDisplay];
+#else
+ return NO == destroyNotifySent && [super needsDisplay];
+#endif
+}
+
+- (void) displayIfNeeded
+{
+#ifndef SOFT_LOCK_BLOCKING
+ if( NO == softLocked && NO == destroyNotifySent ) {
+ [super displayIfNeeded];
+ }
+#else
+ [self softLock];
+ if( NO == destroyNotifySent ) {
+ [super displayIfNeeded];
+ }
+ [self softUnlock];
+#endif
+}
+
- (void) viewWillDraw
{
DBG_PRINT("*************** viewWillDraw: 0x%p\n", javaWindowObject);