Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Synchronize access to the context reference, in case someone reaches …

…out to getContext on the worker thread
  • Loading branch information...
commit b2ff7bba9b601dd4e0fca37a3a4215894b8376e1 1 parent bb9943f
@mttkay mttkay authored
View
44 ignition-core/ignition-core-lib/src/com/github/ignition/core/tasks/IgnitedAsyncTask.java
@@ -89,14 +89,17 @@ public boolean isCancelOnActivityBack() {
*/
@SuppressWarnings("unchecked")
public void connect(ContextT context) {
- this.context = context;
- if (context instanceof IgnitedAsyncTaskContextHandler) {
- this.contextHandler = (IgnitedAsyncTaskContextHandler<ProgressT, ReturnT>) context;
- } else if (delegateHandler == null && context instanceof IgnitedAsyncTaskHandler) {
- this.delegateHandler = (IgnitedAsyncTaskHandler<ContextT, ProgressT, ReturnT>) context;
- }
- if (delegateHandler != null) {
- delegateHandler.setContext(context);
+ // claim a lock for the context instance, in case getContext is used on the worker thread
+ synchronized (context) {
+ this.context = context;
+ if (context instanceof IgnitedAsyncTaskContextHandler) {
+ this.contextHandler = (IgnitedAsyncTaskContextHandler<ProgressT, ReturnT>) context;
+ } else if (delegateHandler == null && context instanceof IgnitedAsyncTaskHandler) {
+ this.delegateHandler = (IgnitedAsyncTaskHandler<ContextT, ProgressT, ReturnT>) context;
+ }
+ if (delegateHandler != null) {
+ delegateHandler.setContext(context);
+ }
}
}
@@ -119,13 +122,16 @@ public void connect(IgnitedAsyncTaskHandler<ContextT, ProgressT, ReturnT> handle
* implicit reference to the same context from any handlers you have connected.</b>
*/
public void disconnect() {
- this.contextHandler = null;
- this.context = null;
- if (delegateHandler != null) {
- if (delegateHandler instanceof Context) {
- delegateHandler = null;
- } else {
- delegateHandler.setContext(null);
+ // claim a lock for the context instance, in case getContext is used on the worker thread
+ synchronized (context) {
+ this.contextHandler = null;
+ this.context = null;
+ if (delegateHandler != null) {
+ if (delegateHandler instanceof Context) {
+ delegateHandler = null;
+ } else {
+ delegateHandler.setContext(null);
+ }
}
}
}
@@ -136,7 +142,9 @@ public void disconnect() {
*/
@Override
public ContextT getContext() {
- return context;
+ synchronized (context) {
+ return context;
+ }
}
/**
@@ -145,7 +153,9 @@ public ContextT getContext() {
*/
@Override
public void setContext(ContextT context) {
- this.context = context;
+ synchronized (context) {
+ this.context = context;
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.