Blender  V3.3
GHOST_TimerManager.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
12 #include "GHOST_TimerManager.h"
13 
14 #include <algorithm>
15 
16 #include "GHOST_TimerTask.h"
17 
19 {
20 }
21 
23 {
24  disposeTimers();
25 }
26 
28 {
29  return (uint32_t)m_timers.size();
30 }
31 
33 {
34  TTimerVector::const_iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
35  return iter != m_timers.end();
36 }
37 
39 {
40  GHOST_TSuccess success;
41  if (!getTimerFound(timer)) {
42  /* Add the timer task. */
43  m_timers.push_back(timer);
44  success = GHOST_kSuccess;
45  }
46  else {
47  success = GHOST_kFailure;
48  }
49  return success;
50 }
51 
53 {
54  GHOST_TSuccess success;
55  TTimerVector::iterator iter = std::find(m_timers.begin(), m_timers.end(), timer);
56  if (iter != m_timers.end()) {
57  /* Remove the timer task. */
58  m_timers.erase(iter);
59  delete timer;
60  success = GHOST_kSuccess;
61  }
62  else {
63  success = GHOST_kFailure;
64  }
65  return success;
66 }
67 
69 {
70  uint64_t smallest = GHOST_kFireTimeNever;
71  TTimerVector::iterator iter;
72 
73  for (iter = m_timers.begin(); iter != m_timers.end(); ++iter) {
74  uint64_t next = (*iter)->getNext();
75 
76  if (next < smallest)
77  smallest = next;
78  }
79 
80  return smallest;
81 }
82 
84 {
85  TTimerVector::iterator iter;
86  bool anyProcessed = false;
87 
88  for (iter = m_timers.begin(); iter != m_timers.end(); ++iter) {
89  if (fireTimer(time, *iter))
90  anyProcessed = true;
91  }
92 
93  return anyProcessed;
94 }
95 
97 {
98  uint64_t next = task->getNext();
99 
100  /* Check if the timer should be fired. */
101  if (time > next) {
102  /* Fire the timer. */
103  GHOST_TimerProcPtr timerProc = task->getTimerProc();
104  uint64_t start = task->getStart();
105  timerProc(task, time - start);
106 
107  /* Update the time at which we will fire it again. */
108  uint64_t interval = task->getInterval();
109  uint64_t numCalls = (next - start) / interval;
110  numCalls++;
111  next = start + numCalls * interval;
112  task->setNext(next);
113 
114  return true;
115  }
116  else {
117  return false;
118  }
119 }
120 
122 {
123  while (m_timers.empty() == false) {
124  delete m_timers[0];
125  m_timers.erase(m_timers.begin());
126  }
127 }
void(* GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, uint64_t time)
Definition: GHOST_Types.h:614
GHOST_TSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFireTimeNever
Definition: GHOST_Types.h:116
bool fireTimers(uint64_t time)
GHOST_TSuccess removeTimer(GHOST_TimerTask *timer)
bool fireTimer(uint64_t time, GHOST_TimerTask *task)
bool getTimerFound(GHOST_TimerTask *timer)
GHOST_TSuccess addTimer(GHOST_TimerTask *timer)
double time
static ulong * next
struct blender::compositor::@179::@181 task
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90