Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2012 Francisco Jerez |
| 3 | // |
| 4 | // Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | // copy of this software and associated documentation files (the "Software"), |
| 6 | // to deal in the Software without restriction, including without limitation |
| 7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | // and/or sell copies of the Software, and to permit persons to whom the |
| 9 | // Software is furnished to do so, subject to the following conditions: |
| 10 | // |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Kenneth Graunke | f0cb66b | 2013-04-21 13:52:08 -0700 | [diff] [blame] | 17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | // OTHER DEALINGS IN THE SOFTWARE. |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 21 | // |
| 22 | |
Francisco Jerez | 099d281 | 2013-09-15 15:29:34 -0700 | [diff] [blame] | 23 | #ifndef CLOVER_CORE_CONTEXT_HPP |
| 24 | #define CLOVER_CORE_CONTEXT_HPP |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 25 | |
Serge Martin | 2fd5079 | 2020-11-06 15:08:51 +1000 | [diff] [blame] | 26 | #include <stack> |
| 27 | |
Francisco Jerez | bff60c8 | 2013-10-06 13:51:01 -0700 | [diff] [blame] | 28 | #include "core/object.hpp" |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 29 | #include "core/device.hpp" |
Francisco Jerez | e5fc61f | 2013-09-16 21:13:47 -0700 | [diff] [blame] | 30 | #include "core/property.hpp" |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 31 | |
| 32 | namespace clover { |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 33 | class context : public ref_counter, public _cl_context { |
Francisco Jerez | e5fc61f | 2013-09-16 21:13:47 -0700 | [diff] [blame] | 34 | private: |
Francisco Jerez | c4578d2 | 2014-02-18 15:07:11 +0100 | [diff] [blame] | 35 | typedef adaptor_range< |
| 36 | evals, const std::vector<intrusive_ref<device>> & |
| 37 | > device_range; |
Francisco Jerez | e5fc61f | 2013-09-16 21:13:47 -0700 | [diff] [blame] | 38 | typedef clover::property_list<cl_context_properties> property_list; |
| 39 | |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 40 | public: |
Serge Martin | 2fd5079 | 2020-11-06 15:08:51 +1000 | [diff] [blame] | 41 | ~context(); |
| 42 | |
Ilia Mirkin | 6706cc1 | 2015-10-30 23:25:59 -0400 | [diff] [blame] | 43 | typedef std::function<void (const char *)> notify_action; |
| 44 | |
| 45 | context(const property_list &props, const ref_vector<device> &devs, |
| 46 | const notify_action ¬ify); |
Francisco Jerez | e5fc61f | 2013-09-16 21:13:47 -0700 | [diff] [blame] | 47 | |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 48 | context(const context &ctx) = delete; |
Francisco Jerez | 5226eac | 2013-09-16 21:44:36 -0700 | [diff] [blame] | 49 | context & |
| 50 | operator=(const context &ctx) = delete; |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 51 | |
Francisco Jerez | 369419f | 2013-09-16 21:11:16 -0700 | [diff] [blame] | 52 | bool |
| 53 | operator==(const context &ctx) const; |
| 54 | bool |
| 55 | operator!=(const context &ctx) const; |
| 56 | |
Serge Martin | 2fd5079 | 2020-11-06 15:08:51 +1000 | [diff] [blame] | 57 | void destroy_notify(std::function<void ()> f); |
| 58 | |
Francisco Jerez | e5fc61f | 2013-09-16 21:13:47 -0700 | [diff] [blame] | 59 | const property_list & |
Francisco Jerez | 9b2fe7c | 2014-02-18 13:12:52 +0100 | [diff] [blame] | 60 | properties() const; |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 61 | |
Francisco Jerez | 10284b1 | 2013-09-16 21:38:32 -0700 | [diff] [blame] | 62 | device_range |
Francisco Jerez | 9b2fe7c | 2014-02-18 13:12:52 +0100 | [diff] [blame] | 63 | devices() const; |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 64 | |
Ilia Mirkin | 6706cc1 | 2015-10-30 23:25:59 -0400 | [diff] [blame] | 65 | const notify_action notify; |
| 66 | |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 67 | private: |
Francisco Jerez | 9b2fe7c | 2014-02-18 13:12:52 +0100 | [diff] [blame] | 68 | property_list props; |
| 69 | const std::vector<intrusive_ref<device>> devs; |
Serge Martin | 2fd5079 | 2020-11-06 15:08:51 +1000 | [diff] [blame] | 70 | std::stack<std::function<void ()>> _destroy_notify; |
Francisco Jerez | 9d06fb8 | 2013-09-15 20:50:30 -0700 | [diff] [blame] | 71 | }; |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Francisco Jerez | c6db1b3 | 2012-04-20 16:56:19 +0200 | [diff] [blame] | 74 | #endif |