Build Packages / Create release (push) Successful in 16s
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 7m35s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 8m44s
Build Packages / build:viewer-tgz:cpu (push) Successful in 9m53s
Build Packages / build:viewer-tgz:cuda (push) Successful in 11m47s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 15m5s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 15m54s
Build Packages / build:windows:nocuda (push) Successful in 17m16s
Build Packages / build:windows:cuda (push) Successful in 19m49s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m53s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 19m51s
Build Packages / build:rugnux:windows (push) Successful in 10m41s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 19m53s
Build Packages / Generate python client (push) Successful in 37s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 20m38s
Build Packages / Build documentation (push) Successful in 2m1s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 19m48s
Build Packages / build:rpm (rocky8) (push) Successful in 17m59s
Build Packages / build:rpm (rocky9) (push) Successful in 18m7s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 21m1s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 18m59s
Build Packages / Unit tests (push) Successful in 1h42m28s
None of this has been built on a Mac - there is none yet. It is the list a read-only audit of the viewer/rugnux subtree produced, plus a serial -fsyntax-only pass of every reachable .cpp with clang 16 + libc++ on Linux, which found exactly one error (the first item). - JFJochDatasetInfoChartView: std::vector<fftwf_complex> does not compile with libc++, whose construct_at refuses an array element type (float[2]). Use std::vector<std::complex<float>> and the reinterpret_cast every other FFTW call site already uses. - libcurl: GSSAPI off on Linux, and neither TLS nor GSSAPI on macOS. The viewer never sets CURLOPT_HTTPAUTH, so Negotiate was dead weight that cost a krb5-devel build dependency; on macOS curl's FindGSS refuses the system Heimdal outright, and with Secure Transport gone from curl (8.15) TLS would mean a Homebrew OpenSSL - the only host library a Mac build would need. Linux keeps OpenSSL. CURL_USE_GSSAPI is forced OFF rather than left unset so an existing build tree drops its cached ON. - libjpeg-turbo ExternalProject: CMAKE_SYSTEM_NAME/PROCESSOR were forwarded unconditionally, which puts even a native sub-build into cross-compiling mode, and CMAKE_OSX_ARCHITECTURES / SYSROOT / DEPLOYMENT_TARGET were not forwarded at all. Now the same rule the zlib-ng sub-build follows. - ShadowAccumulatorGPU.cu was added on the JFJOCH_USE_CUDA option (default ON) instead of JFJOCH_CUDA_AVAILABLE like every other .cu, so a machine without nvcc got a CUDA source in a target with no CUDA language. - CMAKE_OSX_DEPLOYMENT_TARGET defaults to 12.0 (overridable). Left unset, CMake takes the build machine's OS version and the .dmg starts nowhere older. - Standard headers that were only arriving transitively (<chrono>, <cmath>, <limits>, <cstring>, <atomic>, <thread>, <string>); newer libc++ releases keep removing such transitive includes. Checked: the seven changed sources pass clang 16 + libc++ -fsyntax-only. The CMake changes are not configured or built. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015eAE2K7i5JGDwgwifiCfuA
146 lines
4.0 KiB
C++
146 lines
4.0 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <queue>
|
|
#include <mutex>
|
|
#include <condition_variable>
|
|
#include <set>
|
|
|
|
template <class T>
|
|
class ThreadSafeFIFO {
|
|
std::queue<T> queue;
|
|
std::condition_variable c_empty, c_full;
|
|
mutable std::mutex m;
|
|
const size_t max_size;
|
|
size_t max_utilization;
|
|
size_t utilization;
|
|
bool stopped = false;
|
|
public:
|
|
explicit ThreadSafeFIFO(size_t in_max_size = UINT32_MAX) : max_size(in_max_size), max_utilization(0), utilization(0) {}
|
|
|
|
// Release every waiter and make all further blocking operations return at once: puts are
|
|
// dropped, gets answer with a default-constructed element. Used when the owner of the queue is
|
|
// torn down - at that point nobody is going to drain it any more, so a producer blocked on a
|
|
// full queue would never return and the thread join in the destructor would deadlock.
|
|
void Stop() {
|
|
std::unique_lock ul(m);
|
|
stopped = true;
|
|
c_empty.notify_all();
|
|
c_full.notify_all();
|
|
}
|
|
|
|
void Clear() {
|
|
std::unique_lock ul(m);
|
|
queue = {};
|
|
utilization = 0;
|
|
max_utilization = 0;
|
|
// A producer blocked on the full queue has to be told the room it was waiting for is there;
|
|
// nothing else would wake it, as the next Get finds the queue empty and notifies no one.
|
|
c_full.notify_all();
|
|
}
|
|
|
|
bool Put(T val) {
|
|
std::unique_lock ul(m);
|
|
if (queue.size() < max_size) {
|
|
queue.push(val);
|
|
c_empty.notify_one();
|
|
utilization++;
|
|
if (utilization > max_utilization)
|
|
max_utilization = utilization;
|
|
return true;
|
|
} else
|
|
return false;
|
|
};
|
|
|
|
void PutBlocking(T val) {
|
|
std::unique_lock ul(m);
|
|
c_full.wait(ul, [&]{return stopped || (queue.size() < max_size);});
|
|
if (stopped)
|
|
return;
|
|
queue.push(val);
|
|
utilization++;
|
|
if (utilization > max_utilization)
|
|
max_utilization = utilization;
|
|
c_empty.notify_one();
|
|
};
|
|
|
|
bool PutTimeout(T val, std::chrono::milliseconds timeout) {
|
|
std::unique_lock ul(m);
|
|
if (!c_full.wait_for(ul, timeout, [&]{ return stopped || (queue.size() < max_size); }))
|
|
return false;
|
|
if (stopped)
|
|
return false;
|
|
queue.push(val);
|
|
utilization++;
|
|
if (utilization > max_utilization)
|
|
max_utilization = utilization;
|
|
c_empty.notify_one();
|
|
return true;
|
|
}
|
|
|
|
int Get(T &val) {
|
|
std::unique_lock ul(m);
|
|
|
|
if (queue.empty())
|
|
return 0;
|
|
else {
|
|
val = queue.front();
|
|
queue.pop();
|
|
c_full.notify_one();
|
|
utilization--;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
T GetBlocking() {
|
|
std::unique_lock ul(m);
|
|
c_empty.wait(ul, [&]{return stopped || !queue.empty();});
|
|
if (queue.empty())
|
|
return T{};
|
|
T tmp = queue.front();
|
|
queue.pop();
|
|
c_full.notify_one();
|
|
utilization--;
|
|
return tmp;
|
|
};
|
|
|
|
int GetTimeout(T &val, std::chrono::microseconds timeout) {
|
|
std::unique_lock ul(m);
|
|
if (queue.empty())
|
|
c_empty.wait_for(ul, timeout, [&]{return stopped || !queue.empty();});
|
|
|
|
if (queue.empty())
|
|
return 0;
|
|
else {
|
|
val = queue.front();
|
|
queue.pop();
|
|
c_full.notify_one();
|
|
utilization--;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
[[nodiscard]] size_t Size() const {
|
|
std::unique_lock ul(m);
|
|
return queue.size();
|
|
}
|
|
|
|
void ClearMaxUtilization() {
|
|
std::unique_lock ul(m);
|
|
max_utilization = utilization;
|
|
}
|
|
|
|
[[nodiscard]] size_t GetMaxUtilization() const {
|
|
std::unique_lock ul(m);
|
|
return max_utilization;
|
|
}
|
|
|
|
[[nodiscard]] size_t GetCurrentUtilization() const {
|
|
std::unique_lock ul(m);
|
|
return utilization;
|
|
}
|
|
};
|