<commit_before>/*
 * Copyright 2008 The Native Client Authors.  All rights reserved.
 * Use of this source code is governed by a BSD-style license that can
 * be found in the LICENSE file.
 */

#include "native_client/src/trusted/nacl_base/nacl_refcount.h"

#include "native_client/src/shared/platform/nacl_log.h"
#include "native_client/src/shared/platform/nacl_sync_checked.h"

int NaClRefCountCtor(struct NaClRefCount *nrcp) {
  nrcp->ref_count = 1;
  nrcp->vtbl = (struct NaClRefCountVtbl *) NULL;
  if (NaClMutexCtor(&nrcp->mu)) {
    nrcp->vtbl = &kNaClRefCountVtbl;
    return 1;
  }
  return 0;
}

static void NaClRefCountDtor(struct NaClRefCount  *self) {
  NaClLog(4, "NaClRefCountDtor(0x%08"NACL_PRIxPTR"), refcount %"NACL_PRIdS
          ", destroying.\n",
          self->ref_count,
          (uintptr_t) self);
  /*
   * NB: refcount could be non-zero.  Here's why: if a subclass's Ctor
   * fails, it will have already run NaClRefCountCtor and have
   * initialized the mutex and set the ref_count to 1.  Because Unref
   * would free memory and Ctors aren't factories, the subclass Ctor
   * cannot just invoke NaClRefCountUnref; instead, it must directly<commit_msg>Fixed a bug in logging output where object ptr and refcount arguments were reversed. Review URL: http://codereview.chromium.org/6812035<commit_after>/*
 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "native_client/src/trusted/nacl_base/nacl_refcount.h"

#include "native_client/src/shared/platform/nacl_log.h"
#include "native_client/src/shared/platform/nacl_sync_checked.h"

int NaClRefCountCtor(struct NaClRefCount *nrcp) {
  nrcp->ref_count = 1;
  nrcp->vtbl = (struct NaClRefCountVtbl *) NULL;
  if (NaClMutexCtor(&nrcp->mu)) {
    nrcp->vtbl = &kNaClRefCountVtbl;
    return 1;
  }
  return 0;
}

static void NaClRefCountDtor(struct NaClRefCount  *self) {
  NaClLog(4, "NaClRefCountDtor(0x%08"NACL_PRIxPTR"), refcount %"NACL_PRIdS
          ", destroying.\n",
          (uintptr_t) self,
          self->ref_count);
  /*
   * NB: refcount could be non-zero.  Here's why: if a subclass's Ctor
   * fails, it will have already run NaClRefCountCtor and have
   * initialized the mutex and set the ref_count to 1.  Because Unref
   * would free memory and Ctors aren't factories, the subclass Ctor
   * cannot just invoke NaClRefCountUnref; instead, it must directly
{'fraction_non_alphanumeric': 0.09795262946607788, 'fraction_numerical': 0.012444801284624649, 'mean_word_length': 3.857699805068226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5434719', 'n_tokens_mistral': 899, 'n_tokens_neox': 843, 'n_words': 248}