1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_SALHELPER_REFOBJ_HXX
25 #define INCLUDED_SALHELPER_REFOBJ_HXX
29 #include "sal/types.h"
30 #include "rtl/alloc.h"
31 #include "osl/interlck.h"
36 /** A base implementation for reference-counted objects.
38 @deprecated use salhelper::SimpleReferenceObject instead
44 oslInterlockedCount m_nReferenceCount
;
46 ReferenceObject (const ReferenceObject
&) SAL_DELETED_FUNCTION
;
47 ReferenceObject
& operator= (const ReferenceObject
&) SAL_DELETED_FUNCTION
;
52 static void* operator new (size_t n
)
54 return ::rtl_allocateMemory (n
);
56 static void operator delete (void* p
)
60 static void* operator new (size_t, void* p
)
64 static void operator delete (void*, void*)
70 ReferenceObject() : m_nReferenceCount(0)
74 void SAL_CALL
acquire()
76 osl_atomic_increment(&m_nReferenceCount
);
79 void SAL_CALL
release()
81 if (osl_atomic_decrement(&m_nReferenceCount
) == 0)
83 // Last reference released.
91 virtual ~ReferenceObject()
93 assert(m_nReferenceCount
== 0);
98 } // namespace salhelper
100 #endif /* ! INCLUDED_SALHELPER_REFOBJ_HXX */
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */