New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 796830 link

Starred by 2 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task



Sign in to add a comment

midi::TaskService should eliminate base::ConditionVariable::Wait use on the I/O thread

Project Member Reported by toyoshim@chromium.org, Dec 21 2017

Issue description

MidiManager runs on the I/O thread, and use worker threads to run platform specific device operations that may need blocking operations.

In current design, we allows to access MidiManager instance from the worker threads, but it could introduce a race issue on MidiManager destruction. To avoid the race, MidiManager relies on midi::TaskService that provides a safe way to protect MidiManager during MidiManager methods run on another thread. But the TaskService required a condition variable wait call when MidiManager is going to be destructed on the I/O thread. This is not ideal, but the way we do today.

Background:
In the original design, midi::TaskService uses a rw-lock that wasn't assumed as a blocking call as lock operations were. But now that base/ does not provide rw-lock any more, and we needed to rewrite it with locks and a condition variable. At this point, waiting a condition variable was OK even on the I/O thread, but now it's asserted on debug build. This reveal the downside of the original design.

Plan:
Once we finish mojofication on media/midi, we'd try running whole MidiService on a dedicated thread rather than I/O thread. Or change MidiService to post all tasks to a dedicated thread that runs MidiManager. Thus we only need to call sync or block methods only on browser process shutdown there we are allowed to call them.
 
Project Member

Comment 1 by bugdroid1@chromium.org, Jan 9 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/129091daa1acd388aa674c73dbae06dcca03a75a

commit 129091daa1acd388aa674c73dbae06dcca03a75a
Author: Takashi Toyoshima <toyoshim@chromium.org>
Date: Tue Jan 09 12:28:46 2018

Allow to wait a condition variable in midi::TaskService

midi::TaskService is a utility class to allow users to run a task
that is bound to the class instance on another thread safely.

To destruct the instance safely, we need to ensure that no tasks
that may refer the instance are not running on other threads.

Originally the feature was implemented with rwlock, but when rwlock
was removed from the base library, it was changed to use a
condition variable.

Change-Id: I0bfe71800ce43332e96623f2a415975d481c9efb
Bug: 796830
Reviewed-on: https://chromium-review.googlesource.com/833851
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#527971}
[modify] https://crrev.com/129091daa1acd388aa674c73dbae06dcca03a75a/base/threading/thread_restrictions.h
[modify] https://crrev.com/129091daa1acd388aa674c73dbae06dcca03a75a/media/midi/task_service.cc

Comment 2 by raymes@chromium.org, Jan 11 2018

Cc: raymes@chromium.org sa...@chromium.org toyoshim@chromium.org
 Issue 801039  has been merged into this issue.

Comment 3 by gab@chromium.org, Apr 12 2018

Components: -Internals>TaskScheduler

Sign in to add a comment