blob: 9988379742f4ed228475d2fbb8908e4e313e33fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
// -*- C++ -*-
// $Id$
#ifndef JAWS_CACHE_OBJECT_H
#define JAWS_CACHE_OBJECT_H
#include "ace/Lock_Adapter_T.h"
#include "ace/Synch_Traits.h"
#include "ace/Thread_Mutex.h"
#include "ace/Malloc.h"
#include "ace/RW_Thread_Mutex.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_Allocator;
ACE_END_VERSIONED_NAMESPACE_DECL
// Cache bucket -- use Hash_Bucket to hold cacheable objects.
class JAWS_Cache_Object
{
public:
JAWS_Cache_Object (const void *, size_t);
virtual ~JAWS_Cache_Object (void);
void *internal (void) const;
void internal (void *);
const void *data (void) const;
size_t size (void) const;
unsigned int count (void) const;
int acquire (void);
int release (void);
time_t last_access (void) const;
time_t first_access (void) const;
unsigned int priority (void) const;
enum { ACE_CO_REFERENCED, ACE_CO_COUNTED };
void *heap_item (void) const;
void heap_item (void *item);
virtual ACE_Lock & lock (void) = 0;
protected:
virtual unsigned int count_i (void) const = 0;
virtual int acquire_i (void) = 0;
virtual int release_i (void) = 0;
virtual unsigned int priority_i (void) const = 0;
private:
void *internal_;
const void *data_;
size_t size_;
time_t last_access_;
time_t first_access_;
time_t new_last_access_;
void *heap_item_;
};
class JAWS_Referenced_Cache_Object : public JAWS_Cache_Object
{
public:
JAWS_Referenced_Cache_Object (const void *, size_t);
virtual ~JAWS_Referenced_Cache_Object (void);
virtual ACE_Lock & lock (void);
protected:
virtual unsigned int count_i (void) const;
virtual int acquire_i (void);
virtual int release_i (void);
virtual unsigned int priority_i (void) const;
private:
mutable ACE_SYNCH_RW_MUTEX count_;
mutable ACE_Lock_Adapter<ACE_SYNCH_RW_MUTEX> lock_adapter_;
};
class JAWS_Counted_Cache_Object : public JAWS_Cache_Object
{
public:
JAWS_Counted_Cache_Object (const void *, size_t);
virtual ~JAWS_Counted_Cache_Object (void);
virtual ACE_Lock & lock (void);
protected:
virtual unsigned int count_i (void) const;
virtual int acquire_i (void);
virtual int release_i (void);
virtual unsigned int priority_i (void) const;
private:
unsigned int count_;
unsigned int new_count_;
mutable ACE_SYNCH_MUTEX lock_;
mutable ACE_Lock_Adapter<ACE_SYNCH_MUTEX> lock_adapter_;
};
class JAWS_Cache_Object_Factory
{
public:
JAWS_Cache_Object_Factory (ACE_Allocator *alloc = 0);
virtual ~JAWS_Cache_Object_Factory (void);
int open (ACE_Allocator *alloc = 0);
virtual JAWS_Cache_Object * create (const void *, size_t) = 0;
virtual void destroy (JAWS_Cache_Object *) = 0;
protected:
ACE_Allocator *allocator_;
};
class JAWS_Referenced_Cache_Object_Factory : public JAWS_Cache_Object_Factory
{
public:
JAWS_Referenced_Cache_Object_Factory (ACE_Allocator *alloc = 0);
virtual ~JAWS_Referenced_Cache_Object_Factory (void);
virtual JAWS_Cache_Object * create (const void *, size_t);
virtual void destroy (JAWS_Cache_Object *);
};
class JAWS_Counted_Cache_Object_Factory : public JAWS_Cache_Object_Factory
{
public:
JAWS_Counted_Cache_Object_Factory (ACE_Allocator *alloc = 0);
virtual ~JAWS_Counted_Cache_Object_Factory (void);
virtual JAWS_Cache_Object * create (const void *, size_t);
virtual void destroy (JAWS_Cache_Object *);
};
#endif /* JAWS_CACHE_OBJECT_H */
|