Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 290a228f authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Switch fastboot/init/libprocessgroup to std::this_thread::sleep_for.

Bug: http://b/32878766
Test: boots
Change-Id: Ie0ddfb7e60f2da5f6eefbb10c83a92e88c137ae3
parent f77d8b04
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -43,7 +43,9 @@
#include <sys/types.h>
#include <unistd.h>

#include <chrono>
#include <functional>
#include <thread>
#include <utility>
#include <vector>

@@ -301,7 +303,7 @@ static Transport* open_device() {
            announce = false;
            fprintf(stderr, "< waiting for %s >\n", serial ? serial : "any device");
        }
        usleep(1000);
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
    }
}

+17 −15
Original line number Diff line number Diff line
@@ -43,11 +43,15 @@
#include <linux/version.h>
#include <linux/usb/ch9.h>

#include <chrono>
#include <memory>
#include <thread>

#include "fastboot.h"
#include "usb.h"

using namespace std::chrono_literals;

#define MAX_RETRIES 5

/* Timeout in seconds for usb_wait_for_disconnect.
@@ -443,10 +447,9 @@ ssize_t LinuxUsbTransport::Read(void* _data, size_t len)
            if (n < 0) {
                DBG1("ERROR: n = %d, errno = %d (%s)\n",n, errno, strerror(errno));
                if (++retry > MAX_RETRIES) return -1;
            sleep( 1 );
           }
                std::this_thread::sleep_for(1s);
            }
        while( n < 0 );
        } while (n < 0);

        count += n;
        len -= n;
@@ -488,9 +491,8 @@ int LinuxUsbTransport::WaitForDisconnect()
{
  double deadline = now() + WAIT_FOR_DISCONNECT_TIMEOUT;
  while (now() < deadline) {
    if (access(handle_->fname, F_OK))
      return 0;
    usleep(50000);
    if (access(handle_->fname, F_OK)) return 0;
    std::this_thread::sleep_for(50ms);
  }
  return -1;
}
+0 −6
Original line number Diff line number Diff line
@@ -362,9 +362,3 @@ Transport* usb_open(ifc_match_func callback)
    std::unique_ptr<usb_handle> handle = find_usb_device(callback);
    return handle ? new WindowsUsbTransport(std::move(handle)) : nullptr;
}

// called from fastboot.c
void sleep(int seconds)
{
    Sleep(seconds * 1000);
}
+6 −7
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@
#include <linux/loop.h>
#include <linux/module.h>

#include <thread>

#include <selinux/selinux.h>
#include <selinux/label.h>

@@ -65,7 +67,6 @@
#include "util.h"

#define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW
#define UNMOUNT_CHECK_MS 5000
#define UNMOUNT_CHECK_TIMES 10

static constexpr std::chrono::nanoseconds kCommandRetryTimeout = 5s;
@@ -192,11 +193,9 @@ static void unmount_and_fsck(const struct mntent *entry) {
            close(fd);
            break;
        } else if (errno == EBUSY) {
            /* Some processes using |entry->mnt_dir| are still alive. Wait for a
             * while then retry.
             */
            TEMP_FAILURE_RETRY(
                usleep(UNMOUNT_CHECK_MS * 1000 / UNMOUNT_CHECK_TIMES));
            // Some processes using |entry->mnt_dir| are still alive. Wait for a
            // while then retry.
            std::this_thread::sleep_for(5000ms / UNMOUNT_CHECK_TIMES);
            continue;
        } else {
            /* Cannot open the device. Give up. */
@@ -749,7 +748,7 @@ static int do_powerctl(const std::vector<std::string>& args) {
            }

            // Wait a bit before recounting the number or running services.
            usleep(50000 /*us*/);
            std::this_thread::sleep_for(50ms);
        }
        LOG(VERBOSE) << "Terminating running services took " << t.duration() << " seconds";
    }
+2 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <linux/netlink.h>

#include <memory>
#include <thread>

#include <selinux/selinux.h>
#include <selinux/label.h>
@@ -841,7 +842,7 @@ try_loading_again:
    if (booting) {
        // If we're not fully booted, we may be missing
        // filesystems needed for firmware, wait and retry.
        usleep(100000);
        std::this_thread::sleep_for(100ms);
        booting = is_booting();
        goto try_loading_again;
    }
Loading