1 #include "JAWS/Cache_Object.h"
3 #include "ace/Malloc_Base.h"
4 #include "ace/Guard_T.h"
5 #include "ace/OS_NS_time.h"
7 JAWS_Cache_Object::JAWS_Cache_Object (const void *data
, size_t size
)
12 this->first_access_
= ACE_OS::time ((time_t *)0);
13 this->new_last_access_
= this->last_access_
= this->first_access_
;
16 JAWS_Cache_Object::~JAWS_Cache_Object ()
23 JAWS_Cache_Object::internal () const
25 return this->internal_
;
29 JAWS_Cache_Object::internal (void *item
)
31 this->internal_
= item
;
35 JAWS_Cache_Object::data () const
41 JAWS_Cache_Object::size () const
47 JAWS_Cache_Object::count () const
49 return this->count_i ();
53 JAWS_Cache_Object::acquire ()
55 this->new_last_access_
= ACE_OS::time ((time_t *)0);
56 return this->acquire_i ();
60 JAWS_Cache_Object::release ()
62 this->last_access_
= this->new_last_access_
;
63 return this->release_i ();
67 JAWS_Cache_Object::last_access () const
69 return this->last_access_
;
73 JAWS_Cache_Object::first_access () const
75 return this->first_access_
;
79 JAWS_Cache_Object::priority () const
81 return this->priority_i ();
85 JAWS_Cache_Object::heap_item () const
87 return this->heap_item_
;
91 JAWS_Cache_Object::heap_item (void *item
)
93 this->heap_item_
= item
;
97 JAWS_Referenced_Cache_Object::
98 JAWS_Referenced_Cache_Object (const void *data
, size_t size
)
99 : JAWS_Cache_Object (data
, size
),
100 lock_adapter_ (count_
)
104 JAWS_Referenced_Cache_Object::~JAWS_Referenced_Cache_Object ()
109 JAWS_Referenced_Cache_Object::lock ()
111 return this->lock_adapter_
;
115 JAWS_Referenced_Cache_Object::count_i () const
117 if (this->count_
.tryacquire_write () == 0)
124 JAWS_Referenced_Cache_Object::acquire_i ()
126 return this->count_
.acquire_read ();
130 JAWS_Referenced_Cache_Object::release_i ()
132 return this->count_
.release ();
136 JAWS_Referenced_Cache_Object::priority_i () const
138 unsigned int priority
= ~(0U);
140 = ACE_OS::difftime (this->last_access (), this->first_access ());
142 if (delta
>= 0.0 && delta
< ~(0U))
143 priority
= (unsigned) delta
;
149 JAWS_Counted_Cache_Object::
150 JAWS_Counted_Cache_Object (const void *data
, size_t size
)
151 : JAWS_Cache_Object (data
, size
),
154 lock_adapter_ (lock_
)
158 JAWS_Counted_Cache_Object::~JAWS_Counted_Cache_Object ()
163 JAWS_Counted_Cache_Object::lock ()
165 return this->lock_adapter_
;
169 JAWS_Counted_Cache_Object::count_i () const
171 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX
, g
,this->lock_
, 0);
177 JAWS_Counted_Cache_Object::acquire_i ()
179 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX
, g
,this->lock_
, 0);
186 JAWS_Counted_Cache_Object::release_i ()
188 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX
, g
,this->lock_
, 0);
191 this->count_
= this->new_count_
;
196 JAWS_Counted_Cache_Object::priority_i () const
198 return this->count_i ();
201 JAWS_Cache_Object_Factory::JAWS_Cache_Object_Factory (ACE_Allocator
*alloc
)
204 if (this->allocator_
== 0)
205 this->allocator_
= ACE_Allocator::instance ();
208 JAWS_Cache_Object_Factory::~JAWS_Cache_Object_Factory ()
213 JAWS_Cache_Object_Factory::open (ACE_Allocator
*alloc
)
215 this->allocator_
= alloc
;
217 if (this->allocator_
== 0)
218 this->allocator_
= ACE_Allocator::instance ();
223 JAWS_Referenced_Cache_Object_Factory
224 ::JAWS_Referenced_Cache_Object_Factory (ACE_Allocator
*alloc
)
225 : JAWS_Cache_Object_Factory (alloc
)
229 JAWS_Referenced_Cache_Object_Factory
230 ::~JAWS_Referenced_Cache_Object_Factory ()
235 JAWS_Referenced_Cache_Object_Factory::create (const void *data
, size_t size
)
237 JAWS_Referenced_Cache_Object
*obj
;
239 size_t obj_size
= sizeof (JAWS_Referenced_Cache_Object
);
240 ACE_NEW_MALLOC_RETURN (obj
,
241 (JAWS_Referenced_Cache_Object
*)
242 this->allocator_
->malloc (obj_size
),
243 JAWS_Referenced_Cache_Object (data
, size
), 0);
249 JAWS_Referenced_Cache_Object_Factory::destroy (JAWS_Cache_Object
*obj
)
251 JAWS_Referenced_Cache_Object
*rco
= (JAWS_Referenced_Cache_Object
*) obj
;
252 ACE_DES_FREE (rco
, this->allocator_
->free
, JAWS_Referenced_Cache_Object
);
255 JAWS_Counted_Cache_Object_Factory
256 ::JAWS_Counted_Cache_Object_Factory (ACE_Allocator
*alloc
)
257 : JAWS_Cache_Object_Factory (alloc
)
261 JAWS_Counted_Cache_Object_Factory
262 ::~JAWS_Counted_Cache_Object_Factory ()
267 JAWS_Counted_Cache_Object_Factory::create (const void *data
, size_t size
)
269 JAWS_Counted_Cache_Object
*obj
;
271 size_t obj_size
= sizeof (JAWS_Counted_Cache_Object
);
272 ACE_NEW_MALLOC_RETURN (obj
,
273 (JAWS_Counted_Cache_Object
*)
274 this->allocator_
->malloc (obj_size
),
275 JAWS_Counted_Cache_Object (data
, size
), 0);
281 JAWS_Counted_Cache_Object_Factory::destroy (JAWS_Cache_Object
*obj
)
283 JAWS_Counted_Cache_Object
*cco
= (JAWS_Counted_Cache_Object
*) obj
;
284 ACE_DES_FREE (cco
, this->allocator_
->free
, JAWS_Counted_Cache_Object
);