upload to RSA
[framework/system/libsf-common.git] / include / cpool.h
1 /*
2  *  libsf-common
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JuHyun Kim <jh8212.kim@samsung.com>
7  * 
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */ 
21
22
23
24
25 #if !defined(_CPOOL_CLASS_H_)
26 #define _CPOOL_CLASS_H_
27
28
29
30 class cpool : public cmutex
31 {
32 public:
33         static cpool *get_instance();
34         static cpool *current_instance();
35
36         bool put(char *name, void *data, void (*cb_del)(void *data) = NULL);
37         void *get(char *name);
38         bool del(char *name, bool remove = true);
39
40         void release_instance(void);
41
42 private:
43         cpool();
44         virtual ~cpool();
45
46         struct item_t : public clist {
47                 char *name;
48                 unsigned long name_hash;
49                 void *data;
50                 void (*cb_del)(void *data);
51         };
52
53         item_t *m_head;
54         item_t *m_tail;
55
56         static cpool *m_instance;
57         static int m_ref_count;
58         static cmutex m_ref_lock;
59
60         item_t *search_item(char *name);
61 };
62
63
64
65 #endif
66 //! End of a file