-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid synchronized in Device.isDisposed #74 #75
Conversation
@@ -336,6 +335,8 @@ public void dispose () { | |||
trackingLock = null; | |||
} | |||
} | |||
} finally { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to the removal of the synchronization or just better style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it probably not any usual usecase to dispose() Device i wanted to make sure that disposed flag is updated as the very last statement during dispose(). One could also change it to be the very first statement- in any case if isDisposed() is checked in any other thread it has almost no meaning as it could be disposed in the next blink of an eye. So it does not really matter.
Same change needs to be done for SWT Mac and SWT GTK. |
Note that With new code, However, this new problem will probably not make things any worse. Because it's still wrong to call |
Device.isDisposed() is called much more frequently then dispose() and should not be costly synchronized. The isDisposed() check in dispose() is still synchronized so that still there will be no double dispose().
Thats what i think too! |
done |
Calling isDisposed outside the main thread and expecting no change would be wrong IMHO with or without a lock on this method. So I agree the change is fine. |
The javadoc of Device.dispose() states that "After this method has been invoked, the receiver will answer |
will remain true. |
Maybe we should add to the Javadoc that we expect isDisposed to be called from the main thread? |
no. there are a lot of usages where isDisposed() is called from other threads to avoid queuing up messages if widget is already disposed. Still needs a double isDisposed() check within SWT thread though. |
Device.isDisposed() is called much more frequently then dispose() and
should not be costly synchronized. The isDisposed() check in dispose()
is still synchronized so that still there will be no double dispose().