root/cherokee/trunk/cherokee/avl_r.c

Revision 1657, 2.4 kB (checked in by alo, 3 months ago)

--

Line 
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4  *
5  * Authors:
6  *      Alvaro Lopez Ortega <alvaro@alobbs.com>
7  *
8  * Copyright (C) 2001-2008 Alvaro Lopez Ortega
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22  * USA
23  */
24
25 #include "common-internal.h"
26 #include "avl_r.h"
27
28 typedef struct {
29         CHEROKEE_RWLOCK_T(lock);
30         int dummy;
31 } cherokee_avl_r_priv_t;
32
33 #define AVL_R_PRIV(avl_r) ((cherokee_avl_r_priv_t *)((avl_r)->priv))
34 #define AVL_R_LOCK(avl_r) (&AVL_R_PRIV(avl_r)->lock)
35
36
37 ret_t
38 cherokee_avl_r_init (cherokee_avl_r_t *avl_r)
39 {
40         ret_t ret;
41         CHEROKEE_NEW_STRUCT(n, avl_r_priv);
42
43         ret = cherokee_avl_init (&avl_r->avl);
44         if (ret != ret_ok)
45                 return ret;
46
47         avl_r->priv = n;
48         CHEROKEE_RWLOCK_INIT (AVL_R_LOCK(avl_r), NULL);
49
50         return ret_ok;
51 }
52
53
54 ret_t
55 cherokee_avl_r_mrproper (cherokee_avl_r_t *avl_r, cherokee_func_free_t free_func)
56 {
57         if (avl_r->priv) {
58                 CHEROKEE_RWLOCK_DESTROY (AVL_R_LOCK(avl_r));
59                 free (avl_r->priv);
60         }
61
62         return cherokee_avl_mrproper (&avl_r->avl, free_func);
63 }
64
65
66 ret_t
67 cherokee_avl_r_add (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void *value)
68 {
69         ret_t ret;
70
71         CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r));
72         ret = cherokee_avl_add (&avl_r->avl, key, value);
73         CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r));
74
75         return ret;
76 }
77
78
79 ret_t
80 cherokee_avl_r_del (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void **value)
81 {
82         ret_t ret;
83
84         CHEROKEE_RWLOCK_WRITER (AVL_R_LOCK(avl_r));
85         ret = cherokee_avl_del (&avl_r->avl, key, value);
86         CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r));
87
88         return ret;
89 }
90
91
92 ret_t
93 cherokee_avl_r_get (cherokee_avl_r_t *avl_r, cherokee_buffer_t *key, void **value)
94 {
95         ret_t ret;
96
97         CHEROKEE_RWLOCK_READER (AVL_R_LOCK(avl_r));
98         ret = cherokee_avl_get (&avl_r->avl, key, value);
99         CHEROKEE_RWLOCK_UNLOCK (AVL_R_LOCK(avl_r));
100
101         return ret;
102 }
Note: See TracBrowser for help on using the browser.