~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/zmm/object.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-02-02 01:42:48 UTC
  • Revision ID: james.westby@ubuntu.com-20080202014248-cjouolddb8gi2zkz
Tags: upstream-0.10.0.dfsg1
ImportĀ upstreamĀ versionĀ 0.10.0.dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*MT*
 
2
    
 
3
    MediaTomb - http://www.mediatomb.cc/
 
4
    
 
5
    object.cc - this file is part of MediaTomb.
 
6
    
 
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
 
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
 
9
    
 
10
    Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
 
12
                            Leonhard Wimmer <leo@mediatomb.cc>
 
13
    
 
14
    MediaTomb is free software; you can redistribute it and/or modify
 
15
    it under the terms of the GNU General Public License version 2
 
16
    as published by the Free Software Foundation.
 
17
    
 
18
    MediaTomb is distributed in the hope that it will be useful,
 
19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
    GNU General Public License for more details.
 
22
    
 
23
    You should have received a copy of the GNU General Public License
 
24
    version 2 along with MediaTomb; if not, write to the Free Software
 
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
    
 
27
    $Id: object.cc 1294 2007-05-13 16:28:24Z lww $
 
28
*/
 
29
 
 
30
/// \file object.cc
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
    #include "autoconfig.h"
 
34
#endif
 
35
 
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
 
 
39
#include "object.h"
 
40
#include "memory.h"
 
41
 
 
42
using namespace zmm;
 
43
 
 
44
Object::Object()
 
45
{
 
46
    atomic_set(&_ref_count, 0);
 
47
#ifdef ATOMIC_NEED_MUTEX
 
48
    pthread_mutex_init(&mutex, NULL);
 
49
#endif
 
50
}
 
51
Object::~Object()
 
52
{
 
53
#ifdef ATOMIC_NEED_MUTEX
 
54
    pthread_mutex_destroy(&mutex);
 
55
#endif
 
56
}
 
57
 
 
58
void Object::retain()
 
59
{
 
60
#ifdef ATOMIC_NEED_MUTEX
 
61
    atomic_inc(&_ref_count, &mutex);
 
62
#else
 
63
    atomic_inc(&_ref_count);
 
64
#endif
 
65
}
 
66
void Object::release()
 
67
{
 
68
#ifdef ATOMIC_NEED_MUTEX
 
69
    if(atomic_dec(&_ref_count, &mutex))
 
70
#else
 
71
    if(atomic_dec(&_ref_count))
 
72
#endif
 
73
    {
 
74
        delete this;
 
75
    }
 
76
}
 
77
 
 
78
int Object::getRefCount()
 
79
{
 
80
    return atomic_get(&_ref_count);
 
81
}
 
82
 
 
83
void* Object::operator new (size_t size)
 
84
{
 
85
    return MALLOC(size);
 
86
}
 
87
void Object::operator delete (void *ptr)
 
88
{
 
89
    FREE(ptr);
 
90
}