blob: bbde48bd6fb2474a235da841b8fa6ba6100ee9ca [file] [log] [blame]
Francisco Jerezc6db1b32012-04-20 16:56:19 +02001//
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 Graunkef0cb66b2013-04-21 13:52:08 -070017// 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 Jerezc6db1b32012-04-20 16:56:19 +020021//
22
Francisco Jerez099d2812013-09-15 15:29:34 -070023#ifndef CLOVER_CORE_CONTEXT_HPP
24#define CLOVER_CORE_CONTEXT_HPP
Francisco Jerezc6db1b32012-04-20 16:56:19 +020025
Serge Martin2fd50792020-11-06 15:08:51 +100026#include <stack>
27
Francisco Jerezbff60c82013-10-06 13:51:01 -070028#include "core/object.hpp"
Francisco Jerezc6db1b32012-04-20 16:56:19 +020029#include "core/device.hpp"
Francisco Jereze5fc61f2013-09-16 21:13:47 -070030#include "core/property.hpp"
Francisco Jerezc6db1b32012-04-20 16:56:19 +020031
32namespace clover {
Francisco Jerez9d06fb82013-09-15 20:50:30 -070033 class context : public ref_counter, public _cl_context {
Francisco Jereze5fc61f2013-09-16 21:13:47 -070034 private:
Francisco Jerezc4578d22014-02-18 15:07:11 +010035 typedef adaptor_range<
36 evals, const std::vector<intrusive_ref<device>> &
37 > device_range;
Francisco Jereze5fc61f2013-09-16 21:13:47 -070038 typedef clover::property_list<cl_context_properties> property_list;
39
Francisco Jerez9d06fb82013-09-15 20:50:30 -070040 public:
Serge Martin2fd50792020-11-06 15:08:51 +100041 ~context();
42
Ilia Mirkin6706cc12015-10-30 23:25:59 -040043 typedef std::function<void (const char *)> notify_action;
44
45 context(const property_list &props, const ref_vector<device> &devs,
46 const notify_action &notify);
Francisco Jereze5fc61f2013-09-16 21:13:47 -070047
Francisco Jerez9d06fb82013-09-15 20:50:30 -070048 context(const context &ctx) = delete;
Francisco Jerez5226eac2013-09-16 21:44:36 -070049 context &
50 operator=(const context &ctx) = delete;
Francisco Jerez9d06fb82013-09-15 20:50:30 -070051
Francisco Jerez369419f2013-09-16 21:11:16 -070052 bool
53 operator==(const context &ctx) const;
54 bool
55 operator!=(const context &ctx) const;
56
Serge Martin2fd50792020-11-06 15:08:51 +100057 void destroy_notify(std::function<void ()> f);
58
Francisco Jereze5fc61f2013-09-16 21:13:47 -070059 const property_list &
Francisco Jerez9b2fe7c2014-02-18 13:12:52 +010060 properties() const;
Francisco Jerez9d06fb82013-09-15 20:50:30 -070061
Francisco Jerez10284b12013-09-16 21:38:32 -070062 device_range
Francisco Jerez9b2fe7c2014-02-18 13:12:52 +010063 devices() const;
Francisco Jerez9d06fb82013-09-15 20:50:30 -070064
Ilia Mirkin6706cc12015-10-30 23:25:59 -040065 const notify_action notify;
66
Francisco Jerez9d06fb82013-09-15 20:50:30 -070067 private:
Francisco Jerez9b2fe7c2014-02-18 13:12:52 +010068 property_list props;
69 const std::vector<intrusive_ref<device>> devs;
Serge Martin2fd50792020-11-06 15:08:51 +100070 std::stack<std::function<void ()>> _destroy_notify;
Francisco Jerez9d06fb82013-09-15 20:50:30 -070071 };
Francisco Jerezc6db1b32012-04-20 16:56:19 +020072}
73
Francisco Jerezc6db1b32012-04-20 16:56:19 +020074#endif