1 : /*
2 : * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #define NACL_LOG_MODULE_NAME "weak_ref"
8 :
9 : #include "native_client/src/trusted/weak_ref/weak_ref.h"
10 :
11 : #include "native_client/src/shared/platform/nacl_check.h"
12 : #include "native_client/src/shared/platform/nacl_log.h"
13 : #include "native_client/src/shared/platform/nacl_sync.h"
14 : #include "native_client/src/shared/platform/nacl_sync_checked.h"
15 : #include "native_client/src/shared/platform/nacl_sync_raii.h"
16 :
17 : namespace nacl {
18 :
19 0 : AnchoredResource::AnchoredResource(WeakRefAnchor* anchor)
20 0 : : anchor_(anchor->Ref()) {
21 0 : NaClXMutexCtor(&mu_);
22 0 : }
23 :
24 0 : AnchoredResource::~AnchoredResource() {
25 0 : anchor_->Unref();
26 0 : NaClMutexDtor(&mu_);
27 0 : NaClLog(4, "~AnchoredResource: this 0x%"NACL_PRIxPTR"\n", (uintptr_t) this);
28 0 : }
29 :
30 0 : WeakRefAnchor::WeakRefAnchor()
31 0 : : abandoned_(false) {
32 0 : NaClXMutexCtor(&mu_);
33 0 : }
34 :
35 0 : WeakRefAnchor::~WeakRefAnchor() {
36 0 : NaClMutexDtor(&mu_);
37 0 : } // only via Unref
38 :
39 0 : bool WeakRefAnchor::is_abandoned() {
40 0 : nacl::MutexLocker take(&mu_);
41 0 : NaClLog(4, "is_abandoned: %d\n", abandoned_);
42 0 : return abandoned_;
43 : }
44 :
45 0 : void WeakRefAnchor::Abandon() {
46 0 : NaClLog(4,
47 : "Entered WeakRefAnchor::Abandon: this 0x%"NACL_PRIxPTR"\n",
48 0 : (uintptr_t) this);
49 : do {
50 0 : nacl::MutexLocker take(&mu_);
51 0 : abandoned_ = true;
52 : } while (0);
53 :
54 0 : NaClLog(4, "Leaving WeakRefAnchor::Abandon\n");
55 0 : }
56 :
57 : } // namespace nacl
|