Tighten lock in writeState
This commit is contained in:
parent
3369774158
commit
5a15f52a29
@ -407,26 +407,31 @@ public final class SongTimeline {
|
|||||||
{
|
{
|
||||||
// Must update PlaybackService.STATE_VERSION when changing behavior
|
// Must update PlaybackService.STATE_VERSION when changing behavior
|
||||||
// here.
|
// here.
|
||||||
|
|
||||||
|
ArrayList<Song> songs;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
ArrayList<Song> songs = mSongs;
|
// Just grab a copy and release the lock soon:
|
||||||
|
// Performing the actual IO is pretty expensive and
|
||||||
int size = songs.size();
|
// could stall UI elements accessing the timeline.
|
||||||
out.writeInt(size);
|
songs = new ArrayList(mSongs);
|
||||||
|
|
||||||
for (int i = 0; i != size; ++i) {
|
|
||||||
Song song = songs.get(i);
|
|
||||||
if (song == null) {
|
|
||||||
out.writeLong(-1);
|
|
||||||
} else {
|
|
||||||
out.writeLong(song.id);
|
|
||||||
out.writeInt(song.flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeInt(mCurrentPos);
|
|
||||||
out.writeInt(mFinishAction);
|
|
||||||
out.writeInt(mShuffleMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int size = songs.size();
|
||||||
|
out.writeInt(size);
|
||||||
|
|
||||||
|
for (int i = 0; i != size; ++i) {
|
||||||
|
Song song = songs.get(i);
|
||||||
|
if (song == null) {
|
||||||
|
out.writeLong(-1);
|
||||||
|
} else {
|
||||||
|
out.writeLong(song.id);
|
||||||
|
out.writeInt(song.flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeInt(mCurrentPos);
|
||||||
|
out.writeInt(mFinishAction);
|
||||||
|
out.writeInt(mShuffleMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user