Move sync() to a different spot yet again.

This commit is contained in:
James Sanford 2012-11-08 18:29:10 -08:00
parent 8a977116c2
commit 52ca82acf1
3 changed files with 10 additions and 7 deletions

View File

@ -263,7 +263,7 @@ void android_config_init(char *output, int maxlen) {
} }
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_froop_app_kegs_DiskLoader_nativeSync( JNIEnv* env, jobject thiz) { Java_com_froop_app_kegs_CopyHelper_nativeSync( JNIEnv* env, jobject thiz) {
sync(); sync();
sync(); sync();
} }

View File

@ -54,6 +54,7 @@ public class CopyHelper {
if (mPreface != null) { if (mPreface != null) {
out.write(mPreface, 0, mPreface.length); out.write(mPreface, 0, mPreface.length);
} }
int totalread = 0;
do { do {
int numread = mInput.read(buf); int numread = mInput.read(buf);
if (numread <= 0) { if (numread <= 0) {
@ -61,11 +62,18 @@ public class CopyHelper {
} else { } else {
out.write(buf, 0, numread); out.write(buf, 0, numread);
} }
totalread += numread;
} while (true); } while (true);
out.close(); out.close();
if (totalread > 400 * 1024) {
nativeSync();
}
output_file.renameTo(final_file); output_file.renameTo(final_file);
if (mClose) { if (mClose) {
mInput.close(); mInput.close();
} }
} }
// See jni/android_driver.c:nativeSync()
private native void nativeSync();
} }

View File

@ -130,9 +130,7 @@ class DiskLoader extends AsyncTask<Void, Void, Boolean> {
} }
protected Boolean doInBackground(Void... params) { protected Boolean doInBackground(Void... params) {
Boolean result = extractImage(); return extractImage();
nativeSync(); // Flush new disk images before claiming they are ready.
return result;
} }
protected void onCancelled(final Boolean result) { protected void onCancelled(final Boolean result) {
@ -142,7 +140,4 @@ class DiskLoader extends AsyncTask<Void, Void, Boolean> {
protected void onPostExecute(final Boolean result) { protected void onPostExecute(final Boolean result) {
mNotify.onImageReady(result, mImage); mNotify.onImageReady(result, mImage);
} }
// See jni/android_driver.c:nativeSync()
private native void nativeSync();
} }