private void enqueueDiskWrite ( final MemoryCommitResult mcr , final Runnable postWriteRunnable ) { final Runnable writeToDiskRunnable = new Runnable ( ) { public void run ( ) { synchronized ( mWritingToDiskLock ) { writeToFile ( mcr ) ; } synchronized ( XmlStorage . this ) { mDiskWritesInFlight -- ; } if ( postWriteRunnable != null ) { postWriteRunnable . run ( ) ; } } } ; final boolean isFromSyncCommit = ( postWriteRunnable == null ) ; // Typical #commit() path with fewer allocations, doing a write on // the current thread. if ( isFromSyncCommit ) { boolean wasEmpty = false ; synchronized ( XmlStorage . this ) { wasEmpty = mDiskWritesInFlight == 1 ; } if ( wasEmpty ) { writeToDiskRunnable . run ( ) ; return ; } } QueuedWork . singleThreadExecutor ( ) . execute ( writeToDiskRunnable ) ; }
Enqueue an already - committed - to - memory result to be written to disk .