diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llcommon/llrun.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/llcommon/llrun.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/linden/indra/llcommon/llrun.cpp b/linden/indra/llcommon/llrun.cpp new file mode 100644 index 0000000..6cdae74 --- /dev/null +++ b/linden/indra/llcommon/llrun.cpp | |||
@@ -0,0 +1,175 @@ | |||
1 | /** | ||
2 | * @file llrun.cpp | ||
3 | * @author Phoenix | ||
4 | * @date 2006-02-16 | ||
5 | * @brief Implementation of the LLRunner and related classes | ||
6 | * | ||
7 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | #include "llrun.h" | ||
32 | |||
33 | #include "llframetimer.h" | ||
34 | |||
35 | static const LLRunner::run_handle_t INVALID_RUN_HANDLE = 0; | ||
36 | |||
37 | /** | ||
38 | * LLRunner | ||
39 | */ | ||
40 | LLRunner::LLRunner() : | ||
41 | mNextHandle(1) | ||
42 | { | ||
43 | } | ||
44 | |||
45 | LLRunner::~LLRunner() | ||
46 | { | ||
47 | mRunOnce.clear(); | ||
48 | mRunEvery.clear(); | ||
49 | } | ||
50 | |||
51 | S32 LLRunner::run() | ||
52 | { | ||
53 | // We collect all of the runnables which should be run. Since the | ||
54 | // runnables are allowed to adjust the run list, we need to copy | ||
55 | // them into a temporary structure which then iterates over them | ||
56 | // to call out of this method into the runnables. | ||
57 | F64 now = LLFrameTimer::getTotalSeconds(); | ||
58 | run_list_t run_now; | ||
59 | |||
60 | // Collect the run once. We erase the matching ones now because | ||
61 | // it's easier. If we find a reason to keep them around for a | ||
62 | // while, we can restructure this method. | ||
63 | LLRunner::run_list_t::iterator iter = mRunOnce.begin(); | ||
64 | for( ; iter != mRunOnce.end(); ) | ||
65 | { | ||
66 | if(now > (*iter).mNextRunAt) | ||
67 | { | ||
68 | run_now.push_back(*iter); | ||
69 | iter = mRunOnce.erase(iter); | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | ++iter; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | // Collect the ones that repeat. | ||
78 | iter = mRunEvery.begin(); | ||
79 | LLRunner::run_list_t::iterator end = mRunEvery.end(); | ||
80 | for( ; iter != end; ++iter ) | ||
81 | { | ||
82 | if(now > (*iter).mNextRunAt) | ||
83 | { | ||
84 | (*iter).mNextRunAt = now + (*iter).mIncrement; | ||
85 | run_now.push_back(*iter); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // Now, run them. | ||
90 | iter = run_now.begin(); | ||
91 | end = run_now.end(); | ||
92 | for( ; iter != end; ++iter ) | ||
93 | { | ||
94 | (*iter).mRunnable->run(this, (*iter).mHandle); | ||
95 | } | ||
96 | return run_now.size(); | ||
97 | } | ||
98 | |||
99 | LLRunner::run_handle_t LLRunner::addRunnable( | ||
100 | run_ptr_t runnable, | ||
101 | ERunSchedule schedule, | ||
102 | F64 seconds) | ||
103 | { | ||
104 | if(!runnable) return INVALID_RUN_HANDLE; | ||
105 | run_handle_t handle = mNextHandle++; | ||
106 | F64 next_run = LLFrameTimer::getTotalSeconds() + seconds; | ||
107 | LLRunInfo info(handle, runnable, schedule, next_run, seconds); | ||
108 | switch(schedule) | ||
109 | { | ||
110 | case RUN_IN: | ||
111 | // We could optimize this a bit by sorting this on entry. | ||
112 | mRunOnce.push_back(info); | ||
113 | break; | ||
114 | case RUN_EVERY: | ||
115 | mRunEvery.push_back(info); | ||
116 | break; | ||
117 | default: | ||
118 | handle = INVALID_RUN_HANDLE; | ||
119 | break; | ||
120 | } | ||
121 | return handle; | ||
122 | } | ||
123 | |||
124 | LLRunner::run_ptr_t LLRunner::removeRunnable(LLRunner::run_handle_t handle) | ||
125 | { | ||
126 | LLRunner::run_ptr_t rv; | ||
127 | LLRunner::run_list_t::iterator iter = mRunOnce.begin(); | ||
128 | LLRunner::run_list_t::iterator end = mRunOnce.end(); | ||
129 | for( ; iter != end; ++iter) | ||
130 | { | ||
131 | if((*iter).mHandle == handle) | ||
132 | { | ||
133 | rv = (*iter).mRunnable; | ||
134 | mRunOnce.erase(iter); | ||
135 | return rv; | ||
136 | } | ||
137 | } | ||
138 | |||
139 | iter = mRunEvery.begin(); | ||
140 | end = mRunEvery.end(); | ||
141 | for( ; iter != end; ++iter) | ||
142 | { | ||
143 | if((*iter).mHandle == handle) | ||
144 | { | ||
145 | rv = (*iter).mRunnable; | ||
146 | mRunEvery.erase(iter); | ||
147 | return rv; | ||
148 | } | ||
149 | } | ||
150 | return rv; | ||
151 | } | ||
152 | |||
153 | /** | ||
154 | * LLRunner::LLRunInfo | ||
155 | */ | ||
156 | LLRunner::LLRunInfo::LLRunInfo( | ||
157 | run_handle_t handle, | ||
158 | run_ptr_t runnable, | ||
159 | ERunSchedule schedule, | ||
160 | F64 next_run_after, | ||
161 | F64 increment) : | ||
162 | mHandle(handle), | ||
163 | mRunnable(runnable), | ||
164 | mSchedule(schedule), | ||
165 | mNextRunAt(next_run_after), | ||
166 | mIncrement(increment) | ||
167 | { | ||
168 | } | ||
169 | |||
170 | LLRunnable::LLRunnable() | ||
171 | { } | ||
172 | |||
173 | // virtual | ||
174 | LLRunnable::~LLRunnable() | ||
175 | { } | ||