LCOV - app.info - dom/workers/Workers.h

LCOV - code coverage report
| Current view: | directory - dom/workers - Workers.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 10 | 0 | 0.0 %
| Date: | 2012-06-02 | Functions: | 8 | 0 | 0.0 %

           1                 : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is Web Workers.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  *   The Mozilla Foundation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *   Ben Turner <bent.mozilla@gmail.com> (Original Author)
          24                 :  *
          25                 :  * Alternatively, the contents of this file may be used under the terms of
          26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          29                 :  * of those above. If you wish to allow use of your version of this file only
          30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          31                 :  * use your version of this file under the terms of the MPL, indicate your
          32                 :  * decision by deleting the provisions above and replace them with the notice
          33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          34                 :  * the provisions above, a recipient may use your version of this file under
          35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          36                 :  *
          37                 :  * ***** END LICENSE BLOCK ***** */
          38                 :
          39                 : #ifndef mozilla_dom_workers_workers_h__
          40                 : #define mozilla_dom_workers_workers_h__
          41                 :
          42                 : #include "jspubtd.h"
          43                 : #include "jsapi.h"
          44                 : #include "nsISupportsImpl.h"
          45                 : #include "mozilla/Mutex.h"
          46                 :
          47                 : #define BEGIN_WORKERS_NAMESPACE \
          48                 :   namespace mozilla { namespace dom { namespace workers {
          49                 : #define END_WORKERS_NAMESPACE \
          50                 :   } /* namespace workers */ } /* namespace dom */ } /* namespace mozilla */
          51                 : #define USING_WORKERS_NAMESPACE \
          52                 :   using namespace mozilla::dom::workers;
          53                 :
          54                 : #define WORKERS_SHUTDOWN_TOPIC "web-workers-shutdown"
          55                 :
          56                 : class nsPIDOMWindow;
          57                 :
          58                 : BEGIN_WORKERS_NAMESPACE
          59                 :
          60                 : class WorkerPrivate;
          61                 :
          62                 : struct PrivatizableBase
          63               0 : { };
          64                 :
          65                 : #ifdef DEBUG
          66                 : void
          67                 : AssertIsOnMainThread();
          68                 : #else
          69                 : inline void
          70                 : AssertIsOnMainThread()
          71                 : { }
          72                 : #endif
          73                 :
          74                 : // All of these are implemented in RuntimeService.cpp
          75                 : JSBool
          76                 : ResolveWorkerClasses(JSContext* aCx, JSObject* aObj, jsid aId, unsigned aFlags,
          77                 :                      JSObject** aObjp);
          78                 :
          79                 : void
          80                 : CancelWorkersForWindow(JSContext* aCx, nsPIDOMWindow* aWindow);
          81                 :
          82                 : void
          83                 : SuspendWorkersForWindow(JSContext* aCx, nsPIDOMWindow* aWindow);
          84                 :
          85                 : void
          86                 : ResumeWorkersForWindow(JSContext* aCx, nsPIDOMWindow* aWindow);
          87                 :
          88                 : class WorkerTask {
          89                 : public:
          90               0 :     NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkerTask)
          91                 :
          92                 :     virtual ~WorkerTask() { }
          93                 :
          94                 :     virtual bool RunTask(JSContext* aCx) = 0;
          95                 : };
          96                 :
          97               0 : class WorkerCrossThreadDispatcher {
          98                 : public:
          99               0 :   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkerCrossThreadDispatcher)
         100                 :
         101               0 :   WorkerCrossThreadDispatcher(WorkerPrivate* aPrivate) :
         102               0 :     mMutex("WorkerCrossThreadDispatcher"), mPrivate(aPrivate) {}
         103               0 :   void Forget()
         104                 :   {
         105               0 :     mozilla::MutexAutoLock lock(mMutex);
         106               0 :     mPrivate = nsnull;
         107               0 :   }
         108                 :
         109                 :   /**
         110                 :    * Generically useful function for running a bit of C++ code on the worker
         111                 :    * thread.
         112                 :    */
         113                 :   bool PostTask(WorkerTask* aTask);
         114                 :
         115                 : protected:
         116                 :   friend class WorkerPrivate;
         117                 :
         118                 :   // Must be acquired *before* the WorkerPrivate's mutex, when they're both held.
         119                 :   mozilla::Mutex mMutex;
         120                 :   WorkerPrivate* mPrivate;
         121                 : };
         122                 :
         123                 : WorkerCrossThreadDispatcher*
         124                 : GetWorkerCrossThreadDispatcher(JSContext* aCx, jsval aWorker);
         125                 :
         126                 : // Random unique constant to facilitate JSPrincipal debugging
         127                 : const uint32_t kJSPrincipalsDebugToken = 0x7e2df9d2;
         128                 :
         129                 : END_WORKERS_NAMESPACE
         130                 :
         131                 : #endif /* mozilla_dom_workers_workers_h__ */

Generated by: LCOV version 1.7