Changeset 52369 in vbox
- Timestamp:
- Aug 13, 2014 5:18:30 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp
r46435 r52369 58 58 # include <iprt/req.h> 59 59 # include <iprt/mem.h> 60 # include <iprt/time.h> 61 # include <iprt/thread.h> 60 62 #endif /* VBOX */ 61 63 … … 131 133 // DCON_OP_SETUP_REPLY and DCON_OP_INVOKE_REPLY flags 132 134 #define DCON_OP_FLAGS_REPLY_EXCEPTION 0x0001 135 136 // Within this time all the worker threads must be terminated. 137 #define VBOX_XPCOM_SHUTDOWN_TIMEOUT_MS (5000) 133 138 134 139 #pragma pack(1) … … 2902 2907 NS_DECL_NSIRUNNABLE 2903 2908 2904 DConnectWorker(ipcDConnectService *aDConnect) : mDConnect (aDConnect) {}2909 DConnectWorker(ipcDConnectService *aDConnect) : mDConnect (aDConnect), mIsRunnable (PR_FALSE) {} 2905 2910 NS_HIDDEN_(nsresult) Init(); 2906 2911 NS_HIDDEN_(void) Join() { mThread->Join(); }; 2912 NS_HIDDEN_(bool) IsRunning() { return mIsRunnable; }; 2907 2913 2908 2914 private: 2909 2915 nsCOMPtr <nsIThread> mThread; 2910 2916 ipcDConnectService *mDConnect; 2917 2918 // Indicate if thread might be quickly joined on shutdown. 2919 volatile bool mIsRunnable; 2911 2920 }; 2912 2921 … … 2923 2932 { 2924 2933 LOG(("DConnect Worker thread started.\n")); 2934 2935 mIsRunnable = PR_TRUE; 2925 2936 2926 2937 nsAutoMonitor mon(mDConnect->mPendingMon); … … 2972 2983 } 2973 2984 } 2985 2986 mIsRunnable = PR_FALSE; 2974 2987 2975 2988 LOG(("DConnect Worker thread stopped.\n")); … … 3192 3205 #endif 3193 3206 3194 // destroy all worker threads 3195 for (int i = 0; i < mWorkers.Count(); i++) 3196 { 3197 DConnectWorker *worker = NS_STATIC_CAST(DConnectWorker *, mWorkers[i]); 3198 worker->Join(); 3199 delete worker; 3200 } 3207 3208 // Iterate over currently running worker threads 3209 // during VBOX_XPCOM_SHUTDOWN_TIMEOUT_MS, join() those who 3210 // exited a working loop and abandon ones which have not 3211 // managed to do that when timeout occurred. 3212 LOG(("Worker threads: %d\n", mWorkers.Count())); 3213 uint64_t tsStart = RTTimeMilliTS(); 3214 while ((tsStart + VBOX_XPCOM_SHUTDOWN_TIMEOUT_MS ) > RTTimeMilliTS() && mWorkers.Count() > 0) 3215 { 3216 // Some array elements might be deleted while iterating. Going from the last 3217 // to the first array element (intentionally) in order to do not conflict with 3218 // array indexing once element is deleted. 3219 for (int i = mWorkers.Count() - 1; i >= 0; i--) 3220 { 3221 DConnectWorker *worker = NS_STATIC_CAST(DConnectWorker *, mWorkers[i]); 3222 if (worker->IsRunning() == PR_FALSE) 3223 { 3224 LOG(("Worker %p joined.\n", worker)); 3225 worker->Join(); 3226 delete worker; 3227 mWorkers.RemoveElementAt(i); 3228 } 3229 } 3230 3231 // Relax a bit before the next round. 3232 RTThreadSleep(10); 3233 } 3234 3235 LOG(("There are %d thread(s) left.\n", mWorkers.Count())); 3236 3237 // If there are some running threads left, just forget about them. 3201 3238 mWorkers.Clear(); 3202 3239
Note:
See TracChangeset
for help on using the changeset viewer.