Merge pull request #26308 from jjd-uk/estuary_playerprocess
[xbmc.git] / xbmc / threads / SingleLock.h
blobcacb691550f5fab8aaab5ef0a517296d0424d1f0
1 /*
2 * Copyright (c) 2002 Frodo
3 * Portions Copyright (c) by the authors of ffmpeg and xvid
4 * Copyright (C) 2002-2018 Team Kodi
5 * This file is part of Kodi - https://kodi.tv
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 * See LICENSES/README.md for more information.
9 */
11 #pragma once
13 #include "threads/CriticalSection.h"
15 #include <mutex>
17 /**
18 * This implements a "guard" pattern for exiting all locks
19 * currently being held by the current thread and restoring
20 * those locks on destruction.
22 * This class can be used on a CCriticalSection that isn't owned
23 * by this thread in which case it will do nothing.
25 class CSingleExit
27 CCriticalSection& sec;
28 unsigned int count;
29 public:
30 inline explicit CSingleExit(CCriticalSection& cs) : sec(cs), count(cs.exit()) { }
31 inline ~CSingleExit() { sec.restore(count); }