OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/edk/system/message_pipe.h" | 5 #include "mojo/edk/system/message_pipe.h" |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/threading/platform_thread.h" // For |Sleep()|. | 8 #include "base/threading/platform_thread.h" // For |Sleep()|. |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "mojo/edk/system/waiter.h" | 10 #include "mojo/edk/system/waiter.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 HandleSignalsState hss; | 330 HandleSignalsState hss; |
331 | 331 |
332 int32_t buffer[1]; | 332 int32_t buffer[1]; |
333 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); | 333 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); |
334 uint32_t buffer_size; | 334 uint32_t buffer_size; |
335 | 335 |
336 // Always writable (until the other port is closed). | 336 // Always writable (until the other port is closed). |
337 waiter.Init(); | 337 waiter.Init(); |
338 hss = HandleSignalsState(); | 338 hss = HandleSignalsState(); |
339 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 339 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
340 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); | 340 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); |
341 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 341 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
342 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 342 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
343 waiter.Init(); | 343 waiter.Init(); |
344 hss = HandleSignalsState(); | 344 hss = HandleSignalsState(); |
345 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 345 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
346 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE | | 346 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE | |
347 MOJO_HANDLE_SIGNAL_WRITABLE, | 347 MOJO_HANDLE_SIGNAL_WRITABLE, |
348 0, &hss)); | 348 0, &hss)); |
349 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 349 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
350 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 350 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
351 | 351 |
352 // Not yet readable. | 352 // Not yet readable. |
353 waiter.Init(); | 353 waiter.Init(); |
354 ASSERT_EQ(MOJO_RESULT_OK, | 354 ASSERT_EQ( |
355 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); | 355 MOJO_RESULT_OK, |
| 356 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr)); |
356 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr)); | 357 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr)); |
357 hss = HandleSignalsState(); | 358 hss = HandleSignalsState(); |
358 mp->RemoveWaiter(0, &waiter, &hss); | 359 mp->RemoveAwakable(0, &waiter, &hss); |
359 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 360 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
360 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 361 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
361 | 362 |
362 // The peer is not closed. | 363 // The peer is not closed. |
363 waiter.Init(); | 364 waiter.Init(); |
364 ASSERT_EQ( | 365 ASSERT_EQ( |
365 MOJO_RESULT_OK, | 366 MOJO_RESULT_OK, |
366 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 2, nullptr)); | 367 mp->AddAwakable(0, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 2, nullptr)); |
367 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr)); | 368 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr)); |
368 hss = HandleSignalsState(); | 369 hss = HandleSignalsState(); |
369 mp->RemoveWaiter(0, &waiter, &hss); | 370 mp->RemoveAwakable(0, &waiter, &hss); |
370 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); | 371 EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); |
371 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 372 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
372 | 373 |
373 // Write from port 0 (to port 1), to make port 1 readable. | 374 // Write from port 0 (to port 1), to make port 1 readable. |
374 buffer[0] = 123456789; | 375 buffer[0] = 123456789; |
375 EXPECT_EQ(MOJO_RESULT_OK, | 376 EXPECT_EQ(MOJO_RESULT_OK, |
376 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize, | 377 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize, |
377 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 378 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
378 | 379 |
379 // Port 1 should already be readable now. | 380 // Port 1 should already be readable now. |
380 waiter.Init(); | 381 waiter.Init(); |
381 hss = HandleSignalsState(); | 382 hss = HandleSignalsState(); |
382 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 383 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
383 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss)); | 384 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 3, &hss)); |
384 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 385 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
385 hss.satisfied_signals); | 386 hss.satisfied_signals); |
386 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 387 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
387 waiter.Init(); | 388 waiter.Init(); |
388 hss = HandleSignalsState(); | 389 hss = HandleSignalsState(); |
389 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 390 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
390 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE | | 391 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE | |
391 MOJO_HANDLE_SIGNAL_WRITABLE, | 392 MOJO_HANDLE_SIGNAL_WRITABLE, |
392 0, &hss)); | 393 0, &hss)); |
393 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 394 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
394 hss.satisfied_signals); | 395 hss.satisfied_signals); |
395 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 396 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
396 // ... and still writable. | 397 // ... and still writable. |
397 waiter.Init(); | 398 waiter.Init(); |
398 hss = HandleSignalsState(); | 399 hss = HandleSignalsState(); |
399 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 400 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
400 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss)); | 401 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 4, &hss)); |
401 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 402 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
402 hss.satisfied_signals); | 403 hss.satisfied_signals); |
403 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 404 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
404 | 405 |
405 // Close port 0. | 406 // Close port 0. |
406 mp->Close(0); | 407 mp->Close(0); |
407 | 408 |
408 // Port 1 should be signaled with peer closed. | 409 // Port 1 should be signaled with peer closed. |
409 waiter.Init(); | 410 waiter.Init(); |
410 hss = HandleSignalsState(); | 411 hss = HandleSignalsState(); |
411 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 412 EXPECT_EQ( |
412 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 5, &hss)); | 413 MOJO_RESULT_ALREADY_EXISTS, |
| 414 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 5, &hss)); |
413 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 415 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
414 hss.satisfied_signals); | 416 hss.satisfied_signals); |
415 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 417 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
416 hss.satisfiable_signals); | 418 hss.satisfiable_signals); |
417 | 419 |
418 // Port 1 should not be writable. | 420 // Port 1 should not be writable. |
419 waiter.Init(); | 421 waiter.Init(); |
420 hss = HandleSignalsState(); | 422 hss = HandleSignalsState(); |
421 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 423 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
422 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 6, &hss)); | 424 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 6, &hss)); |
423 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 425 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
424 hss.satisfied_signals); | 426 hss.satisfied_signals); |
425 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 427 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
426 hss.satisfiable_signals); | 428 hss.satisfiable_signals); |
427 | 429 |
428 // But it should still be readable. | 430 // But it should still be readable. |
429 waiter.Init(); | 431 waiter.Init(); |
430 hss = HandleSignalsState(); | 432 hss = HandleSignalsState(); |
431 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 433 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
432 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 7, &hss)); | 434 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 7, &hss)); |
433 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 435 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
434 hss.satisfied_signals); | 436 hss.satisfied_signals); |
435 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 437 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, |
436 hss.satisfiable_signals); | 438 hss.satisfiable_signals); |
437 | 439 |
438 // Read from port 1. | 440 // Read from port 1. |
439 buffer[0] = 0; | 441 buffer[0] = 0; |
440 buffer_size = kBufferSize; | 442 buffer_size = kBufferSize; |
441 EXPECT_EQ(MOJO_RESULT_OK, | 443 EXPECT_EQ(MOJO_RESULT_OK, |
442 mp->ReadMessage(1, UserPointer<void>(buffer), | 444 mp->ReadMessage(1, UserPointer<void>(buffer), |
443 MakeUserPointer(&buffer_size), 0, nullptr, | 445 MakeUserPointer(&buffer_size), 0, nullptr, |
444 MOJO_READ_MESSAGE_FLAG_NONE)); | 446 MOJO_READ_MESSAGE_FLAG_NONE)); |
445 EXPECT_EQ(123456789, buffer[0]); | 447 EXPECT_EQ(123456789, buffer[0]); |
446 | 448 |
447 // Now port 1 should no longer be readable. | 449 // Now port 1 should no longer be readable. |
448 waiter.Init(); | 450 waiter.Init(); |
449 hss = HandleSignalsState(); | 451 hss = HandleSignalsState(); |
450 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 452 EXPECT_EQ( |
451 mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 8, nullptr)); | 453 MOJO_RESULT_FAILED_PRECONDITION, |
| 454 mp->AddAwakable(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 8, nullptr)); |
452 EXPECT_EQ(0u, hss.satisfied_signals); | 455 EXPECT_EQ(0u, hss.satisfied_signals); |
453 EXPECT_EQ(0u, hss.satisfiable_signals); | 456 EXPECT_EQ(0u, hss.satisfiable_signals); |
454 | 457 |
455 mp->Close(1); | 458 mp->Close(1); |
456 } | 459 } |
457 | 460 |
458 TEST(MessagePipeTest, ThreadedWaiting) { | 461 TEST(MessagePipeTest, ThreadedWaiting) { |
459 int32_t buffer[1]; | 462 int32_t buffer[1]; |
460 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); | 463 const uint32_t kBufferSize = static_cast<uint32_t>(sizeof(buffer)); |
461 | 464 |
462 MojoResult result; | 465 MojoResult result; |
463 uint32_t context; | 466 uint32_t context; |
464 | 467 |
465 // Write to wake up waiter waiting for read. | 468 // Write to wake up waiter waiting for read. |
466 { | 469 { |
467 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); | 470 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); |
468 test::SimpleWaiterThread thread(&result, &context); | 471 test::SimpleWaiterThread thread(&result, &context); |
469 | 472 |
470 thread.waiter()->Init(); | 473 thread.waiter()->Init(); |
471 ASSERT_EQ(MOJO_RESULT_OK, | 474 ASSERT_EQ(MOJO_RESULT_OK, |
472 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1, | 475 mp->AddAwakable(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, |
473 nullptr)); | 476 1, nullptr)); |
474 thread.Start(); | 477 thread.Start(); |
475 | 478 |
476 buffer[0] = 123456789; | 479 buffer[0] = 123456789; |
477 // Write from port 0 (to port 1), which should wake up the waiter. | 480 // Write from port 0 (to port 1), which should wake up the waiter. |
478 EXPECT_EQ(MOJO_RESULT_OK, | 481 EXPECT_EQ(MOJO_RESULT_OK, |
479 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize, | 482 mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize, |
480 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 483 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
481 | 484 |
482 HandleSignalsState hss; | 485 HandleSignalsState hss; |
483 mp->RemoveWaiter(1, thread.waiter(), &hss); | 486 mp->RemoveAwakable(1, thread.waiter(), &hss); |
484 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | 487 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, |
485 hss.satisfied_signals); | 488 hss.satisfied_signals); |
486 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | 489 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); |
487 | 490 |
488 mp->Close(0); | 491 mp->Close(0); |
489 mp->Close(1); | 492 mp->Close(1); |
490 } // Joins |thread|. | 493 } // Joins |thread|. |
491 // The waiter should have woken up successfully. | 494 // The waiter should have woken up successfully. |
492 EXPECT_EQ(MOJO_RESULT_OK, result); | 495 EXPECT_EQ(MOJO_RESULT_OK, result); |
493 EXPECT_EQ(1u, context); | 496 EXPECT_EQ(1u, context); |
494 | 497 |
495 // Close to cancel waiter. | 498 // Close to cancel waiter. |
496 { | 499 { |
497 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); | 500 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); |
498 test::SimpleWaiterThread thread(&result, &context); | 501 test::SimpleWaiterThread thread(&result, &context); |
499 | 502 |
500 thread.waiter()->Init(); | 503 thread.waiter()->Init(); |
501 ASSERT_EQ(MOJO_RESULT_OK, | 504 ASSERT_EQ(MOJO_RESULT_OK, |
502 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2, | 505 mp->AddAwakable(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, |
503 nullptr)); | 506 2, nullptr)); |
504 thread.Start(); | 507 thread.Start(); |
505 | 508 |
506 // Close port 1 first -- this should result in the waiter being cancelled. | 509 // Close port 1 first -- this should result in the waiter being cancelled. |
507 mp->CancelAllWaiters(1); | 510 mp->CancelAllAwakables(1); |
508 mp->Close(1); | 511 mp->Close(1); |
509 | 512 |
510 // Port 1 is closed, so |Dispatcher::RemoveWaiter()| wouldn't call into the | 513 // Port 1 is closed, so |Dispatcher::RemoveAwakable()| wouldn't call into |
511 // |MessagePipe| to remove any waiter. | 514 // the |MessagePipe| to remove any waiter. |
512 | 515 |
513 mp->Close(0); | 516 mp->Close(0); |
514 } // Joins |thread|. | 517 } // Joins |thread|. |
515 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 518 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
516 EXPECT_EQ(2u, context); | 519 EXPECT_EQ(2u, context); |
517 | 520 |
518 // Close to cancel waiter using peer closed signal. | 521 // Close to cancel waiter using peer closed signal. |
519 { | 522 { |
520 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); | 523 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); |
521 test::SimpleWaiterThread thread(&result, &context); | 524 test::SimpleWaiterThread thread(&result, &context); |
522 | 525 |
523 thread.waiter()->Init(); | 526 thread.waiter()->Init(); |
524 ASSERT_EQ(MOJO_RESULT_OK, | 527 ASSERT_EQ(MOJO_RESULT_OK, |
525 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_PEER_CLOSED, | 528 mp->AddAwakable(1, thread.waiter(), |
526 3, nullptr)); | 529 MOJO_HANDLE_SIGNAL_PEER_CLOSED, 3, nullptr)); |
527 thread.Start(); | 530 thread.Start(); |
528 | 531 |
529 // Close port 1 first -- this should result in the waiter being cancelled. | 532 // Close port 1 first -- this should result in the waiter being cancelled. |
530 mp->CancelAllWaiters(1); | 533 mp->CancelAllAwakables(1); |
531 mp->Close(1); | 534 mp->Close(1); |
532 | 535 |
533 // Port 1 is closed, so |Dispatcher::RemoveWaiter()| wouldn't call into the | 536 // Port 1 is closed, so |Dispatcher::RemoveAwakable()| wouldn't call into |
534 // |MessagePipe| to remove any waiter. | 537 // the |MessagePipe| to remove any waiter. |
535 | 538 |
536 mp->Close(0); | 539 mp->Close(0); |
537 } // Joins |thread|. | 540 } // Joins |thread|. |
538 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 541 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
539 EXPECT_EQ(3u, context); | 542 EXPECT_EQ(3u, context); |
540 | 543 |
541 // Close to make waiter un-wake-up-able. | 544 // Close to make waiter un-wake-up-able. |
542 { | 545 { |
543 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); | 546 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalLocal()); |
544 test::SimpleWaiterThread thread(&result, &context); | 547 test::SimpleWaiterThread thread(&result, &context); |
545 | 548 |
546 thread.waiter()->Init(); | 549 thread.waiter()->Init(); |
547 ASSERT_EQ(MOJO_RESULT_OK, | 550 ASSERT_EQ(MOJO_RESULT_OK, |
548 mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 4, | 551 mp->AddAwakable(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, |
549 nullptr)); | 552 4, nullptr)); |
550 thread.Start(); | 553 thread.Start(); |
551 | 554 |
552 // Close port 0 first -- this should wake the waiter up, since port 1 will | 555 // Close port 0 first -- this should wake the waiter up, since port 1 will |
553 // never be readable. | 556 // never be readable. |
554 mp->CancelAllWaiters(0); | 557 mp->CancelAllAwakables(0); |
555 mp->Close(0); | 558 mp->Close(0); |
556 | 559 |
557 HandleSignalsState hss; | 560 HandleSignalsState hss; |
558 mp->RemoveWaiter(1, thread.waiter(), &hss); | 561 mp->RemoveAwakable(1, thread.waiter(), &hss); |
559 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); | 562 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfied_signals); |
560 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); | 563 EXPECT_EQ(MOJO_HANDLE_SIGNAL_PEER_CLOSED, hss.satisfiable_signals); |
561 | 564 |
562 mp->CancelAllWaiters(1); | 565 mp->CancelAllAwakables(1); |
563 mp->Close(1); | 566 mp->Close(1); |
564 } // Joins |thread|. | 567 } // Joins |thread|. |
565 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 568 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
566 EXPECT_EQ(4u, context); | 569 EXPECT_EQ(4u, context); |
567 } | 570 } |
568 | 571 |
569 } // namespace | 572 } // namespace |
570 } // namespace system | 573 } // namespace system |
571 } // namespace mojo | 574 } // namespace mojo |
OLD | NEW |