diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/api/timer/timeslicer.h | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/Wasabi/api/timer/timeslicer.h')
-rw-r--r-- | Src/Wasabi/api/timer/timeslicer.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Src/Wasabi/api/timer/timeslicer.h b/Src/Wasabi/api/timer/timeslicer.h new file mode 100644 index 00000000..06ae67f4 --- /dev/null +++ b/Src/Wasabi/api/timer/timeslicer.h @@ -0,0 +1,64 @@ +#ifndef __TIMESLICER_H +#define __TIMESLICER_H + +// TimeSlicer allows you to create a background job to perform while not blocking +// the main GUI thread. You give it the max percentage of CPU it should use, call star() +// and it'll start calling onSlice as many times as it can without using more cpu than requested +// +// To use this class, you need to break down your job into multiple tiny chunks that +// you perform in onSlice. Typical uses include adding files to or filtering entries from +// the database, driving state machines, etc. +// +// onSlice will be called multiple times per timer. + +#include "timerclient.h" + +enum { + GRANULARITY_EXTRALOW = 20, + GRANULARITY_LOW = 50, + GRANULARITY_MEDIUM = 100, + GRANULARITY_HIGH = 250, + GRANULARITY_EXTRAHIGH = 1000, +}; + +class TimeSlicer : public TimerClientI { + public: + + TimeSlicer(int percent_cpu_usage=25, int slice_duration=GRANULARITY_LOW); + virtual ~TimeSlicer(); + + virtual void timerclient_timerCallback(int id); + + void startSlicer(); + void stopSlicer(); + int isSlicerStarted(); + + virtual void onSlicerStart(); + virtual void onSlicerStop(); + virtual void onBeginSliceBatch() {} + virtual void onEndSliceBatch() {} + api_dependent *timerclient_getDependencyPtr() { return timeslicer_getDependencyPtr(); } + virtual api_dependent *timeslicer_getDependencyPtr()=0; + virtual void setFirstSliceMinTime(int ms) { firstslicetime = ms; } + virtual int getSliceCount() { return slicecount; } + + + // override this to do your work + virtual void onSlice() { } + + private: + + virtual void runSlice(DWORD start, DWORD stopwhen); + float max_cpu_usage; + int duration; + int started; + int firstslicetime; + int slicecount; +}; + +class TimeSlicerD : public TimeSlicer, public DependentI { + public: + virtual api_dependent *timeslicer_getDependencyPtr() { return this; } +}; + +#endif
\ No newline at end of file |