Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/Assertions.h"
8 #include "mozilla/DebugOnly.h"
9 #include "mozilla/NullPtr.h"
11 #include "LulRWLock.h"
14 namespace lul {
16 // An implementation for targets where libpthread does provide
17 // pthread_rwlock_t. These are straight wrappers around the
18 // equivalent pthread functions.
20 #if defined(LUL_OS_linux)
22 LulRWLock::LulRWLock() {
23 mozilla::DebugOnly<int> r = pthread_rwlock_init(&mLock, nullptr);
24 MOZ_ASSERT(!r);
25 }
27 LulRWLock::~LulRWLock() {
28 mozilla::DebugOnly<int>r = pthread_rwlock_destroy(&mLock);
29 MOZ_ASSERT(!r);
30 }
32 void
33 LulRWLock::WrLock() {
34 mozilla::DebugOnly<int>r = pthread_rwlock_wrlock(&mLock);
35 MOZ_ASSERT(!r);
36 }
38 void
39 LulRWLock::RdLock() {
40 mozilla::DebugOnly<int>r = pthread_rwlock_rdlock(&mLock);
41 MOZ_ASSERT(!r);
42 }
44 void
45 LulRWLock::Unlock() {
46 mozilla::DebugOnly<int>r = pthread_rwlock_unlock(&mLock);
47 MOZ_ASSERT(!r);
48 }
51 // An implementation for cases where libpthread does not provide
52 // pthread_rwlock_t. Currently this is a kludge in that it uses
53 // normal mutexes, resulting in the following limitations: (1) at most
54 // one reader is allowed at once, and (2) any thread that tries to
55 // read-acquire the lock more than once will deadlock. (2) could be
56 // avoided if it were possible to use recursive pthread_mutex_t's.
58 #elif defined(LUL_OS_android)
60 LulRWLock::LulRWLock() {
61 mozilla::DebugOnly<int> r = pthread_mutex_init(&mLock, nullptr);
62 MOZ_ASSERT(!r);
63 }
65 LulRWLock::~LulRWLock() {
66 mozilla::DebugOnly<int>r = pthread_mutex_destroy(&mLock);
67 MOZ_ASSERT(!r);
68 }
70 void
71 LulRWLock::WrLock() {
72 mozilla::DebugOnly<int>r = pthread_mutex_lock(&mLock);
73 MOZ_ASSERT(!r);
74 }
76 void
77 LulRWLock::RdLock() {
78 mozilla::DebugOnly<int>r = pthread_mutex_lock(&mLock);
79 MOZ_ASSERT(!r);
80 }
82 void
83 LulRWLock::Unlock() {
84 mozilla::DebugOnly<int>r = pthread_mutex_unlock(&mLock);
85 MOZ_ASSERT(!r);
86 }
89 #else
90 # error "Unsupported OS"
91 #endif
93 } // namespace lul