Bumping manifests a=b2g-bump
[gecko.git] / dom / workers / Principal.cpp
blob21b99e552ed6469b991a7e49d9b23e3d59a96414
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "Principal.h"
8 #include "jsapi.h"
9 #include "mozilla/Assertions.h"
11 BEGIN_WORKERS_NAMESPACE
13 JSPrincipals*
14 GetWorkerPrincipal()
16 static JSPrincipals sPrincipal;
19 * To make sure the the principals refcount is initialized to one, atomically
20 * increment it on every pass though this function. If we discover this wasn't
21 * the first time, decrement it again. This avoids the need for
22 * synchronization.
24 int32_t prevRefcount = sPrincipal.refcount++;
25 if (prevRefcount > 0) {
26 --sPrincipal.refcount;
27 } else {
28 #ifdef DEBUG
29 sPrincipal.debugToken = kJSPrincipalsDebugToken;
30 #endif
33 return &sPrincipal;
36 void
37 DestroyWorkerPrincipals(JSPrincipals* aPrincipals)
39 MOZ_ASSERT_UNREACHABLE("Worker principals refcount should never fall below one");
42 END_WORKERS_NAMESPACE