1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/cache2/CacheIOThread.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef CacheIOThread__h__ 1.9 +#define CacheIOThread__h__ 1.10 + 1.11 +#include "nsIThreadInternal.h" 1.12 +#include "nsISupportsImpl.h" 1.13 +#include "prthread.h" 1.14 +#include "nsTArray.h" 1.15 +#include "nsAutoPtr.h" 1.16 +#include "mozilla/Monitor.h" 1.17 + 1.18 +class nsIRunnable; 1.19 + 1.20 +namespace mozilla { 1.21 +namespace net { 1.22 + 1.23 +class CacheIOThread : public nsIThreadObserver 1.24 +{ 1.25 +public: 1.26 + NS_DECL_THREADSAFE_ISUPPORTS 1.27 + NS_DECL_NSITHREADOBSERVER 1.28 + 1.29 + CacheIOThread(); 1.30 + virtual ~CacheIOThread(); 1.31 + 1.32 + enum ELevel { 1.33 + OPEN_PRIORITY, 1.34 + READ_PRIORITY, 1.35 + OPEN, 1.36 + READ, 1.37 + MANAGEMENT, 1.38 + WRITE, 1.39 + CLOSE, 1.40 + INDEX, 1.41 + EVICT, 1.42 + LAST_LEVEL, 1.43 + 1.44 + // This is actually executed as the first level, but we want this enum 1.45 + // value merely as an indicator while other values are used as indexes 1.46 + // to the queue array. Hence put at end and not as the first. 1.47 + XPCOM_LEVEL 1.48 + }; 1.49 + 1.50 + nsresult Init(); 1.51 + nsresult Dispatch(nsIRunnable* aRunnable, uint32_t aLevel); 1.52 + // Makes sure that any previously posted event to OPEN or OPEN_PRIORITY 1.53 + // levels (such as file opennings and dooms) are executed before aRunnable 1.54 + // that is intended to evict stuff from the cache. 1.55 + nsresult DispatchAfterPendingOpens(nsIRunnable* aRunnable); 1.56 + bool IsCurrentThread(); 1.57 + 1.58 + /** 1.59 + * Callable only on this thread, checks if there is an event waiting in 1.60 + * the event queue with a higher execution priority. If so, the result 1.61 + * is true and the current event handler should break it's work and return 1.62 + * from Run() method immediately. The event handler will be rerun again 1.63 + * when all more priority events are processed. Events pending after this 1.64 + * handler (i.e. the one that called YieldAndRerun()) will not execute sooner 1.65 + * then this handler is executed w/o a call to YieldAndRerun(). 1.66 + */ 1.67 + static bool YieldAndRerun() 1.68 + { 1.69 + return sSelf ? sSelf->YieldInternal() : false; 1.70 + } 1.71 + 1.72 + nsresult Shutdown(); 1.73 + already_AddRefed<nsIEventTarget> Target(); 1.74 + 1.75 + // Memory reporting 1.76 + size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const; 1.77 + size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; 1.78 + 1.79 +private: 1.80 + static void ThreadFunc(void* aClosure); 1.81 + void ThreadFunc(); 1.82 + void LoopOneLevel(uint32_t aLevel); 1.83 + bool EventsPending(uint32_t aLastLevel = LAST_LEVEL); 1.84 + nsresult DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel); 1.85 + bool YieldInternal(); 1.86 + 1.87 + static CacheIOThread* sSelf; 1.88 + 1.89 + mozilla::Monitor mMonitor; 1.90 + PRThread* mThread; 1.91 + nsCOMPtr<nsIThread> mXPCOMThread; 1.92 + uint32_t mLowestLevelWaiting; 1.93 + uint32_t mCurrentlyExecutingLevel; 1.94 + nsTArray<nsRefPtr<nsIRunnable> > mEventQueue[LAST_LEVEL]; 1.95 + 1.96 + bool mHasXPCOMEvents; 1.97 + bool mRerunCurrentEvent; 1.98 + bool mShutdown; 1.99 +}; 1.100 + 1.101 +} // net 1.102 +} // mozilla 1.103 + 1.104 +#endif