summaryrefslogtreecommitdiff
path: root/cache_8c.html
blob: 285c4ef545e7da2bce3bac48ff3028679721dbb2 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>memcached: cache.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>cache.c File Reference</h1><code>#include &lt;stdlib.h&gt;</code><br>
<code>#include &lt;string.h&gt;</code><br>
<code>#include &lt;inttypes.h&gt;</code><br>
<code>#include &lt;signal.h&gt;</code><br>
<code>#include &quot;<a class="el" href="cache_8h-source.html">cache.h</a>&quot;</code><br>

<p>
<div class="dynheader">
Include dependency graph for cache.c:</div>
<div class="dynsection">
<p><center><img src="cache_8c__incl.png" border="0" usemap="#cache.c_map" alt=""></center>
<map name="cache.c_map">
<area shape="rect" id="node11" href="cache_8h.html" title="cache.h" alt="" coords="403,83,477,112"></map>
</div>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="structcache__t.html">cache_t</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#631fa31e902ac58f80d0374ffed1d486">cache_create</a> (const char *name, size_t bufsize, size_t align, <a class="el" href="cache_8h.html#565b39d1034d5aaccafd0e996904eebc">cache_constructor_t</a> *constructor, <a class="el" href="cache_8h.html#7ac51941cc19301c6ce8b7c4a3d5dd9c">cache_destructor_t</a> *destructor)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Create an object cache.  <a href="#631fa31e902ac58f80d0374ffed1d486"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#81a74098387faa1e105aa3e9e1d60a5e">cache_destroy</a> (<a class="el" href="structcache__t.html">cache_t</a> *cache)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Destroy an object cache.  <a href="#81a74098387faa1e105aa3e9e1d60a5e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#6cc4f3f91247554c4961a0cb8acc298f">cache_alloc</a> (<a class="el" href="structcache__t.html">cache_t</a> *cache)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Allocate an object from the cache.  <a href="#6cc4f3f91247554c4961a0cb8acc298f"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#a1906b5ce5a39f760454519441f3e0b9">cache_free</a> (<a class="el" href="structcache__t.html">cache_t</a> *cache, void *ptr)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Return an object back to the cache.  <a href="#a1906b5ce5a39f760454519441f3e0b9"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Variables</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">const uint64_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#c8198db047750632f151394ed7bb6841">redzone_pattern</a> = 0xdeadbeefcafebabe</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#d4f8c8851cbc2284dc3af57ed3601b6b">cache_error</a> = 0</td></tr>

<tr><td class="memItemLeft" nowrap align="right" valign="top">const int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="cache_8c.html#6eb94ba2de80d22549df5b6f447e1166">initial_pool_size</a> = 64</td></tr>

</table>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="6cc4f3f91247554c4961a0cb8acc298f"></a><!-- doxytag: member="cache.c::cache_alloc" ref="6cc4f3f91247554c4961a0cb8acc298f" args="(cache_t *cache)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* cache_alloc           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structcache__t.html">cache_t</a> *&nbsp;</td>
          <td class="paramname"> <em>handle</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Allocate an object from the cache. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>the handle to the object cache to allocate from </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>a pointer to an initialized object from the cache, or NULL if the allocation cannot be satisfied. </dd></dl>

</div>
</div><p>
<a class="anchor" name="631fa31e902ac58f80d0374ffed1d486"></a><!-- doxytag: member="cache.c::cache_create" ref="631fa31e902ac58f80d0374ffed1d486" args="(const char *name, size_t bufsize, size_t align, cache_constructor_t *constructor, cache_destructor_t *destructor)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structcache__t.html">cache_t</a>* cache_create           </td>
          <td>(</td>
          <td class="paramtype">const char *&nbsp;</td>
          <td class="paramname"> <em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&nbsp;</td>
          <td class="paramname"> <em>bufsize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&nbsp;</td>
          <td class="paramname"> <em>align</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="cache_8h.html#565b39d1034d5aaccafd0e996904eebc">cache_constructor_t</a> *&nbsp;</td>
          <td class="paramname"> <em>constructor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="cache_8h.html#7ac51941cc19301c6ce8b7c4a3d5dd9c">cache_destructor_t</a> *&nbsp;</td>
          <td class="paramname"> <em>destructor</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Create an object cache. 
<p>
The object cache will let you allocate objects of the same size. It is fully MT safe, so you may allocate objects from multiple threads without having to do any syncrhonization in the application code.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>name</em>&nbsp;</td><td>the name of the object cache. This name may be used for debug purposes and may help you track down what kind of object you have problems with (buffer overruns, leakage etc) </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>bufsize</em>&nbsp;</td><td>the size of each object in the cache </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>align</em>&nbsp;</td><td>the alignment requirements of the objects in the cache. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>constructor</em>&nbsp;</td><td>the function to be called to initialize memory when we need to allocate more memory from the os. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>destructor</em>&nbsp;</td><td>the function to be called before we release the memory back to the os. </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>a handle to an object cache if successful, NULL otherwise. </dd></dl>

</div>
</div><p>
<a class="anchor" name="81a74098387faa1e105aa3e9e1d60a5e"></a><!-- doxytag: member="cache.c::cache_destroy" ref="81a74098387faa1e105aa3e9e1d60a5e" args="(cache_t *cache)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cache_destroy           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structcache__t.html">cache_t</a> *&nbsp;</td>
          <td class="paramname"> <em>handle</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Destroy an object cache. 
<p>
Destroy and invalidate an object cache. You should return all buffers allocated with cache_alloc by using cache_free before calling this function. Not doing so results in undefined behavior (the buffers may or may not be invalidated)<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>the handle to the object cache to destroy. </td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a1906b5ce5a39f760454519441f3e0b9"></a><!-- doxytag: member="cache.c::cache_free" ref="a1906b5ce5a39f760454519441f3e0b9" args="(cache_t *cache, void *ptr)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void cache_free           </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structcache__t.html">cache_t</a> *&nbsp;</td>
          <td class="paramname"> <em>handle</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&nbsp;</td>
          <td class="paramname"> <em>ptr</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Return an object back to the cache. 
<p>
The caller should return the object in an initialized state so that the object may be returned in an expected state from cache_alloc.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>handle</em>&nbsp;</td><td>handle to the object cache to return the object to </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>ptr</em>&nbsp;</td><td>pointer to the object to return. </td></tr>
  </table>
</dl>

</div>
</div><p>
<hr><h2>Variable Documentation</h2>
<a class="anchor" name="d4f8c8851cbc2284dc3af57ed3601b6b"></a><!-- doxytag: member="cache.c::cache_error" ref="d4f8c8851cbc2284dc3af57ed3601b6b" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int <a class="el" href="cache_8h.html#d4f8c8851cbc2284dc3af57ed3601b6b">cache_error</a> = 0          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="6eb94ba2de80d22549df5b6f447e1166"></a><!-- doxytag: member="cache.c::initial_pool_size" ref="6eb94ba2de80d22549df5b6f447e1166" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const int <a class="el" href="cache_8c.html#6eb94ba2de80d22549df5b6f447e1166">initial_pool_size</a> = 64          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
<a class="anchor" name="c8198db047750632f151394ed7bb6841"></a><!-- doxytag: member="cache.c::redzone_pattern" ref="c8198db047750632f151394ed7bb6841" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const uint64_t <a class="el" href="cache_8c.html#c8198db047750632f151394ed7bb6841">redzone_pattern</a> = 0xdeadbeefcafebabe          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>

</div>
</div><p>
</div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Apr 17 16:28:09 2009 for memcached by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>