diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llcommon/llworkerthread.h | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llcommon/llworkerthread.h')
-rw-r--r-- | linden/indra/llcommon/llworkerthread.h | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/linden/indra/llcommon/llworkerthread.h b/linden/indra/llcommon/llworkerthread.h index f01e67b..17b7e7b 100644 --- a/linden/indra/llcommon/llworkerthread.h +++ b/linden/indra/llcommon/llworkerthread.h | |||
@@ -47,13 +47,13 @@ class LLWorkerClass; | |||
47 | class LLWorkerThread : public LLQueuedThread | 47 | class LLWorkerThread : public LLQueuedThread |
48 | { | 48 | { |
49 | public: | 49 | public: |
50 | class Request : public LLQueuedThread::QueuedRequest | 50 | class WorkRequest : public LLQueuedThread::QueuedRequest |
51 | { | 51 | { |
52 | protected: | 52 | protected: |
53 | ~Request() {}; // use deleteRequest() | 53 | virtual ~WorkRequest(); // use deleteRequest() |
54 | 54 | ||
55 | public: | 55 | public: |
56 | Request(handle_t handle, U32 priority, LLWorkerClass* workerclass, S32 param); | 56 | WorkRequest(handle_t handle, U32 priority, LLWorkerClass* workerclass, S32 param); |
57 | 57 | ||
58 | S32 getParam() | 58 | S32 getParam() |
59 | { | 59 | { |
@@ -64,6 +64,8 @@ public: | |||
64 | return mWorkerClass; | 64 | return mWorkerClass; |
65 | } | 65 | } |
66 | 66 | ||
67 | /*virtual*/ bool processRequest(); | ||
68 | /*virtual*/ void finishRequest(bool completed); | ||
67 | /*virtual*/ void deleteRequest(); | 69 | /*virtual*/ void deleteRequest(); |
68 | 70 | ||
69 | private: | 71 | private: |
@@ -71,26 +73,24 @@ public: | |||
71 | S32 mParam; | 73 | S32 mParam; |
72 | }; | 74 | }; |
73 | 75 | ||
74 | public: | 76 | private: |
75 | LLWorkerThread(bool threaded = true, bool runalways = true); | 77 | typedef std::list<LLWorkerClass*> delete_list_t; |
76 | ~LLWorkerThread(); | 78 | delete_list_t mDeleteList; |
77 | 79 | LLMutex* mDeleteMutex; | |
78 | protected: | 80 | apr_pool_t* mWorkerAPRPoolp; |
79 | /*virtual*/ bool processRequest(QueuedRequest* req); | ||
80 | 81 | ||
81 | public: | 82 | public: |
82 | handle_t add(LLWorkerClass* workerclass, S32 param, U32 priority = PRIORITY_NORMAL); | 83 | LLWorkerThread(const std::string& name, bool threaded = true); |
83 | 84 | ~LLWorkerThread(); | |
84 | static void initClass(bool local_is_threaded = true, bool local_run_always = true); // Setup sLocal | ||
85 | static S32 updateClass(U32 ms_elapsed); | ||
86 | static S32 getAllPending(); | ||
87 | static void pauseAll(); | ||
88 | static void waitOnAllPending(); | ||
89 | static void cleanupClass(); // Delete sLocal | ||
90 | 85 | ||
91 | public: | 86 | apr_pool_t* getWorkerAPRPool() { return mWorkerAPRPoolp; } |
92 | static LLWorkerThread* sLocal; // Default worker thread | 87 | |
93 | static std::set<LLWorkerThread*> sThreadList; // array of threads (includes sLocal) | 88 | /*virtual*/ S32 update(U32 max_time_ms); |
89 | |||
90 | handle_t addWorkRequest(LLWorkerClass* workerclass, S32 param, U32 priority = PRIORITY_NORMAL); | ||
91 | |||
92 | void deleteWorker(LLWorkerClass* workerclass); // schedule for deletion | ||
93 | S32 getNumDeletes() { return mDeleteList.size(); } // debug | ||
94 | }; | 94 | }; |
95 | 95 | ||
96 | //============================================================================ | 96 | //============================================================================ |
@@ -112,11 +112,17 @@ public: | |||
112 | 112 | ||
113 | class LLWorkerClass | 113 | class LLWorkerClass |
114 | { | 114 | { |
115 | friend class LLWorkerThread; | ||
116 | friend class LLWorkerThread::WorkRequest; | ||
115 | public: | 117 | public: |
116 | typedef LLWorkerThread::handle_t handle_t; | 118 | typedef LLWorkerThread::handle_t handle_t; |
117 | enum FLAGS | 119 | enum FLAGS |
118 | { | 120 | { |
119 | WCF_WORKING = 0x01, | 121 | WCF_HAVE_WORK = 0x01, |
122 | WCF_WORKING = 0x02, | ||
123 | WCF_WORK_FINISHED = 0x10, | ||
124 | WCF_WORK_ABORTED = 0x20, | ||
125 | WCF_DELETE_REQUESTED = 0x40, | ||
120 | WCF_ABORT_REQUESTED = 0x80 | 126 | WCF_ABORT_REQUESTED = 0x80 |
121 | }; | 127 | }; |
122 | 128 | ||
@@ -125,17 +131,29 @@ public: | |||
125 | virtual ~LLWorkerClass(); | 131 | virtual ~LLWorkerClass(); |
126 | 132 | ||
127 | // pure virtual, called from WORKER THREAD, returns TRUE if done | 133 | // pure virtual, called from WORKER THREAD, returns TRUE if done |
128 | virtual bool doWork(S32 param)=0; // Called from LLWorkerThread::processRequest() | 134 | virtual bool doWork(S32 param)=0; // Called from WorkRequest::processRequest() |
129 | 135 | // virtual, called from finishRequest() after completed or aborted | |
130 | // called from WORKER THREAD | 136 | virtual void finishWork(S32 param, bool completed); // called from finishRequest() (WORK THREAD) |
131 | void setWorking(bool working) { working ? setFlags(WCF_WORKING) : clearFlags(WCF_WORKING); } | 137 | // virtual, returns true if safe to delete the worker |
138 | virtual bool deleteOK(); // called from update() (WORK THREAD) | ||
132 | 139 | ||
140 | // schedlueDelete(): schedules deletion once aborted or completed | ||
141 | void scheduleDelete(); | ||
142 | |||
143 | bool haveWork() { return getFlags(WCF_HAVE_WORK); } // may still be true if aborted | ||
133 | bool isWorking() { return getFlags(WCF_WORKING); } | 144 | bool isWorking() { return getFlags(WCF_WORKING); } |
134 | bool wasAborted() { return getFlags(WCF_ABORT_REQUESTED); } | 145 | bool wasAborted() { return getFlags(WCF_ABORT_REQUESTED); } |
146 | |||
147 | // setPriority(): changes the priority of a request | ||
148 | void setPriority(U32 priority); | ||
149 | U32 getPriority() { return mRequestPriority; } | ||
135 | 150 | ||
136 | const std::string& getName() const { return mWorkerClassName; } | 151 | const std::string& getName() const { return mWorkerClassName; } |
137 | 152 | ||
138 | protected: | 153 | protected: |
154 | // called from WORKER THREAD | ||
155 | void setWorking(bool working); | ||
156 | |||
139 | // Call from doWork only to avoid eating up cpu time. | 157 | // Call from doWork only to avoid eating up cpu time. |
140 | // Returns true if work has been aborted | 158 | // Returns true if work has been aborted |
141 | // yields the current thread and calls mWorkerThread->checkPause() | 159 | // yields the current thread and calls mWorkerThread->checkPause() |
@@ -147,20 +165,11 @@ protected: | |||
147 | void addWork(S32 param, U32 priority = LLWorkerThread::PRIORITY_NORMAL); | 165 | void addWork(S32 param, U32 priority = LLWorkerThread::PRIORITY_NORMAL); |
148 | 166 | ||
149 | // abortWork(): requests that work be aborted | 167 | // abortWork(): requests that work be aborted |
150 | void abortWork(); | 168 | void abortWork(bool autocomplete); |
151 | 169 | ||
152 | // checkWork(): if doWork is complete or aborted, call endWork() and return true | 170 | // checkWork(): if doWork is complete or aborted, call endWork() and return true |
153 | bool checkWork(); | 171 | bool checkWork(bool aborting = false); |
154 | 172 | ||
155 | // haveWork(): return true if mWorkHandle != null | ||
156 | bool haveWork() { return mWorkHandle != LLWorkerThread::nullHandle(); } | ||
157 | |||
158 | // killWork(): aborts work and waits for the abort to process | ||
159 | void killWork(); | ||
160 | |||
161 | // setPriority(): changes the priority of a request | ||
162 | void setPriority(U32 priority); | ||
163 | |||
164 | private: | 173 | private: |
165 | void setFlags(U32 flags) { mWorkFlags = mWorkFlags | flags; } | 174 | void setFlags(U32 flags) { mWorkFlags = mWorkFlags | flags; } |
166 | void clearFlags(U32 flags) { mWorkFlags = mWorkFlags & ~flags; } | 175 | void clearFlags(U32 flags) { mWorkFlags = mWorkFlags & ~flags; } |
@@ -175,9 +184,11 @@ private: | |||
175 | protected: | 184 | protected: |
176 | LLWorkerThread* mWorkerThread; | 185 | LLWorkerThread* mWorkerThread; |
177 | std::string mWorkerClassName; | 186 | std::string mWorkerClassName; |
178 | handle_t mWorkHandle; | 187 | handle_t mRequestHandle; |
188 | U32 mRequestPriority; // last priority set | ||
179 | 189 | ||
180 | private: | 190 | private: |
191 | LLMutex mMutex; | ||
181 | LLAtomicU32 mWorkFlags; | 192 | LLAtomicU32 mWorkFlags; |
182 | }; | 193 | }; |
183 | 194 | ||