OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009-2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009-2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return CrossThreadTask8<typename CrossThreadCopier<P1>::Type, MP1, typename
CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, | 471 return CrossThreadTask8<typename CrossThreadCopier<P1>::Type, MP1, typename
CrossThreadCopier<P2>::Type, MP2, typename CrossThreadCopier<P3>::Type, MP3, |
472 typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::T
ype, MP5, typename CrossThreadCopier<P6>::Type, MP6, | 472 typename CrossThreadCopier<P4>::Type, MP4, typename CrossThreadCopier<P5>::T
ype, MP5, typename CrossThreadCopier<P6>::Type, MP6, |
473 typename CrossThreadCopier<P7>::Type, MP7, typename CrossThreadCopier<P8>::T
ype, MP8>::create( | 473 typename CrossThreadCopier<P7>::Type, MP7, typename CrossThreadCopier<P8>::T
ype, MP8>::create( |
474 method, | 474 method, |
475 CrossThreadCopier<P1>::co
py(parameter1), CrossThreadCopier<P2>::copy(parameter2), | 475 CrossThreadCopier<P1>::co
py(parameter1), CrossThreadCopier<P2>::copy(parameter2), |
476 CrossThreadCopier<P3>::co
py(parameter3), CrossThreadCopier<P4>::copy(parameter4), | 476 CrossThreadCopier<P3>::co
py(parameter3), CrossThreadCopier<P4>::copy(parameter4), |
477 CrossThreadCopier<P5>::co
py(parameter5), CrossThreadCopier<P6>::copy(parameter6), | 477 CrossThreadCopier<P5>::co
py(parameter5), CrossThreadCopier<P6>::copy(parameter6), |
478 CrossThreadCopier<P7>::co
py(parameter7), CrossThreadCopier<P8>::copy(parameter8)); | 478 CrossThreadCopier<P7>::co
py(parameter7), CrossThreadCopier<P8>::copy(parameter8)); |
479 } | 479 } |
480 | 480 |
| 481 // createCrossThreadTask(...) is similar to but safer than |
| 482 // CallClosureTask::create(bind(...)) for cross-thread task posting. |
| 483 // postTask(CallClosureTask::create(bind(...))) is not thread-safe |
| 484 // due to temporary objects, see http://crbug.com/390851 for details. |
| 485 // |
| 486 // createCrossThreadTask copies its arguments into Closure |
| 487 // by CrossThreadCopier, rather than copy constructors. |
| 488 // This means it creates deep copy of each argument if necessary. |
| 489 // |
| 490 // To pass things that cannot be copied by CrossThreadCopier |
| 491 // (e.g. pointers), use AllowCrossThreadAccess() explicitly. |
| 492 // |
| 493 // If the first argument of createCrossThreadTask |
| 494 // is a pointer to a member function in class C, |
| 495 // then the second argument of createCrossThreadTask |
| 496 // is a raw pointer (C*) or a weak pointer (const WeakPtr<C>&) to C. |
| 497 // createCrossThreadTask does not use CrossThreadCopier for the pointer, |
| 498 // assuming the user of createCrossThreadTask knows that the pointer |
| 499 // can be accessed from the target thread. |
| 500 |
| 501 // Templates for member function of class C + raw pointer (C*) |
| 502 // which do not use CrossThreadCopier for the raw pointer (a1) |
| 503 template<typename C> |
| 504 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 505 void (C::*function)(), |
| 506 C* p) |
| 507 { |
| 508 return CallClosureTask::create(bind(function, |
| 509 p)); |
| 510 } |
| 511 |
| 512 template<typename C, typename P1, typename MP1> |
| 513 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 514 void (C::*function)(MP1), |
| 515 C* p, const P1& parameter1) |
| 516 { |
| 517 return CallClosureTask::create(bind(function, |
| 518 p, |
| 519 CrossThreadCopier<P1>::copy(parameter1))); |
| 520 } |
| 521 |
| 522 template<typename C, typename P1, typename MP1, typename P2, typename MP2> |
| 523 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 524 void (C::*function)(MP1, MP2), |
| 525 C* p, const P1& parameter1, const P2& parameter2) |
| 526 { |
| 527 return CallClosureTask::create(bind(function, |
| 528 p, |
| 529 CrossThreadCopier<P1>::copy(parameter1), |
| 530 CrossThreadCopier<P2>::copy(parameter2))); |
| 531 } |
| 532 |
| 533 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3> |
| 534 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 535 void (C::*function)(MP1, MP2, MP3), |
| 536 C* p, const P1& parameter1, const P2& parameter2, const P3& parameter3) |
| 537 { |
| 538 return CallClosureTask::create(bind(function, |
| 539 p, |
| 540 CrossThreadCopier<P1>::copy(parameter1), |
| 541 CrossThreadCopier<P2>::copy(parameter2), |
| 542 CrossThreadCopier<P3>::copy(parameter3))); |
| 543 } |
| 544 |
| 545 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3, typename P4, typename MP4> |
| 546 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 547 void (C::*function)(MP1, MP2, MP3, MP4), |
| 548 C* p, const P1& parameter1, const P2& parameter2, const P3& parameter3, cons
t P4& parameter4) |
| 549 { |
| 550 return CallClosureTask::create(bind(function, |
| 551 p, |
| 552 CrossThreadCopier<P1>::copy(parameter1), |
| 553 CrossThreadCopier<P2>::copy(parameter2), |
| 554 CrossThreadCopier<P3>::copy(parameter3), |
| 555 CrossThreadCopier<P4>::copy(parameter4))); |
| 556 } |
| 557 |
| 558 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5> |
| 559 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 560 void (C::*function)(MP1, MP2, MP3, MP4, MP5), |
| 561 C* p, const P1& parameter1, const P2& parameter2, const P3& parameter3, cons
t P4& parameter4, const P5& parameter5) |
| 562 { |
| 563 return CallClosureTask::create(bind(function, |
| 564 p, |
| 565 CrossThreadCopier<P1>::copy(parameter1), |
| 566 CrossThreadCopier<P2>::copy(parameter2), |
| 567 CrossThreadCopier<P3>::copy(parameter3), |
| 568 CrossThreadCopier<P4>::copy(parameter4), |
| 569 CrossThreadCopier<P5>::copy(parameter5))); |
| 570 } |
| 571 |
| 572 // Templates for member function of class C + weak pointer (const WeakPtr<C>&) |
| 573 // which do not use CrossThreadCopier for the weak pointer (a1) |
| 574 template<typename C> |
| 575 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 576 void (C::*function)(), |
| 577 const WeakPtr<C>& p) |
| 578 { |
| 579 return CallClosureTask::create(bind(function, |
| 580 p)); |
| 581 } |
| 582 |
| 583 template<typename C, typename P1, typename MP1> |
| 584 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 585 void (C::*function)(MP1), |
| 586 const WeakPtr<C>& p, const P1& parameter1) |
| 587 { |
| 588 return CallClosureTask::create(bind(function, |
| 589 p, |
| 590 CrossThreadCopier<P1>::copy(parameter1))); |
| 591 } |
| 592 |
| 593 template<typename C, typename P1, typename MP1, typename P2, typename MP2> |
| 594 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 595 void (C::*function)(MP1, MP2), |
| 596 const WeakPtr<C>& p, const P1& parameter1, const P2& parameter2) |
| 597 { |
| 598 return CallClosureTask::create(bind(function, |
| 599 p, |
| 600 CrossThreadCopier<P1>::copy(parameter1), |
| 601 CrossThreadCopier<P2>::copy(parameter2))); |
| 602 } |
| 603 |
| 604 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3> |
| 605 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 606 void (C::*function)(MP1, MP2, MP3), |
| 607 const WeakPtr<C>& p, const P1& parameter1, const P2& parameter2, const P3& p
arameter3) |
| 608 { |
| 609 return CallClosureTask::create(bind(function, |
| 610 p, |
| 611 CrossThreadCopier<P1>::copy(parameter1), |
| 612 CrossThreadCopier<P2>::copy(parameter2), |
| 613 CrossThreadCopier<P3>::copy(parameter3))); |
| 614 } |
| 615 |
| 616 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3, typename P4, typename MP4> |
| 617 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 618 void (C::*function)(MP1, MP2, MP3, MP4), |
| 619 const WeakPtr<C>& p, const P1& parameter1, const P2& parameter2, const P3& p
arameter3, const P4& parameter4) |
| 620 { |
| 621 return CallClosureTask::create(bind(function, |
| 622 p, |
| 623 CrossThreadCopier<P1>::copy(parameter1), |
| 624 CrossThreadCopier<P2>::copy(parameter2), |
| 625 CrossThreadCopier<P3>::copy(parameter3), |
| 626 CrossThreadCopier<P4>::copy(parameter4))); |
| 627 } |
| 628 |
| 629 template<typename C, typename P1, typename MP1, typename P2, typename MP2, typen
ame P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5> |
| 630 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 631 void (C::*function)(MP1, MP2, MP3, MP4, MP5), |
| 632 const WeakPtr<C>& p, const P1& parameter1, const P2& parameter2, const P3& p
arameter3, const P4& parameter4, const P5& parameter5) |
| 633 { |
| 634 return CallClosureTask::create(bind(function, |
| 635 p, |
| 636 CrossThreadCopier<P1>::copy(parameter1), |
| 637 CrossThreadCopier<P2>::copy(parameter2), |
| 638 CrossThreadCopier<P3>::copy(parameter3), |
| 639 CrossThreadCopier<P4>::copy(parameter4), |
| 640 CrossThreadCopier<P5>::copy(parameter5))); |
| 641 } |
| 642 |
| 643 // Other cases; use CrossThreadCopier for all arguments |
| 644 template<typename FunctionType> |
| 645 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 646 FunctionType function) |
| 647 { |
| 648 return CallClosureTask::create(bind(function)); |
| 649 } |
| 650 |
| 651 template<typename FunctionType, typename P1> |
| 652 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 653 FunctionType function, |
| 654 const P1& parameter1) |
| 655 { |
| 656 return CallClosureTask::create(bind(function, |
| 657 CrossThreadCopier<P1>::copy(parameter1))); |
| 658 } |
| 659 |
| 660 template<typename FunctionType, typename P1, typename P2> |
| 661 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 662 FunctionType function, |
| 663 const P1& parameter1, const P2& parameter2) |
| 664 { |
| 665 return CallClosureTask::create(bind(function, |
| 666 CrossThreadCopier<P1>::copy(parameter1), |
| 667 CrossThreadCopier<P2>::copy(parameter2))); |
| 668 } |
| 669 |
| 670 template<typename FunctionType, typename P1, typename P2, typename P3> |
| 671 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 672 FunctionType function, |
| 673 const P1& parameter1, const P2& parameter2, const P3& parameter3) |
| 674 { |
| 675 return CallClosureTask::create(bind(function, |
| 676 CrossThreadCopier<P1>::copy(parameter1), |
| 677 CrossThreadCopier<P2>::copy(parameter2), |
| 678 CrossThreadCopier<P3>::copy(parameter3))); |
| 679 } |
| 680 |
| 681 template<typename FunctionType, typename P1, typename P2, typename P3, typename
P4> |
| 682 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 683 FunctionType function, |
| 684 const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4&
parameter4) |
| 685 { |
| 686 return CallClosureTask::create(bind(function, |
| 687 CrossThreadCopier<P1>::copy(parameter1), |
| 688 CrossThreadCopier<P2>::copy(parameter2), |
| 689 CrossThreadCopier<P3>::copy(parameter3), |
| 690 CrossThreadCopier<P4>::copy(parameter4))); |
| 691 } |
| 692 |
| 693 template<typename FunctionType, typename P1, typename P2, typename P3, typename
P4, typename P5> |
| 694 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 695 FunctionType function, |
| 696 const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4&
parameter4, const P5& parameter5) |
| 697 { |
| 698 return CallClosureTask::create(bind(function, |
| 699 CrossThreadCopier<P1>::copy(parameter1), |
| 700 CrossThreadCopier<P2>::copy(parameter2), |
| 701 CrossThreadCopier<P3>::copy(parameter3), |
| 702 CrossThreadCopier<P4>::copy(parameter4), |
| 703 CrossThreadCopier<P5>::copy(parameter5))); |
| 704 } |
| 705 |
| 706 template<typename FunctionType, typename P1, typename P2, typename P3, typename
P4, typename P5, typename P6> |
| 707 PassOwnPtr<ExecutionContextTask> createCrossThreadTask( |
| 708 FunctionType function, |
| 709 const P1& parameter1, const P2& parameter2, const P3& parameter3, const P4&
parameter4, const P5& parameter5, const P6& parameter6) |
| 710 { |
| 711 return CallClosureTask::create(bind(function, |
| 712 CrossThreadCopier<P1>::copy(parameter1), |
| 713 CrossThreadCopier<P2>::copy(parameter2), |
| 714 CrossThreadCopier<P3>::copy(parameter3), |
| 715 CrossThreadCopier<P4>::copy(parameter4), |
| 716 CrossThreadCopier<P5>::copy(parameter5), |
| 717 CrossThreadCopier<P6>::copy(parameter6))); |
| 718 } |
| 719 |
481 } // namespace WebCore | 720 } // namespace WebCore |
482 | 721 |
483 #endif // CrossThreadTask_h | 722 #endif // CrossThreadTask_h |
OLD | NEW |