MySQL  8.0.19
Source Code Documentation
simset.h
Go to the documentation of this file.
1 /* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
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, version 2.0, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef SIMSET_H
24 #define SIMSET_H
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <stddef.h>
31 #ifndef XCOM_STANDALONE
32 #include "my_compiler.h"
33 #endif
35 
36 struct linkage;
37 typedef struct linkage linkage;
38 
39 struct linkage {
40  unsigned int type; /* Not strictly necessary, used for rudimentary run time
41  type check */
42  linkage *suc; /* Next in list */
43  linkage *pred; /* Previous in list */
44 };
45 
46 /* extern int link_empty(linkage *self) ; */ /* True if list is empty */
47 extern linkage *link_first(linkage *self); /* First in list */
48 extern linkage *link_last(linkage *self); /* Last in list */
49 /*extern linkage *link_extract_first(linkage *self); */ /* Extract first from
50  list */
51 extern linkage *link_extract_last(linkage *self); /* Extract last from list */
52 extern linkage *link_init(linkage *self,
53  unsigned int type); /* Initialize a link */
54 extern linkage *link_out(linkage *self); /* Remove link from list */
55 extern void link_follow(linkage *self,
56  linkage *ptr); /* Insert self in list after ptr */
57 extern void link_precede(linkage *self,
58  linkage *ptr); /* Insert self in list before ptr */
59 /* extern void link_into(linkage *self, linkage *s); */ /* Insert self in list
60  before ptr */
61 extern char *dbg_linkage(linkage *self); /* Debug link */
62 extern unsigned int type_hash(
63  const char *byte); /* Hash character string to unsigned */
64 extern int cardinal(linkage *self);
65 
66 /* Forward iterator */
67 #define FWD_ITER(head, type, action) \
68  { \
69  linkage *p = link_first(head); \
70  while (p != (head)) { \
71  linkage *_next = link_first(p); \
72  { \
73  type *link_iter = (type *)p; \
74  (void)link_iter; \
75  action; \
76  } /* Cast to void avoids unused variable warning */ \
77  p = _next; \
78  } \
79  }
80 
81 /* Reverse iterator */
82 #define REV_ITER(head, type, action) \
83  { \
84  linkage *p = link_last(head); \
85  while (p != (head)) { \
86  linkage *_next = link_last(p); \
87  { \
88  type *link_iter = (type *)p; \
89  (void)link_iter; \
90  action; \
91  } /* Cast to void avoids unused variable warning */ \
92  p = _next; \
93  } \
94  }
95 
96 /* Get containing struct from pointer to member and type */
97 #define container_of(ptr, type, member) \
98  ((type *)(((char *)(ptr)) - offsetof(type, member)))
99 
100 #define NULL_TYPE 0xdefaced
101 
102 #if 0
103 #define LINK_SANITY_CHECK(x) \
104  { \
105  assert((x)->suc); \
106  assert((x)->pred); \
107  }
108 #define TYPE_SANITY_CHECK(x, y) \
109  { assert((x)->type == (y)->type); }
110 #else
111 #define LINK_SANITY_CHECK(x)
112 #define TYPE_SANITY_CHECK(x, y)
113 #endif
114 
115 #define link_into(self, s) link_precede(self, s)
116 #define link_extract_first(self) link_out((self)->suc)
117 #define link_empty(self) ((self) == (self)->suc)
118 
119 #if 0
120 static inline linkage *link_out(linkage *self)
121 {
122  /* XDBG("%s ",__func__); */
123  if (!link_empty(self)) {
124  TYPE_SANITY_CHECK(self, self->suc);
125  TYPE_SANITY_CHECK(self, self->pred);
126  self->suc->pred = self->pred;
127  self->pred->suc = self->suc;
128  self->suc = self->pred = self;
129  }
130  LINK_SANITY_CHECK(self);
131  return self;
132 }
133 
134 #endif
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif
link_follow
void link_follow(linkage *self, linkage *ptr)
Definition: simset.c:74
my_compiler.h
link_first
linkage * link_first(linkage *self)
Definition: simset.c:33
link_init
linkage * link_init(linkage *self, unsigned int type)
Definition: simset.c:53
self
static bool self
Definition: dlfcn.c:11
cardinal
int cardinal(linkage *self)
Definition: simset.c:108
dbg_linkage
char * dbg_linkage(linkage *self)
Definition: simset.c:114
LINK_SANITY_CHECK
#define LINK_SANITY_CHECK(x)
Definition: simset.h:111
linkage::type
unsigned int type
Definition: simset.h:40
link_out
linkage * link_out(linkage *self)
Definition: simset.c:61
link_extract_last
linkage * link_extract_last(linkage *self)
Definition: simset.c:44
x_platform.h
linkage
Definition: simset.h:39
link_last
linkage * link_last(linkage *self)
Definition: simset.c:35
link_precede
void link_precede(linkage *self, linkage *ptr)
Definition: simset.c:87
type_hash
unsigned int type_hash(const char *byte)
Definition: simset.c:141
HttpMethod::type
int type
Definition: http_common.h:411
TYPE_SANITY_CHECK
#define TYPE_SANITY_CHECK(x, y)
Definition: simset.h:112
linkage::pred
linkage * pred
Definition: simset.h:43
linkage::suc
linkage * suc
Definition: simset.h:42
link_empty
#define link_empty(self)
Definition: simset.h:117