! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. * * \note All calls to this function return the same cl_context as the first. */
| 2649 | * \note All calls to this function return the same cl_context as the first. |
| 2650 | */ |
| 2651 | static Context getDefault(cl_int * err = NULL) |
| 2652 | { |
| 2653 | int state = detail::compare_exchange( |
| 2654 | &default_initialized_, |
| 2655 | __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); |
| 2656 | |
| 2657 | if (state & __DEFAULT_INITIALIZED) { |
| 2658 | if (err != NULL) { |
| 2659 | *err = default_error_; |
| 2660 | } |
| 2661 | return default_; |
| 2662 | } |
| 2663 | |
| 2664 | if (state & __DEFAULT_BEING_INITIALIZED) { |
| 2665 | // Assume writes will propagate eventually... |
| 2666 | while(default_initialized_ != __DEFAULT_INITIALIZED) { |
| 2667 | detail::fence(); |
| 2668 | } |
| 2669 | |
| 2670 | if (err != NULL) { |
| 2671 | *err = default_error_; |
| 2672 | } |
| 2673 | return default_; |
| 2674 | } |
| 2675 | |
| 2676 | cl_int error; |
| 2677 | default_ = Context( |
| 2678 | CL_DEVICE_TYPE_DEFAULT, |
| 2679 | NULL, |
| 2680 | NULL, |
| 2681 | NULL, |
| 2682 | &error); |
| 2683 | |
| 2684 | detail::fence(); |
| 2685 | |
| 2686 | default_error_ = error; |
| 2687 | // Assume writes will propagate eventually... |
| 2688 | default_initialized_ = __DEFAULT_INITIALIZED; |
| 2689 | |
| 2690 | detail::fence(); |
| 2691 | |
| 2692 | if (err != NULL) { |
| 2693 | *err = default_error_; |
| 2694 | } |
| 2695 | return default_; |
| 2696 | |
| 2697 | } |
| 2698 | |
| 2699 | //! \brief Default constructor - initializes to NULL. |
| 2700 | Context() : detail::Wrapper<cl_type>() { } |