forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.cpp
More file actions
70 lines (60 loc) · 1.83 KB
/
Event.cpp
File metadata and controls
70 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*******************************************************
* Copyright (c) 2019, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <Event.hpp>
#include <common/err_common.hpp>
#include <events.hpp>
#include <platform.hpp>
#include <queue.hpp>
#include <af/event.h>
#include <memory>
using std::make_unique;
namespace cpu {
/// \brief Creates a new event and marks it in the queue
Event makeEvent(cpu::queue& queue) {
Event e;
if (0 == e.create()) { e.mark(queue); }
return e;
}
af_event createEvent() {
auto e = make_unique<Event>();
// Ensure that the default queue is initialized
getQueue();
if (e->create() != 0) {
AF_ERROR("Could not create event", AF_ERR_RUNTIME);
}
Event& ref = *e.release();
return getHandle(ref);
}
void markEventOnActiveQueue(af_event eventHandle) {
Event& event = getEvent(eventHandle);
// Use the currently-active queue
if (event.mark(getQueue()) != 0) {
AF_ERROR("Could not mark event on active queue", AF_ERR_RUNTIME);
}
}
void enqueueWaitOnActiveQueue(af_event eventHandle) {
Event& event = getEvent(eventHandle);
// Use the currently-active queue
if (event.enqueueWait(getQueue()) != 0) {
AF_ERROR("Could not enqueue wait on active queue for event",
AF_ERR_RUNTIME);
}
}
void block(af_event eventHandle) {
Event& event = getEvent(eventHandle);
if (event.block() != 0) {
AF_ERROR("Could not block on active queue for event", AF_ERR_RUNTIME);
}
}
af_event createAndMarkEvent() {
af_event handle = createEvent();
markEventOnActiveQueue(handle);
return handle;
}
} // namespace cpu