• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 Rockchip Electronics Co., LTD.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __RK_LIST_H__
19 #define __RK_LIST_H__
20 
21 #include <pthread.h>
22 #include "rk_type.h"
23 // desctructor of list node
24 typedef void *(*node_destructor)(void *);
25 
26 struct rk_list_node;
27 class rk_list {
28 public:
29     rk_list(node_destructor func);
30     ~rk_list();
31 
32     // for FIFO or FILO implement
33     // adding functions support simple structure like C struct or C++ class pointer,
34     // do not support C++ object
35     RK_S32 add_at_head(void *data, RK_S32 size);
36     RK_S32 add_at_tail(void *data, RK_S32 size);
37     // deleting function will copy the stored data to input pointer with size as size
38     // if NULL is passed to deleting functions, the node will be delete directly
39     RK_S32 del_at_head(void *data, RK_S32 size);
40     RK_S32 del_at_tail(void *data, RK_S32 size);
41 
42     // for status check
43     RK_S32 list_is_empty();
44     RK_S32 list_size();
45 
46     // for vector implement - not implemented yet
47     // adding function will return a key
48     RK_S32 add_by_key(void *data, RK_S32 size, RK_U32 *key);
49     RK_S32 del_by_key(void *data, RK_S32 size, RK_U32 key);
50     RK_S32 show_by_key(void *data, RK_U32 key);
51 
52     RK_S32 flush();
53 
54 private:
55     pthread_mutex_t         mutex;
56     node_destructor         destroy;
57     struct rk_list_node    *head;
58     RK_S32                 count;
59 
60     rk_list();
61     rk_list(const rk_list &);
62     rk_list &operator=(const rk_list &);
63 };
64 
65 #endif
66