Commit 44ffdf49 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[TaskScheduler]: Use ScopedBlockingCall to mark blocking tasks.

This CL uses ScopedBlockingCall to mark blocking calls in /device/usb.

This CL was created by replacing calls to AssertBlockingAllowed()
with instantiations of ScopedBlockingCall(MAY_BLOCK).
I kindly ask the reviewer to make sure of the following:
  - ScopedBlockingCall is instantiated in a scope with minimal CPU usage.
    If this is not the case, ScopedBlockingCall should be instantiated
    closer to the blocking call. See scoped_blocking_call.h for more
    info. Please let me know when/where the blocking call happens if this needs
    to be changed.
  - Parameter |blocking_type| matches expectation (MAY_BLOCK/WILL_BLOCK). See
    BlockingType for more info. While I assumed MAY_BLOCK by default, that might
    not be the best fit if we know that this callsite is guaranteed to block.
  - The ScopedBlockingCall's scope covers the entirety of the blocking operation
    previously asserted against by the AssertBlockingAllowed().

This CL was uploaded by git cl split.

R=reillyg@chromium.org

Bug: 874080
Change-Id: I0ee2ff9b2a81c101f943716b4965d4f21f231e41
Reviewed-on: https://chromium-review.googlesource.com/1191322Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594140}
parent 5fbe87da
......@@ -19,7 +19,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/sequence_checker.h"
#include "base/stl_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/device_event_log/device_event_log.h"
#include "device/usb/usb_device_linux.h"
......@@ -211,7 +211,6 @@ UsbDeviceHandleUsbfs::FileThreadHelper::~FileThreadHelper() {
}
void UsbDeviceHandleUsbfs::FileThreadHelper::Start() {
base::AssertBlockingAllowed();
sequence_checker_.DetachFromSequence();
DCHECK(sequence_checker_.CalledOnValidSequence());
......@@ -234,6 +233,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::SetConfiguration(
ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int rc = HANDLE_EINTR(
ioctl(fd_.get(), USBDEVFS_SETCONFIGURATION, &configuration_value));
if (rc)
......@@ -249,6 +249,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ReleaseInterface(
ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int rc = HANDLE_EINTR(
ioctl(fd_.get(), USBDEVFS_RELEASEINTERFACE, &interface_number));
if (rc) {
......@@ -272,6 +273,8 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::SetInterface(
usbdevfs_setinterface cmd = {0};
cmd.interface = interface_number;
cmd.altsetting = alternate_setting;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int rc = HANDLE_EINTR(ioctl(fd_.get(), USBDEVFS_SETINTERFACE, &cmd));
if (rc) {
USB_PLOG(DEBUG) << "Failed to set interface " << interface_number
......@@ -285,6 +288,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ResetDevice(
ResultCallback callback) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// TODO(reillyg): libusb releases interfaces before and then reclaims
// interfaces after a reset. We should probably do this too or document that
// callers have to call ClaimInterface as well.
......@@ -301,6 +305,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt(
DCHECK(sequence_checker_.CalledOnValidSequence());
int tmp_endpoint = endpoint_address;
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
int rc = HANDLE_EINTR(ioctl(fd_.get(), USBDEVFS_CLEAR_HALT, &tmp_endpoint));
if (rc) {
USB_PLOG(DEBUG) << "Failed to clear the stall condition on endpoint "
......@@ -313,6 +318,7 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::ClearHalt(
void UsbDeviceHandleUsbfs::FileThreadHelper::DiscardUrb(Transfer* transfer) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
HANDLE_EINTR(ioctl(fd_.get(), USBDEVFS_DISCARDURB, &transfer->urb));
task_runner_->PostTask(FROM_HERE,
......@@ -327,6 +333,8 @@ void UsbDeviceHandleUsbfs::FileThreadHelper::OnFileCanWriteWithoutBlocking() {
std::vector<usbdevfs_urb*> urbs;
urbs.reserve(MAX_URBS_PER_EVENT);
for (size_t i = 0; i < MAX_URBS_PER_EVENT; ++i) {
base::ScopedBlockingCall scoped_blocking_call(
base::BlockingType::MAY_BLOCK);
usbdevfs_urb* urb;
int rc = HANDLE_EINTR(ioctl(fd_.get(), USBDEVFS_REAPURBNDELAY, &urb));
if (rc) {
......
......@@ -15,7 +15,7 @@
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/thread_restrictions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"
......@@ -101,7 +101,7 @@ void UsbDeviceImpl::OpenOnBlockingThread(
OpenCallback callback,
scoped_refptr<base::TaskRunner> task_runner,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) {
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
libusb_device_handle* handle = nullptr;
const int rv = libusb_open(platform_device(), &handle);
if (LIBUSB_SUCCESS == rv) {
......
......@@ -20,8 +20,8 @@
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "components/device_event_log/device_event_log.h"
#include "device/udev_linux/udev_watcher.h"
......@@ -102,7 +102,7 @@ UsbServiceLinux::FileThreadHelper::~FileThreadHelper() {
// static
void UsbServiceLinux::FileThreadHelper::Start() {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::AssertBlockingAllowed();
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
// Initializing udev for device enumeration and monitoring may fail. In that
// case this service will continue to exist but no devices will be found.
......@@ -117,6 +117,8 @@ void UsbServiceLinux::FileThreadHelper::Start() {
void UsbServiceLinux::FileThreadHelper::OnDeviceAdded(
ScopedUdevDevicePtr device) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
const char* subsystem = udev_device_get_subsystem(device.get());
if (!subsystem || strcmp(subsystem, "usb") != 0)
return;
......@@ -176,6 +178,8 @@ void UsbServiceLinux::FileThreadHelper::OnDeviceAdded(
void UsbServiceLinux::FileThreadHelper::OnDeviceRemoved(
ScopedUdevDevicePtr device) {
DCHECK(sequence_checker_.CalledOnValidSequence());
base::ScopedBlockingCall scoped_blocking_call(base::BlockingType::MAY_BLOCK);
const char* device_path = udev_device_get_devnode(device.get());
if (device_path) {
task_runner_->PostTask(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment