]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Locking: Dropping DEFINE_DOMAIN ugly macro
authorMaria Matejka <mq@ucw.cz>
Mon, 20 Nov 2023 16:40:25 +0000 (17:40 +0100)
committerMaria Matejka <mq@ucw.cz>
Mon, 4 Dec 2023 09:39:32 +0000 (10:39 +0100)
lib/locking.h
lib/locking_test.c
lib/rcu.c
lib/route.h
nest/locks.c
nest/route.h
sysdep/unix/alloc.c
sysdep/unix/io-loop.c
sysdep/unix/io-loop.h
sysdep/unix/log.c

index 6cec2ff3e4620d67a0df9d2d7171f81b84c88e86..86cbf72d9a95e10e2c53d28439db838f0b8d95c4 100644 (file)
@@ -9,27 +9,37 @@
 #ifndef _BIRD_LOCKING_H_
 #define _BIRD_LOCKING_H_
 
+#include "lib/macro.h"
+
 struct domain_generic;
 struct pool;
 
+#define LOCK_ORDER \
+  the_bird, \
+  meta, \
+  control, \
+  proto, \
+  service, \
+  rtable, \
+  attrs, \
+  logging, \
+  resource, \
+
 /* Here define the global lock order; first to last. */
 struct lock_order {
-  struct domain_generic *the_bird;
-  struct domain_generic *meta;
-  struct domain_generic *control;
-  struct domain_generic *proto;
-  struct domain_generic *service;
-  struct domain_generic *rtable;
-  struct domain_generic *attrs;
-  struct domain_generic *logging;
-  struct domain_generic *resource;
+#define LOCK_ORDER_EXPAND(p)   struct domain_generic *p;
+  MACRO_FOREACH(LOCK_ORDER_EXPAND, LOCK_ORDER)
+#undef LOCK_ORDER_EXPAND
 };
 
+#define LOCK_ORDER_EXPAND(p)   struct domain__##p { struct domain_generic *p; };
+  MACRO_FOREACH(LOCK_ORDER_EXPAND, LOCK_ORDER)
+#undef LOCK_ORDER_EXPAND
+
 extern _Thread_local struct lock_order locking_stack;
 extern _Thread_local struct domain_generic **last_locked;
 
 #define DOMAIN(type) struct domain__##type
-#define DEFINE_DOMAIN(type) DOMAIN(type) { struct domain_generic *type; }
 #define DOMAIN_ORDER(type)  OFFSETOF(struct lock_order, type)
 
 #define DOMAIN_NEW(type)  (DOMAIN(type)) { .type = domain_new(DOMAIN_ORDER(type)) }
@@ -63,7 +73,6 @@ uint dg_order(struct domain_generic *dg);
 #define DG_UNLOCK(d)   do_unlock(d, DG_LSP(d))
 
 /* Use with care. To be removed in near future. */
-DEFINE_DOMAIN(the_bird);
 extern DOMAIN(the_bird) the_bird_domain;
 
 #define the_bird_lock()                LOCK_DOMAIN(the_bird, the_bird_domain)
@@ -273,4 +282,11 @@ extern DOMAIN(the_bird) the_bird_domain;
       _obj ? (_pobj->locked_at = NULL, LOBJ_UNLOCK_SIMPLE(_obj, _level), _obj) : NULL; \
       LOBJ_LOCK_SIMPLE(_obj, _level), _pobj->locked_at = (struct _stem##_private **) _lataux, _obj = NULL)
 
+/*
+ *  Get the locked object when the lock is already taken
+ */
+
+#define LOBJ_PRIV(_obj, _level) \
+  ({ ASSERT_DIE(DOMAIN_IS_LOCKED(_level, (_obj)->lock)); &(_obj)->priv; })
+
 #endif
index 0d99b1898180358a298efa4918c8f65b611da6f5..6c5de0cb8921cdff251765f1a5d1d71711fdcb01 100644 (file)
@@ -5,8 +5,6 @@
 #include <stdatomic.h>
 #include <pthread.h>
 
-DEFINE_DOMAIN(proto);
-
 #define FOO_PUBLIC \
   const char *name;    \
   _Atomic uint counter;        \
index 7ea6ec9b8aa53a440171a06ded069c83326e086c..c4b4721b1b3cc671dde4816c6412c3ab27910e9d 100644 (file)
--- a/lib/rcu.c
+++ b/lib/rcu.c
@@ -23,7 +23,6 @@ static list rcu_thread_list;
 
 static struct rcu_thread main_rcu_thread;
 
-DEFINE_DOMAIN(resource);
 static DOMAIN(resource) rcu_domain;
 
 static int
index a0446b391b02916238fcb14edfd9c4d1c1b29fd1..f7e9c7f7239661997c43946baffb347150945ef1 100644 (file)
@@ -89,7 +89,6 @@ struct rte_owner {
   event *stop;
 };
 
-DEFINE_DOMAIN(attrs);
 extern DOMAIN(attrs) attrs_domain;
 
 #define RTA_LOCK       LOCK_DOMAIN(attrs, attrs_domain)
index 66409c6db38be68fa8fb4bbcc6a89e25a08b620a..8036a1ef1c3032937e5289524f45115bde0d79a2 100644 (file)
@@ -38,7 +38,6 @@
 
 static list olock_list;
 
-DEFINE_DOMAIN(attrs);
 static DOMAIN(attrs) olock_domain;
 #define OBJ_LOCK       LOCK_DOMAIN(attrs, olock_domain)
 #define OBJ_UNLOCK     UNLOCK_DOMAIN(attrs, olock_domain)
index a3119c5b674ea7015d9c41e81285a7bd00ff4756..d6661afc5264eb5baf21fc688b0f1a45ff36edff 100644 (file)
@@ -98,18 +98,16 @@ struct rt_table_exporter {
 
 extern uint rtable_max_id;
 
-DEFINE_DOMAIN(rtable);
-
 /* The public part of rtable structure */
-#define RTABLE_PUBLIC                                                                          \
-  resource r;                                                                                  \
-  node n;                              /* Node in list of all tables */                        \
-  char *name;                          /* Name of this table */                                \
-  uint addr_type;                      /* Type of address data stored in table (NET_*) */      \
-  uint id;                             /* Integer table ID for fast lookup */                  \
-  DOMAIN(rtable) lock;                 /* Lock to take to access the private parts */          \
-  struct rtable_config *config;                /* Configuration of this table */                       \
-  struct birdloop *loop;               /* Service thread */                                    \
+#define RTABLE_PUBLIC \
+    resource r;                                                                                        \
+    node n;                            /* Node in list of all tables */                        \
+    char *name;                                /* Name of this table */                                \
+    uint addr_type;                    /* Type of address data stored in table (NET_*) */      \
+    uint id;                           /* Integer table ID for fast lookup */                  \
+    DOMAIN(rtable) lock;               /* Lock to take to access the private parts */          \
+    struct rtable_config *config;      /* Configuration of this table */                       \
+    struct birdloop *loop;             /* Service thread */                                    \
 
 /* The complete rtable structure */
 struct rtable_private {
@@ -167,7 +165,9 @@ struct rtable_private {
 
 /* The final union private-public rtable structure */
 typedef union rtable {
-  struct { RTABLE_PUBLIC; };
+  struct {
+    RTABLE_PUBLIC;
+  };
   struct rtable_private priv;
 } rtable;
 
index 56e755db2d4aacdcf039aeae977a36439d6e100d..341c02a2e589176c94bfdd181d14b7e3ebcbb15b 100644 (file)
@@ -120,7 +120,6 @@ long page_size = 0;
     void *pages[0];
   };
 
-  DEFINE_DOMAIN(resource);
   static DOMAIN(resource) empty_pages_domain;
   static struct empty_pages *empty_pages = NULL;
 
index 5213fdc036231dd3965948fb1d8c85bd4275d7c6..0a222ba029b9f4dec33116ce16e1e7df475678d7 100644 (file)
@@ -594,7 +594,6 @@ sockets_fire(struct birdloop *loop)
  *     Threads
  */
 
-DEFINE_DOMAIN(attrs);
 static void bird_thread_start_event(void *_data);
 
 struct birdloop_pickup_group {
index d1fb4ea89bfa19748b3823cbea102ed886f572b6..53d9f96b9378825cb4d2de08804468b461bd0dfe 100644 (file)
@@ -105,8 +105,6 @@ struct bird_thread
 };
 
 
-DEFINE_DOMAIN(control);
-
 struct bird_thread_syncer {
   pool *pool;
   DOMAIN(control) lock;
index 0d6adf428bbebc1a5eff393972402dcc0591c02c..41c8f07f7a014caccf72484a39ad94637d2e8026 100644 (file)
@@ -41,7 +41,6 @@ _Thread_local uint this_thread_id;
 
 #include <pthread.h>
 
-DEFINE_DOMAIN(logging);
 static DOMAIN(logging) log_domain;
 #define log_lock()  LOCK_DOMAIN(logging, log_domain);
 #define log_unlock()  UNLOCK_DOMAIN(logging, log_domain);