From 6fa87d3bef7972f7fac034adb68cd856f69c8607 Mon Sep 17 00:00:00 2001 From: Daniel Rugerio Date: Tue, 25 Nov 2025 11:00:04 -0800 Subject: New SDCAVAD sample. --- audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h (limited to 'audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h') diff --git a/audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h b/audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h new file mode 100644 index 00000000..f4ed6220 --- /dev/null +++ b/audio/SoundWire/Samples/SdcaVad/Inc/cpp_utils.h @@ -0,0 +1,71 @@ +/*++ + +Copyright (c) Microsoft Corporation. All rights reserved. + + THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY + KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR + PURPOSE. + +Module Name: + + cpp_utils.h + +Abstract: + + Contains CPP utilities + +Environment: + + Kernel mode + +--*/ + +#pragma once + +// Function scope_exit instantiates scope_exit object +// Constructor accepts lamda as parameter. +// Assign tasks in lamdba to be executed on scope exit. +template +auto scope_exit(F f) +{ + class scope_exit + { + public: + scope_exit(F f) : + _f{ f } + { + } + + ~scope_exit() + { + if (_call) + { + _f(); + } + } + + // Ensures the scope_exit lambda will not be called + void release() + { + _call = false; + } + + // Executes the scope_exit lambda immediately if not yet run; ensures it will not run again + void reset() + { + if (_call) + { + _f(); + _call = false; + } + } + + private: + F _f; + bool _call = true; + }; + + return scope_exit{ f }; +}; + -- cgit v1.3.1