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 // createCallClosureTask(...) is similar to but safer than | |
tkent
2014/07/10 03:36:14
I'd like to name this createCrossThreadTask.
This
hiroshige
2014/07/10 04:39:56
The name createCrossThreadTask seems good, but doe
tyoshino (SeeGerritForStatus)
2014/07/10 04:50:04
Yes we can also rename 1 later to align naming con
tkent
2014/07/10 05:06:23
I'm sorry, I meant createCallbackTask.
Smaller pa
hiroshige
2014/07/10 07:16:31
Probably yes.
I renamed createCallClosureTask to
| |
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 // createCallClosureTask 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 createCallClosureTask | |
494 // is a pointer to a member function in class C, | |
495 // then the second argument of createCallClosureTask | |
496 // is a raw pointer (C*) or a weak pointer (const WeakPtr<C>&) to C. | |
497 // createCallClosureTask does not use CrossThreadCopier for the pointer, | |
498 // assuming the user of createCallClosureTask 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 R, typename C> | |
tkent
2014/07/10 03:36:14
Is R necessary? it's always void, right?
hiroshige
2014/07/10 04:39:56
Right, because CallClosureTask::create require Clo
hiroshige
2014/07/10 07:16:32
Done.
| |
504 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(), C* a1 ) | |
505 { | |
506 return CallClosureTask::create(bind(function, | |
507 a1)); | |
508 } | |
509 | |
510 template<typename R, typename C, typename P2, typename A2> | |
511 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2), C* a1, const A2& a2) | |
512 { | |
513 return CallClosureTask::create(bind(function, | |
514 a1, | |
515 CrossThreadCopier<A2>::copy(a2))); | |
516 } | |
517 | |
518 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3> | |
519 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3), C* a1, const A2& a2, const A3& a3) | |
520 { | |
521 return CallClosureTask::create(bind(function, | |
522 a1, | |
523 CrossThreadCopier<A2>::copy(a2), | |
524 CrossThreadCopier<A3>::copy(a3))); | |
525 } | |
526 | |
527 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4> | |
528 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4), C* a1, const A2& a2, const A3& a3, const A4& a4) | |
529 { | |
530 return CallClosureTask::create(bind(function, | |
531 a1, | |
532 CrossThreadCopier<A2>::copy(a2), | |
533 CrossThreadCopier<A3>::copy(a3), | |
534 CrossThreadCopier<A4>::copy(a4))); | |
535 } | |
536 | |
537 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4, typename P5, typename A5> | |
538 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4, P5), C* a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) | |
539 { | |
540 return CallClosureTask::create(bind(function, | |
541 a1, | |
542 CrossThreadCopier<A2>::copy(a2), | |
543 CrossThreadCopier<A3>::copy(a3), | |
544 CrossThreadCopier<A4>::copy(a4), | |
545 CrossThreadCopier<A5>::copy(a5))); | |
546 } | |
547 | |
548 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4, typename P5, typename A5, typename P6, typename A 6> | |
549 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4, P5, P6), C* a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, cons t A6& a6) | |
550 { | |
551 return CallClosureTask::create(bind(function, | |
552 a1, | |
553 CrossThreadCopier<A2>::copy(a2), | |
554 CrossThreadCopier<A3>::copy(a3), | |
555 CrossThreadCopier<A4>::copy(a4), | |
556 CrossThreadCopier<A5>::copy(a5), | |
557 CrossThreadCopier<A6>::copy(a6))); | |
558 } | |
559 | |
560 // Templates for member function of class C + weak pointer (const WeakPtr<C>&) | |
561 // which do not use CrossThreadCopier for the weak pointer (a1) | |
562 template<typename R, typename C> | |
563 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(), const WeakPtr<C>& a1) | |
564 { | |
565 return CallClosureTask::create(bind(function, | |
566 a1)); | |
567 } | |
568 | |
569 template<typename R, typename C, typename P2, typename A2> | |
570 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2), con st WeakPtr<C>& a1, const A2& a2) | |
571 { | |
572 return CallClosureTask::create(bind(function, | |
573 a1, | |
574 CrossThreadCopier<A2>::copy(a2))); | |
575 } | |
576 | |
577 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3> | |
578 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3), const WeakPtr<C>& a1, const A2& a2, const A3& a3) | |
579 { | |
580 return CallClosureTask::create(bind(function, | |
581 a1, | |
582 CrossThreadCopier<A2>::copy(a2), | |
583 CrossThreadCopier<A3>::copy(a3))); | |
584 } | |
585 | |
586 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4> | |
587 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4), const WeakPtr<C>& a1, const A2& a2, const A3& a3, const A4& a4) | |
588 { | |
589 return CallClosureTask::create(bind(function, | |
590 a1, | |
591 CrossThreadCopier<A2>::copy(a2), | |
592 CrossThreadCopier<A3>::copy(a3), | |
593 CrossThreadCopier<A4>::copy(a4))); | |
594 } | |
595 | |
596 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4, typename P5, typename A5> | |
597 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4, P5), const WeakPtr<C>& a1, const A2& a2, const A3& a3, const A4& a4, const A 5& a5) | |
598 { | |
599 return CallClosureTask::create(bind(function, | |
600 a1, | |
601 CrossThreadCopier<A2>::copy(a2), | |
602 CrossThreadCopier<A3>::copy(a3), | |
603 CrossThreadCopier<A4>::copy(a4), | |
604 CrossThreadCopier<A5>::copy(a5))); | |
605 } | |
606 | |
607 template<typename R, typename C, typename P2, typename A2, typename P3, typename A3, typename P4, typename A4, typename P5, typename A5, typename P6, typename A 6> | |
608 PassOwnPtr<ExecutionContextTask> createCallClosureTask(R (C::*function)(P2, P3, P4, P5, P6), const WeakPtr<C>& a1, const A2& a2, const A3& a3, const A4& a4, con st A5& a5, const A6& a6) | |
609 { | |
610 return CallClosureTask::create(bind(function, | |
611 a1, | |
612 CrossThreadCopier<A2>::copy(a2), | |
613 CrossThreadCopier<A3>::copy(a3), | |
614 CrossThreadCopier<A4>::copy(a4), | |
615 CrossThreadCopier<A5>::copy(a5), | |
616 CrossThreadCopier<A6>::copy(a6))); | |
617 } | |
618 | |
619 // Other cases; use CrossThreadCopier for all arguments | |
620 template<typename FunctionType> | |
621 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function) | |
622 { | |
623 return CallClosureTask::create(bind(function)); | |
624 } | |
625 | |
626 template<typename FunctionType, typename A1> | |
627 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1) | |
628 { | |
629 return CallClosureTask::create(bind(function, | |
630 CrossThreadCopier<A1>::copy(a1))); | |
631 } | |
632 | |
633 template<typename FunctionType, typename A1, typename A2> | |
634 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1, const A2& a2) | |
635 { | |
636 return CallClosureTask::create(bind(function, | |
637 CrossThreadCopier<A1>::copy(a1), | |
638 CrossThreadCopier<A2>::copy(a2))); | |
639 } | |
640 | |
641 template<typename FunctionType, typename A1, typename A2, typename A3> | |
642 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1, const A2& a2, const A3& a3) | |
643 { | |
644 return CallClosureTask::create(bind(function, | |
645 CrossThreadCopier<A1>::copy(a1), | |
646 CrossThreadCopier<A2>::copy(a2), | |
647 CrossThreadCopier<A3>::copy(a3))); | |
648 } | |
649 | |
650 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4> | |
651 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1, const A2& a2, const A3& a3, const A4& a4) | |
652 { | |
653 return CallClosureTask::create(bind(function, | |
654 CrossThreadCopier<A1>::copy(a1), | |
655 CrossThreadCopier<A2>::copy(a2), | |
656 CrossThreadCopier<A3>::copy(a3), | |
657 CrossThreadCopier<A4>::copy(a4))); | |
658 } | |
659 | |
660 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5> | |
661 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) | |
662 { | |
663 return CallClosureTask::create(bind(function, | |
664 CrossThreadCopier<A1>::copy(a1), | |
665 CrossThreadCopier<A2>::copy(a2), | |
666 CrossThreadCopier<A3>::copy(a3), | |
667 CrossThreadCopier<A4>::copy(a4), | |
668 CrossThreadCopier<A5>::copy(a5))); | |
669 } | |
670 | |
671 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> | |
672 PassOwnPtr<ExecutionContextTask> createCallClosureTask(FunctionType function, co nst A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6 ) | |
673 { | |
674 return CallClosureTask::create(bind(function, | |
675 CrossThreadCopier<A1>::copy(a1), | |
676 CrossThreadCopier<A2>::copy(a2), | |
677 CrossThreadCopier<A3>::copy(a3), | |
678 CrossThreadCopier<A4>::copy(a4), | |
679 CrossThreadCopier<A5>::copy(a5), | |
680 CrossThreadCopier<A6>::copy(a6))); | |
681 } | |
682 | |
481 } // namespace WebCore | 683 } // namespace WebCore |
482 | 684 |
483 #endif // CrossThreadTask_h | 685 #endif // CrossThreadTask_h |
OLD | NEW |