From 0893a034f90f80629c5b634b564bdd4977c48369 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 17 Feb 2011 02:21:12 -0800 Subject: Use C++ RAII for WebThreadLock/Unlock(). --- UICaboodle/BrowserView.mm | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'UICaboodle') diff --git a/UICaboodle/BrowserView.mm b/UICaboodle/BrowserView.mm index 8bc0eff..956e359 100644 --- a/UICaboodle/BrowserView.mm +++ b/UICaboodle/BrowserView.mm @@ -35,6 +35,18 @@ extern NSString * const kCAFilterNearest; #define lprintf(args...) fprintf(stderr, args) +// WebThreadLocked {{{ +struct WebThreadLocked { + _finline WebThreadLocked() { + WebThreadLock(); + } + + _finline ~WebThreadLocked() { + WebThreadUnlock(); + } +}; +// }}} + template static inline void CYRelease(Type_ &value) { if (value != nil) { @@ -525,9 +537,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se error_ = false; - WebThreadLock(); + WebThreadLocked lock; [webview_ loadRequest:request]; - WebThreadUnlock(); } - (void) reloadURL { @@ -892,9 +903,8 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se if (button == [alert cancelButtonIndex]) { } else if (button == [alert firstOtherButtonIndex]) { if (request_ != nil) { - WebThreadLock(); + WebThreadLocked lock; [webview_ loadRequest:request_]; - WebThreadUnlock(); } } @@ -1108,7 +1118,7 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se } - (void) callFunction:(WebScriptObject *)function { - WebThreadLock(); + WebThreadLocked lock; WebView *webview([[webview_ _documentView] webView]); WebFrame *frame([webview mainFrame]); @@ -1141,8 +1151,6 @@ static void $UIWebViewWebViewDelegate$webViewClose$(UIWebViewWebViewDelegate *se settings->setJavaScriptCanOpenWindowsAutomatically(no);*/ [preferences setJavaScriptCanOpenWindowsAutomatically:maybe]; - - WebThreadUnlock(); } - (void) reloadButtonClicked { -- cgit v1.2.3