OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/task_scheduler/task_scheduler_impl.h" | 5 #include "base/task_scheduler/task_scheduler_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 12, | 384 12, |
385 scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( | 385 scheduler_.GetMaxConcurrentTasksWithTraitsDeprecated( |
386 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock())); | 386 TaskTraits().WithPriority(TaskPriority::USER_BLOCKING).MayBlock())); |
387 } | 387 } |
388 | 388 |
389 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner | 389 // Verify that the RunsTasksOnCurrentThread() method of a SequencedTaskRunner |
390 // returns false when called from a task that isn't part of the sequence. | 390 // returns false when called from a task that isn't part of the sequence. |
391 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { | 391 TEST_F(TaskSchedulerImplTest, SequencedRunsTasksOnCurrentThread) { |
392 StartTaskScheduler(); | 392 StartTaskScheduler(); |
393 auto single_thread_task_runner = | 393 auto single_thread_task_runner = |
394 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 394 scheduler_.CreateSingleThreadTaskRunnerWithTraits( |
| 395 TaskTraits(), |
| 396 TaskScheduler::SingleThreadTaskRunnerThreadMode::SHARED); |
395 auto sequenced_task_runner = | 397 auto sequenced_task_runner = |
396 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); | 398 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
397 | 399 |
398 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 400 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
399 WaitableEvent::InitialState::NOT_SIGNALED); | 401 WaitableEvent::InitialState::NOT_SIGNALED); |
400 single_thread_task_runner->PostTask( | 402 single_thread_task_runner->PostTask( |
401 FROM_HERE, | 403 FROM_HERE, |
402 BindOnce( | 404 BindOnce( |
403 [](scoped_refptr<TaskRunner> sequenced_task_runner, | 405 [](scoped_refptr<TaskRunner> sequenced_task_runner, |
404 WaitableEvent* task_ran) { | 406 WaitableEvent* task_ran) { |
405 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); | 407 EXPECT_FALSE(sequenced_task_runner->RunsTasksOnCurrentThread()); |
406 task_ran->Signal(); | 408 task_ran->Signal(); |
407 }, | 409 }, |
408 sequenced_task_runner, Unretained(&task_ran))); | 410 sequenced_task_runner, Unretained(&task_ran))); |
409 task_ran.Wait(); | 411 task_ran.Wait(); |
410 } | 412 } |
411 | 413 |
412 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner | 414 // Verify that the RunsTasksOnCurrentThread() method of a SingleThreadTaskRunner |
413 // returns false when called from a task that isn't part of the sequence. | 415 // returns false when called from a task that isn't part of the sequence. |
414 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { | 416 TEST_F(TaskSchedulerImplTest, SingleThreadRunsTasksOnCurrentThread) { |
415 StartTaskScheduler(); | 417 StartTaskScheduler(); |
416 auto sequenced_task_runner = | 418 auto sequenced_task_runner = |
417 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); | 419 scheduler_.CreateSequencedTaskRunnerWithTraits(TaskTraits()); |
418 auto single_thread_task_runner = | 420 auto single_thread_task_runner = |
419 scheduler_.CreateSingleThreadTaskRunnerWithTraits(TaskTraits()); | 421 scheduler_.CreateSingleThreadTaskRunnerWithTraits( |
| 422 TaskTraits(), |
| 423 TaskScheduler::SingleThreadTaskRunnerThreadMode::SHARED); |
420 | 424 |
421 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 425 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
422 WaitableEvent::InitialState::NOT_SIGNALED); | 426 WaitableEvent::InitialState::NOT_SIGNALED); |
423 sequenced_task_runner->PostTask( | 427 sequenced_task_runner->PostTask( |
424 FROM_HERE, | 428 FROM_HERE, |
425 BindOnce( | 429 BindOnce( |
426 [](scoped_refptr<TaskRunner> single_thread_task_runner, | 430 [](scoped_refptr<TaskRunner> single_thread_task_runner, |
427 WaitableEvent* task_ran) { | 431 WaitableEvent* task_ran) { |
428 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); | 432 EXPECT_FALSE(single_thread_task_runner->RunsTasksOnCurrentThread()); |
429 task_ran->Signal(); | 433 task_ran->Signal(); |
430 }, | 434 }, |
431 single_thread_task_runner, Unretained(&task_ran))); | 435 single_thread_task_runner, Unretained(&task_ran))); |
432 task_ran.Wait(); | 436 task_ran.Wait(); |
433 } | 437 } |
434 | 438 |
435 #if defined(OS_WIN) | 439 #if defined(OS_WIN) |
436 TEST_F(TaskSchedulerImplTest, COMSTATaskRunnersRunWithCOMSTA) { | 440 TEST_F(TaskSchedulerImplTest, COMSTATaskRunnersRunWithCOMSTA) { |
437 StartTaskScheduler(); | 441 StartTaskScheduler(); |
438 auto com_sta_task_runner = | 442 auto com_sta_task_runner = scheduler_.CreateCOMSTATaskRunnerWithTraits( |
439 scheduler_.CreateCOMSTATaskRunnerWithTraits(TaskTraits()); | 443 TaskTraits(), TaskScheduler::SingleThreadTaskRunnerThreadMode::SHARED); |
440 | 444 |
441 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, | 445 WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL, |
442 WaitableEvent::InitialState::NOT_SIGNALED); | 446 WaitableEvent::InitialState::NOT_SIGNALED); |
443 com_sta_task_runner->PostTask( | 447 com_sta_task_runner->PostTask( |
444 FROM_HERE, | 448 FROM_HERE, |
445 Bind( | 449 Bind( |
446 [](scoped_refptr<TaskRunner> single_thread_task_runner, | 450 [](scoped_refptr<TaskRunner> single_thread_task_runner, |
447 WaitableEvent* task_ran) { | 451 WaitableEvent* task_ran) { |
448 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); | 452 HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); |
449 if (SUCCEEDED(hr)) { | 453 if (SUCCEEDED(hr)) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // Give a chance for the file watcher to fire before closing the handles. | 525 // Give a chance for the file watcher to fire before closing the handles. |
522 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 526 PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
523 | 527 |
524 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0]))); | 528 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[0]))); |
525 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1]))); | 529 EXPECT_EQ(0, IGNORE_EINTR(close(pipes[1]))); |
526 } | 530 } |
527 #endif // defined(OS_POSIX) | 531 #endif // defined(OS_POSIX) |
528 | 532 |
529 } // namespace internal | 533 } // namespace internal |
530 } // namespace base | 534 } // namespace base |
OLD | NEW |