Warn when RAII lock returned from function is discarded

Discarding RAII lock returned from function almost always
is a bug. This change introduces usage of [[no_discard]]
attribute from C++17 to prevent such misues.

Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
Patryk Wrobel
2022-09-01 15:54:57 +00:00
committed by Compute-Runtime-Automation
parent d672920121
commit 90ba50bf52
15 changed files with 23 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -71,7 +71,7 @@ class AubSubCaptureManager {
MOCKABLE_VIRTUAL std::string generateFilterFileName() const;
MOCKABLE_VIRTUAL std::string generateToggleFileName(const std::string &kernelName) const;
bool isKernelIndexInSubCaptureRange(uint32_t kernelIdx, uint32_t rangeStartIdx, uint32_t rangeEndIdx) const;
MOCKABLE_VIRTUAL std::unique_lock<std::mutex> lock() const;
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<std::mutex> lock() const;
bool subCaptureIsActive = false;
bool subCaptureWasActiveInPreviousEnqueue = false;

View File

@@ -138,7 +138,7 @@ struct AubFileStream : public AubStream {
MOCKABLE_VIRTUAL void expectMemory(uint64_t physAddress, const void *memory, size_t size,
uint32_t addressSpace, uint32_t compareOperation);
MOCKABLE_VIRTUAL bool addComment(const char *message);
MOCKABLE_VIRTUAL std::unique_lock<std::mutex> lockStream();
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<std::mutex> lockStream();
std::ofstream fileHandle;
std::string fileName;

View File

@@ -194,7 +194,7 @@ class CommandStreamReceiver {
MOCKABLE_VIRTUAL bool createPreemptionAllocation();
MOCKABLE_VIRTUAL bool createPerDssBackedBuffer(Device &device);
virtual void createKernelArgsBufferAllocation() = 0;
MOCKABLE_VIRTUAL std::unique_lock<MutexType> obtainUniqueOwnership();
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<MutexType> obtainUniqueOwnership();
bool peekTimestampPacketWriteEnabled() const { return timestampPacketWriteEnabled; }
@@ -365,7 +365,7 @@ class CommandStreamReceiver {
bool checkImplicitFlushForGpuIdle();
void downloadTagAllocation(uint32_t taskCountToWait);
void printTagAddressContent(uint32_t taskCountToWait, int64_t waitTimeout, bool start);
MOCKABLE_VIRTUAL std::unique_lock<MutexType> obtainHostPtrSurfaceCreationLock();
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<MutexType> obtainHostPtrSurfaceCreationLock();
std::unique_ptr<FlushStampTracker> flushStamp;
std::unique_ptr<SubmissionAggregator> submissionAggregator;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -144,7 +144,7 @@ class CompilerInterface {
MOCKABLE_VIRTUAL bool loadIgc();
static SpinLock spinlock;
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> lock() {
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> lock() {
return std::unique_lock<SpinLock>{spinlock};
}
std::unique_ptr<CompilerCache> cache = nullptr;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -33,7 +33,7 @@ class HostPtrManager {
bool releaseHostPtr(uint32_t rootDeviceIndex, const void *ptr);
void storeFragment(uint32_t rootDeviceIndex, AllocationStorageData &storageData);
void storeFragment(uint32_t rootDeviceIndex, FragmentStorage &fragment);
std::unique_lock<std::recursive_mutex> obtainOwnership();
[[nodiscard]] std::unique_lock<std::recursive_mutex> obtainOwnership();
protected:
static AllocationRequirements getAllocationRequirements(uint32_t rootDeviceIndex, const void *inputPtr, size_t size);

View File

@@ -260,7 +260,7 @@ class MemoryManager {
};
std::unordered_map<std::string, KernelAllocationInfo> &getKernelAllocationMap() { return this->kernelAllocationMap; };
std::unique_lock<std::mutex> lockKernelAllocationMap() { return std::unique_lock<std::mutex>(this->kernelAllocationMutex); };
[[nodiscard]] std::unique_lock<std::mutex> lockKernelAllocationMap() { return std::unique_lock<std::mutex>(this->kernelAllocationMutex); };
protected:
bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -31,7 +31,7 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler {
void setAubManager(aub_stream::AubManager *aubManager);
protected:
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {
return std::unique_lock<SpinLock>{lock};
}
aub_stream::AubManager *aubManager = nullptr;

View File

@@ -72,7 +72,7 @@ class DrmMemoryManager : public MemoryManager {
bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) override;
bool setMemPrefetch(GraphicsAllocation *gfxAllocation, uint32_t subDeviceId, uint32_t rootDeviceIndex) override;
std::unique_lock<std::mutex> acquireAllocLock();
[[nodiscard]] std::unique_lock<std::mutex> acquireAllocLock();
std::vector<GraphicsAllocation *> &getSysMemAllocs();
std::vector<GraphicsAllocation *> &getLocalMemAllocs(uint32_t rootDeviceIndex);
void registerSysMemAlloc(GraphicsAllocation *allocation) override;

View File

@@ -23,7 +23,7 @@ class DrmMemoryOperationsHandlerBind : public DrmMemoryOperationsHandler {
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
[[nodiscard]] std::unique_lock<std::mutex> lockHandlerIfUsed() override;
MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;

View File

@@ -24,7 +24,7 @@ class DrmMemoryOperationsHandlerDefault : public DrmMemoryOperationsHandler {
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override;
MemoryOperationsStatus mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) override;
std::unique_lock<std::mutex> lockHandlerIfUsed() override;
[[nodiscard]] std::unique_lock<std::mutex> lockHandlerIfUsed() override;
MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) override;

View File

@@ -232,7 +232,7 @@ class Drm : public DriverModel {
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevice(ExecutionEnvironment &executionEnvironment, std::string &osPciPath);
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment, std::string &osPciPath);
std::unique_lock<std::mutex> lockBindFenceMutex();
[[nodiscard]] std::unique_lock<std::mutex> lockBindFenceMutex();
void setPciDomain(uint32_t domain) {
pciDomain = domain;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 Intel Corporation
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -30,7 +30,7 @@ class WddmResidentAllocationsContainer {
MOCKABLE_VIRTUAL void removeResource(const D3DKMT_HANDLE &handle);
protected:
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock(SpinLock &lock) {
return std::unique_lock<SpinLock>{lock};
}

View File

@@ -32,8 +32,8 @@ class WddmResidencyController {
static void APIENTRY trimCallback(_Inout_ D3DKMT_TRIMNOTIFICATION *trimNotification);
MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
std::unique_lock<SpinLock> acquireTrimCallbackLock();
[[nodiscard]] MOCKABLE_VIRTUAL std::unique_lock<SpinLock> acquireLock();
[[nodiscard]] std::unique_lock<SpinLock> acquireTrimCallbackLock();
WddmAllocation *getTrimCandidateHead();
void addToTrimCandidateList(GraphicsAllocation *allocation);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -58,7 +58,7 @@ class AubSubCaptureManagerMock : public AubSubCaptureManager {
return toggleFileName;
}
std::unique_lock<std::mutex> lock() const override {
[[nodiscard]] std::unique_lock<std::mutex> lock() const override {
isLocked = true;
return std::unique_lock<std::mutex>{mutex};
}