-
Notifications
You must be signed in to change notification settings - Fork 107
/
observer_list_threadsafe.cc
65 lines (51 loc) · 1.77 KB
/
observer_list_threadsafe.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/observer_list_threadsafe.h"
#include "base/compiler_specific.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
#if defined(STARBOARD)
#include <pthread.h>
#endif
namespace base {
namespace internal {
#if defined(STARBOARD)
namespace {
ABSL_CONST_INIT pthread_once_t s_once_flag = PTHREAD_ONCE_INIT;
ABSL_CONST_INIT SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid;
void InitThreadLocalKey() {
s_thread_local_key = SbThreadCreateLocalKey(NULL);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}
}
void ObserverListThreadSafeBase::EnsureThreadLocalKeyInited() {
pthread_once(&s_once_flag, InitThreadLocalKey);
DCHECK(SbThreadIsValidLocalKey(s_thread_local_key));
}
const SbThreadLocalKey ObserverListThreadSafeBase::GetThreadLocalKey() {
return s_thread_local_key;
}
#else
ABSL_CONST_INIT thread_local const ObserverListThreadSafeBase::
NotificationDataBase* current_notification = nullptr;
#endif
// static
const ObserverListThreadSafeBase::NotificationDataBase*&
ObserverListThreadSafeBase::GetCurrentNotification() {
#if defined(STARBOARD)
// We can't use a reference to a pointer in Starboard here.
NOTIMPLEMENTED();
static const ObserverListThreadSafeBase::NotificationDataBase* rv = nullptr;
return rv;
#else
// Workaround false-positive MSAN use-of-uninitialized-value on
// thread_local storage for loaded libraries:
// https://github.com/google/sanitizers/issues/1265
MSAN_UNPOISON(
¤t_notification,
sizeof(const ObserverListThreadSafeBase::NotificationDataBase*));
return current_notification;
#endif
}
} // namespace internal
} // namespace base