summaryrefslogtreecommitdiffstats
path: root/src/opencl/qcluserevent.cpp
blob: 2f715e952f10ed8da53d5836e0a603eaaa2cc805 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtOpenCL module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qcluserevent.h"
#include "qclcontext.h"
#include "qclext_p.h"
#include <QtCore/qdebug.h>

QT_BEGIN_NAMESPACE

/*!
    \class QCLUserEvent
    \brief The QCLUserEvent class represents OpenCL 1.1 user events.
    \since 4.7
    \ingroup opencl

    User events are a feature of OpenCL 1.1 which allows an application
    to insert a marker into the command queue.  Commands that depend
    upon the marker will not be executed until the application triggers
    the user event with setFinished().

    User events are constructed with QCLContext::createUserEvent(),
    which will return null if the OpenCL implementation does not
    support OpenCL 1.1.

    \sa QCLEvent, QCLContext::createUserEvent()
*/

/*!
    \fn QCLUserEvent::QCLUserEvent()

    Constructs a null user event.
*/

/*!
    Constructs an OpenCL event object from the native identifier \a id.
    This class takes over ownership of \a id and will release it in
    the destructor.

    If \a id is not a user event, then the newly constructed event
    will be set to null, and \a id will be released.
*/
QCLUserEvent::QCLUserEvent(cl_event id)
    : QCLEvent(id)
{
    validateEvent();
}

/*!
    Constructs a copy of \a other.  The \c{clRetainEvent()} function
    will be called to update the reference count on eventId().

    If \a other is not a user event, then the newly constructed event
    will be set to null.
*/
QCLUserEvent::QCLUserEvent(const QCLEvent &other)
    : QCLEvent(other)
{
    validateEvent();
}

/*!
    Assigns \a other to this OpenCL event object.  The current eventId() will
    be released with \c{clReleaseEvent()}, and the new eventId() will be
    retained with \c{clRetainEvent()}.

    If \a other is not a user event, then this event will be
    set to null.
*/
QCLUserEvent &QCLUserEvent::operator=(const QCLEvent &other)
{
    if (m_id != other.m_id) {
        if (m_id)
            clReleaseEvent(m_id);
        m_id = other.m_id;
        if (m_id)
            clRetainEvent(m_id);
        validateEvent();
    }
    return *this;
}

/*!
    \fn void QCLUserEvent::setFinished()

    Sets this user event to the finished state.  Any queued
    commands that depend upon this event can now proceed.

    \sa setStatus()
*/

/*!
    Sets the \a status of this user event.  The \a status should
    be either \c{CL_COMPLETE} or a negative OpenCL error code.

    \sa setFinished()
*/
void QCLUserEvent::setStatus(cl_int status)
{
#ifdef QT_OPENCL_1_1
    if (m_id) {
        cl_int error = clSetUserEventStatus(m_id, status);
        if (error != CL_SUCCESS) {
            qWarning() << "QCLUserEvent::setStatus:"
                    << QCLContext::errorName(error);
        }
    }
#endif
}

/*!
    \internal
*/
void QCLUserEvent::validateEvent()
{
    if (commandType() != CL_COMMAND_USER) {
        clReleaseEvent(m_id);
        m_id = 0;
    }
}

QT_END_NAMESPACE