Project
Loading...
Searching...
No Matches
GPUDisplayInterface.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
15#include "GPUDisplayInterface.h"
16#include "GPULogging.h"
17#include "utils/qlibload.h"
18
19#include <dlfcn.h>
20#include <mutex>
21#include <tuple>
22#include <stdexcept>
23
24using namespace o2::gpu;
25
26static constexpr const char* libName = "lib" LIBRARY_PREFIX "GPUTrackingDisplay" LIBRARY_EXTENSION;
27static constexpr const char* funcName = "GPUTrackingDisplayLoader";
28
29static void* loadUnloadLib(bool load)
30{
31 static size_t count = 0;
32 static LIBRARY_TYPE lib = nullptr;
33 static void* func = nullptr;
34
35 static std::mutex mut;
36 std::lock_guard<std::mutex> lock(mut);
37
38 if (load) {
39 if (count == 0) {
40 lib = LIBRARY_LOAD(libName);
41 if (lib == nullptr) {
42 GPUError("Cannot load display library %s", libName);
43 return nullptr;
44 }
45 func = LIBRARY_FUNCTION(lib, funcName);
46 if (func == nullptr) {
47 GPUError("Error getting factory function from display library %s", libName);
48 LIBRARY_CLOSE(lib);
49 lib = nullptr;
50 return nullptr;
51 }
52 }
53 count++;
54 return func;
55 } else {
56 if (count == 0) {
57 throw std::runtime_error("reference count mismatch");
58 }
59 if (--count == 0) {
60 LIBRARY_CLOSE(lib);
61 lib = nullptr;
62 func = nullptr;
63 }
64 }
65 return nullptr;
66}
67
69{
70 std::tuple args = {frontend, chain, qa, param, calib, config};
71 auto func = (GPUDisplayInterface * (*)(const char*, void*)) loadUnloadLib(true);
72 return func ? func("display", &args) : nullptr;
73}
74
76{
77 std::tuple args = {type};
78 auto func = (GPUDisplayFrontendInterface * (*)(const char*, void*)) loadUnloadLib(true);
79 return func ? func("frontend", &args) : nullptr;
80}
81
84{
85 loadUnloadLib(false);
86}
GPUChain * chain
static GPUDisplayFrontendInterface * getFrontend(const char *type)
static GPUDisplayInterface * getDisplay(GPUDisplayFrontendInterface *frontend, GPUChainTracking *chain, GPUQA *qa, const GPUParam *param=nullptr, const GPUCalibObjectsConst *calib=nullptr, const GPUSettingsDisplay *config=nullptr)
GLenum func
Definition glcorearb.h:778
GLint GLsizei count
Definition glcorearb.h:399
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLenum GLfloat param
Definition glcorearb.h:271
#define LIBRARY_EXTENSION
Definition qlibload.h:25
#define LIBRARY_CLOSE
Definition qlibload.h:28
#define LIBRARY_TYPE
Definition qlibload.h:26
#define LIBRARY_PREFIX
Definition qlibload.h:35
#define LIBRARY_LOAD(name)
Definition qlibload.h:27
#define LIBRARY_FUNCTION
Definition qlibload.h:29