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