media/gmp-clearkey/0.1/RefCounted.h
author Mike de Boer <mdeboer@mozilla.com>
Fri, 10 Apr 2015 13:23:14 +0200
changeset 267072 719d7e41abeac7fee33b6d7ab4676ed6b537c3af
parent 250837 b096ec537e81ffa5a936761eb6f0e1d317fef0e3
child 269239 38f4f036b6119f8c3d00480426c505fb07a80306
permissions -rw-r--r--
Bug 1132301 - Part 5: Add unit tests for the Social Sharing feature of Loop. r=Standard8, a=lizzard

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __RefCount_h__
#define __RefCount_h__

// Note: Not thread safe!
class RefCounted {
public:
  void AddRef() {
    ++mRefCount;
  }

  uint32_t Release() {
    uint32_t newCount = --mRefCount;
    if (!newCount) {
      delete this;
    }
    return newCount;
  }

protected:
  RefCounted()
    : mRefCount(0)
  {
  }
  virtual ~RefCounted()
  {
  }
  uint32_t mRefCount;
};

#endif // __RefCount_h__