Skip to content

Commit 6145f52

Browse files
committed
MINOR: proxy: use atomic ops for default proxy refcount
Default proxy refcount <def_ref> is used to comptabilize reference on a default proxy instance by standard proxies. Currently, this is necessary when a default proxy defines TCP/HTTP rules or a tcpcheck ruleset. Transform every access on <def_ref> so that atomic operations are now used. Currently, this is not strictly needed as default proxies references are only manipulated at init or deinit in single thread mode. However, when dynamic backends deletion will be implemented, <def_ref> will be decremented at runtime also.
1 parent f64aa03 commit 6145f52

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/proxy.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,7 @@ void defaults_px_destroy_all_unref(void)
30093009
for (px = cebis_item_first(&defproxy_by_name, conf.name_node, id, struct proxy); px; px = nx) {
30103010
BUG_ON(!(px->cap & PR_CAP_DEF));
30113011
nx = cebis_item_next(&defproxy_by_name, conf.name_node, id, px);
3012-
if (!px->conf.def_ref)
3012+
if (!HA_ATOMIC_LOAD(&px->conf.def_ref))
30133013
defaults_px_destroy(px);
30143014
}
30153015
}
@@ -3024,7 +3024,7 @@ void defaults_px_detach(struct proxy *px)
30243024
{
30253025
BUG_ON(!(px->cap & PR_CAP_DEF));
30263026
cebis_item_delete(&defproxy_by_name, conf.name_node, id, px);
3027-
if (!px->conf.def_ref)
3027+
if (!HA_ATOMIC_LOAD(&px->conf.def_ref))
30283028
defaults_px_destroy(px);
30293029
/* If not destroyed, <px> can still be accessed in <defaults_list>. */
30303030
}
@@ -3040,7 +3040,7 @@ void defaults_px_ref_all(void)
30403040
for (px = cebis_item_first(&defproxy_by_name, conf.name_node, id, struct proxy);
30413041
px;
30423042
px = cebis_item_next(&defproxy_by_name, conf.name_node, id, px)) {
3043-
++px->conf.def_ref;
3043+
HA_ATOMIC_INC(&px->conf.def_ref);
30443044
}
30453045
}
30463046

@@ -3057,7 +3057,7 @@ void defaults_px_unref_all(void)
30573057
nx = cebis_item_next(&defproxy_by_name, conf.name_node, id, px);
30583058

30593059
BUG_ON(!px->conf.def_ref);
3060-
if (!--px->conf.def_ref)
3060+
if (!HA_ATOMIC_SUB_FETCH(&px->conf.def_ref, 1))
30613061
defaults_px_destroy(px);
30623062
}
30633063
}
@@ -3066,8 +3066,7 @@ void defaults_px_unref_all(void)
30663066
* done if <px> already references <defpx>. Otherwise, the default proxy
30673067
* <def_ref> count is incremented by one.
30683068
*
3069-
* This operation is not thread safe. It must only be performed during init
3070-
* stage or under thread isolation.
3069+
* Access on default proxy reference is thread safe thanks to atomic ops.
30713070
*/
30723071
static inline void defaults_px_ref(struct proxy *defpx, struct proxy *px)
30733072
{
@@ -3077,7 +3076,7 @@ static inline void defaults_px_ref(struct proxy *defpx, struct proxy *px)
30773076
BUG_ON(px->defpx);
30783077

30793078
px->defpx = defpx;
3080-
defpx->conf.def_ref++;
3079+
HA_ATOMIC_INC(&defpx->conf.def_ref);
30813080
}
30823081

30833082
/* Check that <px> can inherits from <defpx> default proxy. If some settings
@@ -3178,14 +3177,15 @@ int proxy_ref_defaults(struct proxy *px, struct proxy *defpx, char **errmsg)
31783177

31793178
/* proxy <px> removes its reference on its default proxy. The default proxy
31803179
* <def_ref> count is decremented by one. If it was the last reference, the
3181-
* corresponding default proxy is destroyed. For now this operation is not
3182-
* thread safe and is performed during deinit staged only.
3183-
*/
3180+
* corresponding default proxy is destroyed.
3181+
*
3182+
* Access on default proxy reference is thread safe thanks to atomic ops.
3183+
*/
31843184
void proxy_unref_defaults(struct proxy *px)
31853185
{
31863186
if (px->defpx == NULL)
31873187
return;
3188-
if (!--px->defpx->conf.def_ref)
3188+
if (!HA_ATOMIC_SUB_FETCH(&px->defpx->conf.def_ref, 1))
31893189
defaults_px_destroy(px->defpx);
31903190
px->defpx = NULL;
31913191
}

0 commit comments

Comments
 (0)