make sure that the sync thread is protected by a consistent lock
This commit is contained in:
committed by
Debajit Ghosh
parent
42b1648212
commit
3cff76aaa8
@@ -39,8 +39,9 @@ public abstract class AbstractThreadedSyncAdapter {
|
|||||||
private final AtomicInteger mNumSyncStarts;
|
private final AtomicInteger mNumSyncStarts;
|
||||||
private final ISyncAdapterImpl mISyncAdapterImpl;
|
private final ISyncAdapterImpl mISyncAdapterImpl;
|
||||||
|
|
||||||
// all accesses to this member variable must be synchronized on "this"
|
// all accesses to this member variable must be synchronized on mSyncThreadLock
|
||||||
private SyncThread mSyncThread;
|
private SyncThread mSyncThread;
|
||||||
|
private final Object mSyncThreadLock = new Object();
|
||||||
|
|
||||||
/** Kernel event log tag. Also listed in data/etc/event-log-tags. */
|
/** Kernel event log tag. Also listed in data/etc/event-log-tags. */
|
||||||
public static final int LOG_SYNC_DETAILS = 2743;
|
public static final int LOG_SYNC_DETAILS = 2743;
|
||||||
@@ -71,7 +72,7 @@ public abstract class AbstractThreadedSyncAdapter {
|
|||||||
boolean alreadyInProgress;
|
boolean alreadyInProgress;
|
||||||
// synchronize to make sure that mSyncThread doesn't change between when we
|
// synchronize to make sure that mSyncThread doesn't change between when we
|
||||||
// check it and when we use it
|
// check it and when we use it
|
||||||
synchronized (this) {
|
synchronized (mSyncThreadLock) {
|
||||||
if (mSyncThread == null) {
|
if (mSyncThread == null) {
|
||||||
if (mAutoInitialize
|
if (mAutoInitialize
|
||||||
&& extras != null
|
&& extras != null
|
||||||
@@ -102,7 +103,7 @@ public abstract class AbstractThreadedSyncAdapter {
|
|||||||
public void cancelSync(ISyncContext syncContext) {
|
public void cancelSync(ISyncContext syncContext) {
|
||||||
// synchronize to make sure that mSyncThread doesn't change between when we
|
// synchronize to make sure that mSyncThread doesn't change between when we
|
||||||
// check it and when we use it
|
// check it and when we use it
|
||||||
synchronized (this) {
|
synchronized (mSyncThreadLock) {
|
||||||
if (mSyncThread != null
|
if (mSyncThread != null
|
||||||
&& mSyncThread.mSyncContext.getISyncContext() == syncContext) {
|
&& mSyncThread.mSyncContext.getISyncContext() == syncContext) {
|
||||||
mSyncThread.interrupt();
|
mSyncThread.interrupt();
|
||||||
@@ -158,7 +159,7 @@ public abstract class AbstractThreadedSyncAdapter {
|
|||||||
}
|
}
|
||||||
// synchronize so that the assignment will be seen by other threads
|
// synchronize so that the assignment will be seen by other threads
|
||||||
// that also synchronize accesses to mSyncThread
|
// that also synchronize accesses to mSyncThread
|
||||||
synchronized (this) {
|
synchronized (mSyncThreadLock) {
|
||||||
mSyncThread = null;
|
mSyncThread = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user