Skip to content

Commit e3e4ec7

Browse files
weivincewangGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Skip unnecessary sleep during shutdown"
2 parents f583ff6 + 8c00e42 commit e3e4ec7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

init/reboot.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ static void DumpUmountDebuggingInfo(bool dump_all) {
267267

268268
static UmountStat UmountPartitions(std::chrono::milliseconds timeout) {
269269
Timer t;
270-
UmountStat stat = UMOUNT_STAT_TIMEOUT;
271-
int retry = 0;
272270
/* data partition needs all pending writes to be completed and all emulated partitions
273271
* umounted.If the current waiting is not good enough, give
274272
* up and leave it to e2fsck after reboot to fix it.
@@ -280,25 +278,27 @@ static UmountStat UmountPartitions(std::chrono::milliseconds timeout) {
280278
return UMOUNT_STAT_ERROR;
281279
}
282280
if (block_devices.size() == 0) {
283-
stat = UMOUNT_STAT_SUCCESS;
284-
break;
281+
return UMOUNT_STAT_SUCCESS;
285282
}
286-
if ((timeout < t.duration()) && retry > 0) { // try umount at least once
287-
stat = UMOUNT_STAT_TIMEOUT;
288-
break;
283+
bool unmount_done = true;
284+
if (emulated_devices.size() > 0) {
285+
unmount_done = std::all_of(emulated_devices.begin(), emulated_devices.end(),
286+
[](auto& entry) { return entry.Umount(); });
287+
if (unmount_done) {
288+
sync();
289+
}
289290
}
290-
if (emulated_devices.size() > 0 &&
291-
std::all_of(emulated_devices.begin(), emulated_devices.end(),
292-
[](auto& entry) { return entry.Umount(); })) {
293-
sync();
291+
unmount_done = std::all_of(block_devices.begin(), block_devices.end(),
292+
[](auto& entry) { return entry.Umount(); }) &&
293+
unmount_done;
294+
if (unmount_done) {
295+
return UMOUNT_STAT_SUCCESS;
294296
}
295-
for (auto& entry : block_devices) {
296-
entry.Umount();
297+
if ((timeout < t.duration())) { // try umount at least once
298+
return UMOUNT_STAT_TIMEOUT;
297299
}
298-
retry++;
299300
std::this_thread::sleep_for(100ms);
300301
}
301-
return stat;
302302
}
303303

304304
static void KillAllProcesses() { android::base::WriteStringToFile("i", "/proc/sysrq-trigger"); }

0 commit comments

Comments
 (0)