summaryrefslogtreecommitdiffstats
path: root/Whisper/Utils/DelayExecution.h
blob: 23d0262ecb5bd9ae5243e399c75e9b4ab26a419f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#include <atlbase.h>

// Utility class implementing a high-resolution Sleep() function
class DelayExecution
{
	using pfnDelay = void( * )( const DelayExecution& de );
	pfnDelay pfn = nullptr;
	CHandle timer;

	static void sleepOnTheTimer( const DelayExecution& delay );
	static void spinWait( const DelayExecution& );
	static void sleep( const DelayExecution& );

public:
	DelayExecution();
	DelayExecution( const DelayExecution& ) = delete;
	~DelayExecution() = default;

	void delay() const
	{
		pfn( *this );
	}
};