소스 검색

Remove pointless deadlock-inducing synchronisation

Change-Id: I1896aefedd97de3556690c33fb7ed141bfaa02d7
Reviewed-on: http://gerrit.dmdirc.com/1288
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.4
Chris Smith 14 년 전
부모
커밋
6d9e1cd3ce
1개의 변경된 파일17개의 추가작업 그리고 27개의 파일을 삭제
  1. 17
    27
      src/com/dmdirc/parser/common/CallbackObject.java

+ 17
- 27
src/com/dmdirc/parser/common/CallbackObject.java 파일 보기

@@ -32,7 +32,6 @@ import java.lang.annotation.Annotation;
32 32
 import java.lang.reflect.Constructor;
33 33
 import java.lang.reflect.InvocationTargetException;
34 34
 import java.lang.reflect.Method;
35
-import java.util.ArrayList;
36 35
 import java.util.Date;
37 36
 import java.util.HashMap;
38 37
 import java.util.List;
@@ -81,10 +80,8 @@ public abstract class CallbackObject {
81 80
      * @param eMethod OBject to callback to.
82 81
      */
83 82
     protected final void addCallback(final CallbackInterface eMethod) {
84
-        synchronized (callbackInfo) {
85
-            if (!callbackInfo.contains(eMethod)) {
86
-                callbackInfo.add(eMethod);
87
-            }
83
+        if (!callbackInfo.contains(eMethod)) {
84
+            callbackInfo.add(eMethod);
88 85
         }
89 86
     }
90 87
 
@@ -94,9 +91,7 @@ public abstract class CallbackObject {
94 91
      * @param eMethod Object that was being called back to.
95 92
      */
96 93
     protected final void delCallback(final CallbackInterface eMethod) {
97
-        synchronized (callbackInfo) {
98
-            callbackInfo.remove(eMethod);
99
-        }
94
+        callbackInfo.remove(eMethod);
100 95
     }
101 96
 
102 97
     /**
@@ -166,27 +161,22 @@ public abstract class CallbackObject {
166 161
 
167 162
         createFakeArgs(newArgs);
168 163
 
169
-        synchronized (callbackInfo) {
170
-            // The invoked callbacks could in theory register or delete new
171
-            // callbacks with this object, so we'll copy the array as well as
172
-            // synchronising to avoid CMEs.
173
-            for (CallbackInterface iface : new ArrayList<CallbackInterface>(callbackInfo)) {
174
-                try {
175
-                    type.getMethods()[0].invoke(iface, newArgs);
176
-                } catch (Exception e) {
177
-                    if (getType().equals(ErrorInfoListener.class)) {
178
-                        System.out.printf("Exception in onError Callback. [%s]\n", e.getMessage());
179
-                        e.printStackTrace();
180
-                    } else {
181
-                        final ParserError ei = new ParserError(ParserError.ERROR_ERROR,
182
-                                "Exception in callback (" + e.getMessage() + ")",
183
-                                myParser.getLastLine());
184
-                        ei.setException(e);
185
-                        callErrorInfo(ei);
186
-                    }
164
+        for (CallbackInterface iface : callbackInfo) {
165
+            try {
166
+                type.getMethods()[0].invoke(iface, newArgs);
167
+            } catch (Exception e) {
168
+                if (getType().equals(ErrorInfoListener.class)) {
169
+                    System.out.printf("Exception in onError Callback. [%s]\n", e.getMessage());
170
+                    e.printStackTrace();
171
+                } else {
172
+                    final ParserError ei = new ParserError(ParserError.ERROR_ERROR,
173
+                            "Exception in callback (" + e.getMessage() + ")",
174
+                            myParser.getLastLine());
175
+                    ei.setException(e);
176
+                    callErrorInfo(ei);
187 177
                 }
188
-                bResult = true;
189 178
             }
179
+            bResult = true;
190 180
         }
191 181
         
192 182
         return bResult;

Loading…
취소
저장