| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import java.util.HashSet; | 7 import java.util.HashSet; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A thread-safe event queue which provides both {@link #add} and {@link #remove
} functions with | 10 * A thread-safe event queue which provides both {@link #add} and {@link #remove
} functions with |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 private void execute(Object obj, ParamT parameter) { | 60 private void execute(Object obj, ParamT parameter) { |
| 61 ParameterRunnable<ParamT> runnable = (ParameterRunnable<ParamT>) obj
; | 61 ParameterRunnable<ParamT> runnable = (ParameterRunnable<ParamT>) obj
; |
| 62 runnable.run(parameter); | 62 runnable.run(parameter); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * A self removable {@link ParameterRunner}, uses a boolean {@link Parameter
Callback} to decide | 67 * A self removable {@link ParameterRunner}, uses a boolean {@link Parameter
Callback} to decide |
| 68 * whether removes self from {@link Event} or not. | 68 * whether removes self from {@link Event} or not. |
| 69 */ | 69 */ |
| 70 private static class SelfRemovableParameterRunnable<ParamT> | 70 private static final class SelfRemovableParameterRunnable<ParamT> |
| 71 implements ParameterRunnable<ParamT> { | 71 implements ParameterRunnable<ParamT> { |
| 72 private final ParameterCallback<Boolean, ParamT> mCallback; | 72 private final ParameterCallback<Boolean, ParamT> mCallback; |
| 73 private final Event<ParamT> mOwner; | 73 private final Event<ParamT> mOwner; |
| 74 | 74 |
| 75 // This lock is used to make sure mEvent is correctly set before remove
in run function. | 75 // This lock is used to make sure mEvent is correctly set before remove
in run function. |
| 76 // i.e. mOwner.add and assigment of mEvent need to be atomic. | 76 // i.e. mOwner.add and assigment of mEvent need to be atomic. |
| 77 private final Object mLock; | 77 private final Object mLock; |
| 78 private final Object mEvent; | 78 private final Object mEvent; |
| 79 | 79 |
| 80 private SelfRemovableParameterRunnable(Event<ParamT> owner, | 80 private SelfRemovableParameterRunnable(Event<ParamT> owner, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Returns true if there is no runnable attached to current instance. | 169 * Returns true if there is no runnable attached to current instance. |
| 170 */ | 170 */ |
| 171 public boolean isEmpty() { | 171 public boolean isEmpty() { |
| 172 synchronized (mSet) { | 172 synchronized (mSet) { |
| 173 return mSet.isEmpty(); | 173 return mSet.isEmpty(); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| OLD | NEW |