Panda3D
weakReferenceList.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file weakReferenceList.h
10  * @author drose
11  * @date 2004-09-27
12  */
13 
14 #ifndef WEAKREFERENCELIST_H
15 #define WEAKREFERENCELIST_H
16 
17 #include "pandabase.h"
18 #include "pmap.h"
19 #include "mutexImpl.h"
20 
22 
23 /**
24  * This is an object shared by all the weak pointers that point to the same
25  * ReferenceCount object. It is created whenever a weak reference to an
26  * object is created, and can outlive the object until all weak references
27  * have disappeared.
28  */
29 class EXPCL_PANDA_EXPRESS WeakReferenceList {
30 public:
33 
34  INLINE void ref() const;
35  INLINE bool unref() const;
36  INLINE bool was_deleted() const;
37 
38  void add_callback(WeakPointerCallback *callback, void *data);
39  void remove_callback(WeakPointerCallback *callback);
40 
41 private:
42  void mark_deleted();
43 
44 public:
45  // This lock protects the callbacks below, but it also protects the object
46  // from being deleted during a call to WeakPointerTo::lock().
47  MutexImpl _lock;
48 
49 private:
51  Callbacks _callbacks;
52 
53  // This has a very large number added to it if the object is still alive.
54  // It could be 1, but having it be a large number makes it easy to check
55  // whether the object has been deleted or not.
56  static const AtomicAdjust::Integer _alive_offset = (1 << 30);
57  mutable AtomicAdjust::Integer _count;
58 
59  friend class ReferenceCount;
60 };
61 
62 #include "weakReferenceList.I"
63 
64 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an object shared by all the weak pointers that point to the same ReferenceCount object.
Derive from this class and override the callback() method if you want to get an immediate callback fr...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for all things that want to be reference-counted.
A fake mutex implementation for single-threaded applications that don't need any synchronization cont...