Skip to content

Commit 51d68ed

Browse files
committed
Simplified the memory footprint.
1 parent 1f8389f commit 51d68ed

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/main/java/rx/internal/schedulers/ScheduledAction.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import rx.functions.Action0;
2424
import rx.plugins.RxJavaPlugins;
2525
import rx.subscriptions.CompositeSubscription;
26-
import rx.subscriptions.Subscriptions;
2726

2827
/**
2928
* A {@code Runnable} that executes an {@code Action0} and can be cancelled. The analog is the
@@ -32,9 +31,6 @@
3231
public final class ScheduledAction implements Runnable, Subscription {
3332
final CompositeSubscription cancel;
3433
final Action0 action;
35-
volatile int once;
36-
static final AtomicIntegerFieldUpdater<ScheduledAction> ONCE_UPDATER
37-
= AtomicIntegerFieldUpdater.newUpdater(ScheduledAction.class, "once");
3834
/** Set by the run() method to avoid self interrupting at the end of the run method. */
3935
volatile Thread runner;
4036

@@ -71,9 +67,7 @@ public boolean isUnsubscribed() {
7167

7268
@Override
7369
public void unsubscribe() {
74-
if (ONCE_UPDATER.compareAndSet(this, 0, 1)) {
75-
cancel.unsubscribe();
76-
}
70+
cancel.unsubscribe();
7771
}
7872

7973
/**
@@ -92,7 +86,7 @@ public void add(Subscription s) {
9286
* @param f the future to add
9387
*/
9488
public void add(final Future<?> f) {
95-
cancel.add(Subscriptions.create(new FutureCompleter(f)));
89+
cancel.add(new FutureCompleter(f));
9690
}
9791

9892
/**
@@ -112,19 +106,25 @@ public void addParent(CompositeSubscription parent) {
112106
* prevent unnecessary self-interrupting if the unsubscription
113107
* happens from the same thread.
114108
*/
115-
private final class FutureCompleter implements Action0 {
109+
private final class FutureCompleter implements Subscription {
116110
private final Future<?> f;
117111

118112
private FutureCompleter(Future<?> f) {
119113
this.f = f;
120114
}
121115

122116
@Override
123-
public void call() {
117+
public void unsubscribe() {
124118
if (runner != Thread.currentThread()) {
125119
f.cancel(true);
120+
} else {
121+
f.cancel(false);
126122
}
127123
}
124+
@Override
125+
public boolean isUnsubscribed() {
126+
return f.isCancelled();
127+
}
128128
}
129129

130130
/** Remove a child subscription from a composite when unsubscribing. */

0 commit comments

Comments
 (0)