OpenShot Audio Library | OpenShotAudio  0.6.0
juce_TimeSliceThread.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 namespace juce
24 {
25 
26 class TimeSliceThread;
27 
28 
29 //==============================================================================
43 class JUCE_API TimeSliceClient
44 {
45 public:
47  virtual ~TimeSliceClient() = default;
48 
64  virtual int useTimeSlice() = 0;
65 
66 
67 private:
68  friend class TimeSliceThread;
69  Time nextCallTime;
70 };
71 
72 
73 //==============================================================================
82 class JUCE_API TimeSliceThread : public Thread
83 {
84 public:
85  //==============================================================================
92  explicit TimeSliceThread (const String& threadName);
93 
101  ~TimeSliceThread() override;
102 
103  //==============================================================================
108  void addTimeSliceClient (TimeSliceClient* clientToAdd, int millisecondsBeforeStarting = 0);
109 
114  void moveToFrontOfQueue (TimeSliceClient* clientToMove);
115 
120  void removeTimeSliceClient (TimeSliceClient* clientToRemove);
121 
126  void removeAllClients();
127 
129  int getNumClients() const;
130 
132  TimeSliceClient* getClient (int index) const;
133 
135  bool contains (const TimeSliceClient*) const;
136 
137  //==============================================================================
138  #ifndef DOXYGEN
139  void run() override;
140  #endif
141 
142  //==============================================================================
143 private:
144  CriticalSection callbackLock, listLock;
145  Array<TimeSliceClient*> clients;
146  TimeSliceClient* clientBeingCalled = nullptr;
147 
148  TimeSliceClient* getNextClient (int index) const;
149 
150  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TimeSliceThread)
151 };
152 
153 } // namespace juce
virtual int useTimeSlice()=0
virtual ~TimeSliceClient()=default