MySQL  8.0.22
Source Code Documentation
simset.h
Go to the documentation of this file.
1 /* Copyright (c) 2012, 2020, 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 #include <stddef.h>
27 #ifndef XCOM_STANDALONE
28 #include "my_compiler.h"
29 #endif
30 #include "xcom/x_platform.h"
31 
32 struct linkage;
33 typedef struct linkage linkage;
34 
35 struct linkage {
36  unsigned int type; /* Not strictly necessary, used for rudimentary run time
37  type check */
38  linkage *suc; /* Next in list */
39  linkage *pred; /* Previous in list */
40 };
41 
42 extern char *dbg_linkage(linkage *self); /* Debug link */
43 
44 /* fwd decl */
45 static inline linkage *link_out(linkage *self); /* Remove link from list */
46 
47 /* Forward iterator */
48 #define FWD_ITER(head, type, action) \
49  { \
50  linkage *p = link_first(head); \
51  while (p != (head)) { \
52  linkage *_next = link_first(p); \
53  { \
54  type *link_iter = (type *)p; \
55  (void)link_iter; \
56  action; \
57  } /* Cast to void avoids unused variable warning */ \
58  p = _next; \
59  } \
60  }
61 
62 /* Reverse iterator */
63 #define REV_ITER(head, type, action) \
64  { \
65  linkage *p = link_last(head); \
66  while (p != (head)) { \
67  linkage *_next = link_last(p); \
68  { \
69  type *link_iter = (type *)p; \
70  (void)link_iter; \
71  action; \
72  } /* Cast to void avoids unused variable warning */ \
73  p = _next; \
74  } \
75  }
76 
77 /* Get containing struct from pointer to member and type */
78 #define container_of(ptr, type, member) \
79  ((type *)(((char *)(ptr)) - offsetof(type, member)))
80 
81 #define NULL_TYPE 0xdefaced
82 
83 #ifdef USE_LINK_SANITY_CHECK
84 #define LINK_SANITY_CHECK(x) \
85  { \
86  assert((x)->suc); \
87  assert((x)->pred); \
88  }
89 #define TYPE_SANITY_CHECK(x, y) \
90  { assert((x)->type == (y)->type); }
91 #else
92 #define LINK_SANITY_CHECK(x)
93 #define TYPE_SANITY_CHECK(x, y)
94 #endif
95 
96 #define link_into(self, s) link_precede(self, s)
97 
98 #define TYPE_HASH(x) 0
99 
100 /* purecov: begin deadcode */
101 static inline linkage *link_first(linkage *self) { return self->suc; }
102 
103 static inline linkage *link_last(linkage *self) { return self->pred; }
104 /* purecov: end */
105 static inline linkage *link_extract_first(linkage *self) {
106  return link_out(self->suc);
107 }
108 
109 static inline linkage *link_extract_last(linkage *self) {
110  return link_out(self->pred);
111 }
112 
113 static inline int link_empty(linkage *self) { return self == self->suc; }
114 
115 static inline linkage *link_init(linkage *self, unsigned int type) {
116  /* XDBG("%s ",__func__); */
117  self->type = type;
118  self->suc = self->pred = self;
119  LINK_SANITY_CHECK(self);
120  return self;
121 }
122 
123 static inline linkage *link_out(linkage *self) {
124  /* XDBG("%s ",__func__); */
125  if (!link_empty(self)) {
126  TYPE_SANITY_CHECK(self, self->suc);
127  TYPE_SANITY_CHECK(self, self->pred);
128  self->suc->pred = self->pred;
129  self->pred->suc = self->suc;
130  self->suc = self->pred = self;
131  }
132  LINK_SANITY_CHECK(self);
133  return self;
134 }
135 
136 static inline void link_follow(linkage *self, linkage *ptr) {
137  /* XDBG("%s ",__func__); */
138  link_out(self);
139  if (ptr) {
140  TYPE_SANITY_CHECK(self, ptr);
141  LINK_SANITY_CHECK(ptr);
142  self->pred = ptr;
143  self->suc = ptr->suc;
144  self->suc->pred = ptr->suc = self;
145  LINK_SANITY_CHECK(self);
146  }
147 }
148 
149 static inline void link_precede(linkage *self, linkage *ptr) {
150  /* XDBG("%s ",__func__); */
151  link_out(self);
152  if (ptr) {
153  TYPE_SANITY_CHECK(self, ptr);
154  LINK_SANITY_CHECK(ptr);
155  self->suc = ptr;
156  self->pred = ptr->pred;
157  self->pred->suc = ptr->pred = self;
158  LINK_SANITY_CHECK(self);
159  }
160 }
161 
162 /* purecov: begin deadcode */
163 static inline int cardinal(linkage *self) {
164  int n = 0;
165  FWD_ITER(self, linkage, n++);
166  return n;
167 }
168 /* purecov: end */
169 
170 #endif
static linkage * link_first(linkage *self)
Definition: simset.h:101
char * dbg_linkage(linkage *self)
Definition: simset.cc:31
#define LINK_SANITY_CHECK(x)
Definition: simset.h:92
linkage * suc
Definition: simset.h:38
#define FWD_ITER(head, type, action)
Definition: simset.h:48
linkage * pred
Definition: simset.h:39
static void link_follow(linkage *self, linkage *ptr)
Definition: simset.h:136
Definition: simset.h:35
Header for compiler-dependent features.
static int cardinal(linkage *self)
Definition: simset.h:163
unsigned int type
Definition: simset.h:36
static linkage * link_extract_last(linkage *self)
Definition: simset.h:109
static linkage * link_last(linkage *self)
Definition: simset.h:103
int n
Definition: xcom_base.cc:442
static linkage * link_extract_first(linkage *self)
Definition: simset.h:105
static int link_empty(linkage *self)
Definition: simset.h:113
#define TYPE_SANITY_CHECK(x, y)
Definition: simset.h:93
static linkage * link_init(linkage *self, unsigned int type)
Definition: simset.h:115
static linkage * link_out(linkage *self)
Definition: simset.h:123
static void link_precede(linkage *self, linkage *ptr)
Definition: simset.h:149
static bool self
Definition: dlfcn.c:11