Recent GCC 10 trunk in C++20 mode reports issues like > include/opencl/OpenCLZone.hxx:27:9: error: ‘++’ expression of ‘volatile’-qualified type is deprecated [-Werror=volatile] > 27 | gnEnterCount++; > | ^~~~~~~~~~~~ But unlike in the case ofec17c8ec52
"-Werror=volatile in OpenGLZone", * it looks like there are no multi-threading issues here, and the counters are just accessed (via OpenCLZone::isInZone) from the VCLExceptionSignal_impl signal handler in addition to being modified (via OpenCLZone RAII objects) from mainline code; and * from the usage pattern of gnEnterCount and gnLeaveCount it appears that they can be combined into a single counter. (f41eb66302
"opencl: OpenCLZone, detect CL device change and disable CL on crash" presumably modelled OpenCLZone naively after OpenGLZone, without simplifying it where possible.) One minor advantage of having two monotonically increasing counters is that when they overflow, the implementation of isInZone (comparing them for equality) still gives ~useful results (assuming that a false "match" of non-overflown gnEnterCount against overflown gnLeaveCount is highly unlikely). But instances of OpenCLZone RAII objects are presumably never nested very deeply (if at all), so that the newly added "TODO: overflow" comment (which would even cause UB if std::sig_atomic_t is signed) is probably of no practical concern. Change-Id: I92e1f2c46ca996a0a86bacabcda2accba5eb6298 Reviewed-on: https://gerrit.libreoffice.org/79106 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <opencl/openclwrapper.hxx>
|
|
#include <opencl/OpenCLZone.hxx>
|
|
#include <opencl_device.hxx>
|
|
|
|
#include <memory>
|
|
|
|
#include <officecfg/Office/Common.hxx>
|
|
#include <com/sun/star/util/XFlushable.hpp>
|
|
#include <com/sun/star/configuration/theDefaultProvider.hpp>
|
|
|
|
// FIXME: templatize me vs. OpenGLZone.
|
|
|
|
std::sig_atomic_t volatile OpenCLZone::gnEnterCount = 0;
|
|
bool volatile OpenCLZone::gbInInitialTest = false;
|
|
|
|
/**
|
|
* Called from a signal handler if we get
|
|
* a crash or hang in some CL code.
|
|
*/
|
|
void OpenCLZone::hardDisable()
|
|
{
|
|
// protect ourselves from double calling etc.
|
|
static bool bDisabled = false;
|
|
if (!bDisabled)
|
|
{
|
|
bDisabled = true;
|
|
|
|
std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
|
|
officecfg::Office::Common::Misc::UseOpenCL::set(false, xChanges);
|
|
xChanges->commit();
|
|
|
|
// Force synchronous config write
|
|
auto xConfProvider = css::configuration::theDefaultProvider::get(comphelper::getProcessComponentContext());
|
|
css::uno::Reference<css::util::XFlushable> xFlushable(xConfProvider, css::uno::UNO_QUERY_THROW);
|
|
xFlushable->flush();
|
|
|
|
releaseOpenCLEnv(&openclwrapper::gpuEnv);
|
|
}
|
|
}
|
|
|
|
void OpenCLZone::enterInitialTest()
|
|
{
|
|
gbInInitialTest = true;
|
|
}
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|