00001 #ifndef _MAP_H_
00002 #define _MAP_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <linux/types.h>
00013
00014
00015 typedef struct {
00016 int64_t count;
00017 int64_t sum;
00018 int64_t min, max;
00019 int64_t histogram[BUCKETS];
00020 } stat;
00021
00022
00023 union key_data {
00024 long val;
00025 char *str;
00026 };
00027
00028
00029 enum keytype { NONE, LONG, STR } __attribute__ ((packed));
00030
00031 enum valtype { INT64, STAT, STRING, END };
00032
00033
00034
00035 struct map_node {
00036
00037 struct list_head lnode;
00038
00039 struct hlist_node hnode;
00040 union key_data key1;
00041 union key_data key2;
00042 enum keytype key1type;
00043 enum keytype key2type;
00044 };
00045
00046
00047 struct map_node_int64 {
00048 struct map_node n;
00049 int64_t val;
00050 };
00051
00052
00053 struct map_node_str {
00054 struct map_node n;
00055 char *str;
00056 };
00057
00058
00059 struct map_node_stat {
00060 struct map_node n;
00061 stat stats;
00062 };
00063
00064
00065
00066
00067 struct map_root {
00068
00069 enum valtype type;
00070
00071
00072 int maxnum;
00073
00074
00075 int num;
00076
00077
00078 int no_wrap;
00079
00080
00081 struct list_head head;
00082
00083
00084
00085 struct list_head pool;
00086
00087
00088 struct map_node *key;
00089
00090
00091
00092
00093 u_int8_t create;
00094 enum keytype c_key1type;
00095 enum keytype c_key2type;
00096 struct hlist_head *c_keyhead;
00097 union key_data c_key1;
00098 union key_data c_key2;
00099
00100
00101 struct hlist_head hashes[HASH_TABLE_SIZE];
00102
00103
00104 void *membuf;
00105 };
00106
00107
00108 typedef struct map_root *MAP;
00109
00110
00111 #define key1str(ptr) (ptr->n.key1.str)
00112
00113 #define key2str(ptr) (ptr->n.key2.str)
00114
00115 #define key1int(ptr) (ptr->n.key1.val)
00116
00117 #define key2int(ptr) (ptr->n.key2.val)
00118
00119
00120
00121
00122
00123 #define _stp_map_key2(map, key1, key2) \
00124 ({ \
00125 if (__builtin_types_compatible_p (typeof (key1), char[])) \
00126 if (__builtin_types_compatible_p (typeof (key2), char[])) \
00127 _stp_map_key_str_str (map, (char *)(key1), (char *)(key2)); \
00128 else \
00129 _stp_map_key_str_long (map, (char *)(key1), (long)(key2)); \
00130 else \
00131 if (__builtin_types_compatible_p (typeof (key2), char[])) \
00132 _stp_map_key_long_str (map, (long)(key1), (char *)(key2)); \
00133 else \
00134 _stp_map_key_long_long (map, (long)(key1), (long)(key2)); \
00135 })
00136
00137
00138
00139
00140
00141 #define _stp_map_key(map, key) \
00142 ({ \
00143 if (__builtin_types_compatible_p (typeof (key), char[])) \
00144 _stp_map_key_str (map, (char *)(key)); \
00145 else \
00146 _stp_map_key_long (map, (long)(key)); \
00147 })
00148
00149
00150
00151
00152
00153 #define _stp_map_set(map, val) \
00154 ({ \
00155 if (__builtin_types_compatible_p (typeof (val), char[])) \
00156 _stp_map_set_str (map, (char *)(val)); \
00157 else \
00158 _stp_map_set_int64 (map, (int64_t)(val)); \
00159 })
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 #define foreach(map, ptr) \
00170 for (ptr = (typeof(ptr))_stp_map_start(map); ptr; \
00171 ptr = (typeof(ptr))_stp_map_iter (map, (struct map_node *)ptr))
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 #define _stp_list_add(map, val) \
00182 ({ \
00183 if (__builtin_types_compatible_p (typeof (val), char[])) \
00184 _stp_list_add_str (map, (char *)(val)); \
00185 else \
00186 _stp_list_add_int64 (map, (int64_t)(val)); \
00187 })
00188
00189 #endif