4 #ifndef JAWS_CACHE_OBJECT_H
5 #define JAWS_CACHE_OBJECT_H
7 #include "ace/Thread_Mutex.h"
8 #include "ace/Synch_Traits.h"
9 #include "ace/Malloc.h"
10 #include "ace/RW_Thread_Mutex.h"
11 #include "ace/Lock_Adapter_T.h"
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_END_VERSIONED_NAMESPACE_DECL
18 // Cache bucket -- use Hash_Bucket to hold cacheable objects.
20 class JAWS_Cache_Object
23 JAWS_Cache_Object (const void *, size_t);
24 virtual ~JAWS_Cache_Object ();
26 void *internal () const;
27 void internal (void *);
29 const void *data () const;
31 unsigned int count () const;
36 time_t last_access () const;
37 time_t first_access () const;
39 unsigned int priority () const;
41 enum { ACE_CO_REFERENCED
, ACE_CO_COUNTED
};
43 void *heap_item () const;
44 void heap_item (void *item
);
46 virtual ACE_Lock
& lock () = 0;
49 virtual unsigned int count_i () const = 0;
50 virtual int acquire_i () = 0;
51 virtual int release_i () = 0;
52 virtual unsigned int priority_i () const = 0;
61 time_t new_last_access_
;
66 class JAWS_Referenced_Cache_Object
: public JAWS_Cache_Object
69 JAWS_Referenced_Cache_Object (const void *, size_t);
70 virtual ~JAWS_Referenced_Cache_Object ();
72 virtual ACE_Lock
& lock ();
75 virtual unsigned int count_i () const;
76 virtual int acquire_i ();
77 virtual int release_i ();
78 virtual unsigned int priority_i () const;
81 mutable ACE_SYNCH_RW_MUTEX count_
;
82 mutable ACE_Lock_Adapter
<ACE_SYNCH_RW_MUTEX
> lock_adapter_
;
85 class JAWS_Counted_Cache_Object
: public JAWS_Cache_Object
88 JAWS_Counted_Cache_Object (const void *, size_t);
89 virtual ~JAWS_Counted_Cache_Object ();
91 virtual ACE_Lock
& lock ();
94 virtual unsigned int count_i () const;
95 virtual int acquire_i ();
96 virtual int release_i ();
97 virtual unsigned int priority_i () const;
101 unsigned int new_count_
;
102 mutable ACE_SYNCH_MUTEX lock_
;
103 mutable ACE_Lock_Adapter
<ACE_SYNCH_MUTEX
> lock_adapter_
;
106 class JAWS_Cache_Object_Factory
109 JAWS_Cache_Object_Factory (ACE_Allocator
*alloc
= 0);
110 virtual ~JAWS_Cache_Object_Factory ();
112 int open (ACE_Allocator
*alloc
= 0);
114 virtual JAWS_Cache_Object
* create (const void *, size_t) = 0;
115 virtual void destroy (JAWS_Cache_Object
*) = 0;
118 ACE_Allocator
*allocator_
;
121 class JAWS_Referenced_Cache_Object_Factory
: public JAWS_Cache_Object_Factory
124 JAWS_Referenced_Cache_Object_Factory (ACE_Allocator
*alloc
= 0);
125 virtual ~JAWS_Referenced_Cache_Object_Factory ();
127 virtual JAWS_Cache_Object
* create (const void *, size_t);
128 virtual void destroy (JAWS_Cache_Object
*);
131 class JAWS_Counted_Cache_Object_Factory
: public JAWS_Cache_Object_Factory
134 JAWS_Counted_Cache_Object_Factory (ACE_Allocator
*alloc
= 0);
135 virtual ~JAWS_Counted_Cache_Object_Factory ();
137 virtual JAWS_Cache_Object
* create (const void *, size_t);
138 virtual void destroy (JAWS_Cache_Object
*);
141 #endif /* JAWS_CACHE_OBJECT_H */