MySQL 8.4.2
Source Code Documentation
simset.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2024, Oracle and/or its affiliates.
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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SIMSET_H
25#define SIMSET_H
26
27#include <stddef.h>
28#ifndef XCOM_STANDALONE
29#include "my_compiler.h"
30#endif
31#include "xcom/x_platform.h"
32
33struct linkage;
34typedef struct linkage linkage;
35
36struct linkage {
37 unsigned int type; /* Not strictly necessary, used for rudimentary run time
38 type check */
39 linkage *suc; /* Next in list */
40 linkage *pred; /* Previous in list */
41};
42
43extern char *dbg_linkage(linkage *self); /* Debug link */
44
45/* fwd decl */
46static inline linkage *link_out(linkage *self); /* Remove link from list */
47
48/* Forward iterator */
49#define FWD_ITER(head, type, action) \
50 { \
51 linkage *p = link_first(head); \
52 while (p != (head)) { \
53 linkage *_next = link_first(p); \
54 { \
55 type *link_iter = (type *)p; \
56 (void)link_iter; \
57 action; \
58 } /* Cast to void avoids unused variable warning */ \
59 p = _next; \
60 } \
61 }
62
63/* Reverse iterator */
64#define REV_ITER(head, type, action) \
65 { \
66 linkage *p = link_last(head); \
67 while (p != (head)) { \
68 linkage *_next = link_last(p); \
69 { \
70 type *link_iter = (type *)p; \
71 (void)link_iter; \
72 action; \
73 } /* Cast to void avoids unused variable warning */ \
74 p = _next; \
75 } \
76 }
77
78/* Get containing struct from pointer to member and type */
79#define container_of(ptr, type, member) \
80 ((type *)(((char *)(ptr)) - offsetof(type, member)))
81
82#define NULL_TYPE 0xdefaced
83
84#ifdef USE_LINK_SANITY_CHECK
85#define LINK_SANITY_CHECK(x) \
86 { \
87 assert((x)->suc); \
88 assert((x)->pred); \
89 }
90#define TYPE_SANITY_CHECK(x, y) \
91 { assert((x)->type == (y)->type); }
92#else
93#define LINK_SANITY_CHECK(x)
94#define TYPE_SANITY_CHECK(x, y)
95#endif
96
97#define link_into(self, s) link_precede(self, s)
98
99#define TYPE_HASH(x) 0
100
101/* purecov: begin deadcode */
102static inline linkage *link_first(linkage *self) { return self->suc; }
103
104static inline linkage *link_last(linkage *self) { return self->pred; }
105/* purecov: end */
106static inline linkage *link_extract_first(linkage *self) {
107 return link_out(self->suc);
108}
109
110static inline linkage *link_extract_last(linkage *self) {
111 return link_out(self->pred);
112}
113
114static inline int link_empty(linkage *self) { return self == self->suc; }
115
116static inline linkage *link_init(linkage *self, unsigned int type) {
117 /* XDBG("%s ",__func__); */
118 self->type = type;
119 self->suc = self->pred = self;
120 LINK_SANITY_CHECK(self);
121 return self;
122}
123
124static inline linkage *link_out(linkage *self) {
125 /* XDBG("%s ",__func__); */
126 if (!link_empty(self)) {
127 TYPE_SANITY_CHECK(self, self->suc);
128 TYPE_SANITY_CHECK(self, self->pred);
129 self->suc->pred = self->pred;
130 self->pred->suc = self->suc;
131 self->suc = self->pred = self;
132 }
133 LINK_SANITY_CHECK(self);
134 return self;
135}
136
137static inline void link_follow(linkage *self, linkage *ptr) {
138 /* XDBG("%s ",__func__); */
139 link_out(self);
140 if (ptr) {
141 TYPE_SANITY_CHECK(self, ptr);
143 self->pred = ptr;
144 self->suc = ptr->suc;
145 self->suc->pred = ptr->suc = self;
146 LINK_SANITY_CHECK(self);
147 }
148}
149
150static inline void link_precede(linkage *self, linkage *ptr) {
151 /* XDBG("%s ",__func__); */
152 link_out(self);
153 if (ptr) {
154 TYPE_SANITY_CHECK(self, ptr);
156 self->suc = ptr;
157 self->pred = ptr->pred;
158 self->pred->suc = ptr->pred = self;
159 LINK_SANITY_CHECK(self);
160 }
161}
162
163/* purecov: begin deadcode */
164static inline int cardinal(linkage *self) {
165 int n = 0;
166 FWD_ITER(self, linkage, n++);
167 return n;
168}
169/* purecov: end */
170
171#endif
Header for compiler-dependent features.
required string type
Definition: replication_group_member_actions.proto:34
#define FWD_ITER(head, type, action)
Definition: simset.h:49
static linkage * link_init(linkage *self, unsigned int type)
Definition: simset.h:116
#define LINK_SANITY_CHECK(x)
Definition: simset.h:93
static linkage * link_extract_last(linkage *self)
Definition: simset.h:110
static void link_precede(linkage *self, linkage *ptr)
Definition: simset.h:150
char * dbg_linkage(linkage *self)
Definition: simset.cc:35
#define TYPE_SANITY_CHECK(x, y)
Definition: simset.h:94
static linkage * link_last(linkage *self)
Definition: simset.h:104
static linkage * link_out(linkage *self)
Definition: simset.h:124
static linkage * link_first(linkage *self)
Definition: simset.h:102
static int cardinal(linkage *self)
Definition: simset.h:164
static linkage * link_extract_first(linkage *self)
Definition: simset.h:106
static void link_follow(linkage *self, linkage *ptr)
Definition: simset.h:137
static int link_empty(linkage *self)
Definition: simset.h:114
Definition: simset.h:36
linkage * pred
Definition: simset.h:40
unsigned int type
Definition: simset.h:37
linkage * suc
Definition: simset.h:39
int n
Definition: xcom_base.cc:509