Project
Loading...
Searching...
No Matches
GPUDisplayGUIWrapper.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
16#include "GPUDisplayGUI.h"
17
18#include <QApplication>
19#include <QTimer>
20
21#include <thread>
22#include <mutex>
23#include <condition_variable>
24
25using namespace o2::gpu;
26
27namespace o2::gpu::internal
28{
30 std::unique_ptr<QApplication> app;
31 std::unique_ptr<GPUDisplayGUI> gui;
32 std::unique_ptr<QTimer> timer;
33 std::thread t;
34 volatile bool start = false;
35 volatile bool stop = false;
36 volatile bool terminate = false;
37 volatile bool started = false;
38 volatile bool stopped = false;
39 std::mutex mutex, mutexRet;
40 std::condition_variable signal, signalRet;
41};
42} // namespace o2::gpu::internal
43
45{
46 static bool first = true;
47 static std::mutex mutex;
48 {
49 std::lock_guard<std::mutex> guard(mutex);
50 if (!first) {
51 throw std::runtime_error("Must not start QApplication twice");
52 first = true;
53 }
54 }
56 mO->t = std::thread(&GPUDisplayGUIWrapper::guiThread, this);
57}
59{
60 stop();
61 {
62 std::lock_guard<std::mutex> guard(mO->mutex);
63 mO->terminate = true;
64 mO->signal.notify_one();
65 }
66 mO->t.join();
67}
68
70{
71 if (mO->stop) {
72 mO->gui->close();
73 mO->stop = false;
74 }
75}
76
77void GPUDisplayGUIWrapper::guiThread()
78{
79 static int32_t tmp_argc = 1;
80 static const char* tmp_argv[2] = {"GPU CA Standalone Event Display GUI", NULL};
81 mO->app.reset(new QApplication(tmp_argc, (char**)tmp_argv));
82 while (!mO->terminate) {
83 {
84 std::unique_lock<std::mutex> lock(mO->mutex);
85 if (!mO->start && !mO->terminate) {
86 mO->signal.wait(lock);
87 }
88 }
89 if (mO->terminate) {
90 break;
91 }
92 if (mO->start) {
93 mO->start = false;
94 mO->stopped = false;
95 mO->gui.reset(new GPUDisplayGUI);
96 mO->gui->setWrapper(this);
97 mO->gui->show();
98 mO->timer.reset(new QTimer(mO->gui.get()));
99 mO->timer->start(10);
100 mO->gui->connect(mO->timer.get(), SIGNAL(timeout()), mO->gui.get(), SLOT(UpdateTimer()));
101 {
102 std::lock_guard<std::mutex> guard(mO->mutexRet);
103 mO->started = true;
104 mO->signalRet.notify_one();
105 }
106 mO->app->exec();
107 mO->timer->stop();
108 mO->timer.reset(nullptr);
109 mO->gui.reset(nullptr);
110 std::lock_guard<std::mutex> guard(mO->mutexRet);
111 mO->started = false;
112 mO->stopped = true;
113 mO->signalRet.notify_one();
114 }
115 }
116 mO->app.reset(nullptr);
117}
118
120{
121 if (!mO->started) {
122 {
123 std::lock_guard<std::mutex> guard(mO->mutex);
124 mO->start = true;
125 mO->signal.notify_one();
126 }
127 {
128 std::unique_lock<std::mutex> lock(mO->mutexRet);
129 while (mO->started == false) {
130 mO->signalRet.wait(lock);
131 }
132 }
133 }
134 return 0;
135}
136
138{
139 if (mO->started) {
140 mO->stop = true;
141 {
142 std::unique_lock<std::mutex> lock(mO->mutexRet);
143 while (mO->stopped == false) {
144 mO->signalRet.wait(lock);
145 }
146 }
147 }
148 return 0;
149}
150
152{
153 if (mO->started) {
154 }
155 return 0;
156}
157
159{
160 return mO->started;
161}
GLuint start
Definition glcorearb.h:469
GLbitfield GLuint64 timeout
Definition glcorearb.h:1573