yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinSource codes8c4603c

master
922 B38 linesraw
1#pragma once
2#include <atomic>
3#include <assert.h>
4#include <limits.h>
5
6namespace ComLight
7{
8	// Very base class of objects, implements reference counting.
9	class RefCounter
10	{
11		std::atomic_uint referenceCounter;
12
13	public:
14
15		RefCounter() : referenceCounter( 0 ) { }
16
17		inline virtual ~RefCounter() { }
18
19		RefCounter( const RefCounter &that ) = delete;
20		RefCounter( RefCounter &&that ) = delete;
21
22	protected:
23
24		uint32_t implAddRef()
25		{
26			return ++referenceCounter;
27		}
28
29		uint32_t implRelease()
30		{
31			// Might be a good idea to use locks, at least in debug builds. They're much slower than atomics, but with locks it's possible to detect when 2 threads call release at the same time, for object with counter = 1.
32			// It's a memory management bug, but it would be nice if debug builds would handle that case gracefully.
33			const uint32_t rc = --referenceCounter;
34			assert( rc != UINT_MAX );
35			return rc;
36		}
37	};
38}