]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Linux indentation on memory.[ch]
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 31 Mar 2017 14:37:23 +0000 (16:37 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 31 Mar 2017 15:59:48 +0000 (17:59 +0200)
The fact that I originally wrote this in Linux Kernel style and then
reindented it to GNU makes me want to gouge my eyes out every time I
look at it.  Restore original indentation.

[This patch is whitespace-only.]

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/memory.c
lib/memory.h

index 28e358dfc13e334cc8da40e6812eecbacd92ebc9..c6207adb981f1ef32f9ab233608cb51c0caaa358 100644 (file)
@@ -27,122 +27,107 @@ struct memgroup **mg_insert = &mg_first;
 DEFINE_MGROUP(LIB, "libfrr")
 DEFINE_MTYPE(LIB, TMP, "Temporary memory")
 
-static inline void
-mt_count_alloc (struct memtype *mt, size_t size)
+static inline void mt_count_alloc(struct memtype *mt, size_t size)
 {
-  size_t oldsize;
+       size_t oldsize;
 
-  atomic_fetch_add_explicit(&mt->n_alloc, 1, memory_order_relaxed);
+       atomic_fetch_add_explicit(&mt->n_alloc, 1, memory_order_relaxed);
 
-  oldsize = atomic_load_explicit(&mt->size, memory_order_relaxed);
-  if (oldsize == 0)
-    oldsize = atomic_exchange_explicit(&mt->size, size, memory_order_relaxed);
-  if (oldsize != 0 && oldsize != size && oldsize != SIZE_VAR)
-    atomic_store_explicit(&mt->size, SIZE_VAR, memory_order_relaxed);
+       oldsize = atomic_load_explicit(&mt->size, memory_order_relaxed);
+       if (oldsize == 0)
+               oldsize = atomic_exchange_explicit(&mt->size, size, memory_order_relaxed);
+       if (oldsize != 0 && oldsize != size && oldsize != SIZE_VAR)
+               atomic_store_explicit(&mt->size, SIZE_VAR, memory_order_relaxed);
 }
 
-static inline void
-mt_count_free (struct memtype *mt)
+static inline void mt_count_free(struct memtype *mt)
 {
-  assert(mt->n_alloc);
-  atomic_fetch_sub_explicit(&mt->n_alloc, 1, memory_order_relaxed);
+       assert(mt->n_alloc);
+       atomic_fetch_sub_explicit(&mt->n_alloc, 1, memory_order_relaxed);
 }
 
-static inline void *
-mt_checkalloc (struct memtype *mt, void *ptr, size_t size)
+static inline void *mt_checkalloc(struct memtype *mt, void *ptr, size_t size)
 {
-  if (__builtin_expect(ptr == NULL, 0))
-    {
-      memory_oom (size, mt->name);
-      return NULL;
-    }
-  mt_count_alloc (mt, size);
-  return ptr;
+       if (__builtin_expect(ptr == NULL, 0)) {
+               memory_oom(size, mt->name);
+               return NULL;
+       }
+       mt_count_alloc(mt, size);
+       return ptr;
 }
 
-void *
-qmalloc (struct memtype *mt, size_t size)
+void *qmalloc(struct memtype *mt, size_t size)
 {
-  return mt_checkalloc (mt, malloc (size), size);
+       return mt_checkalloc(mt, malloc(size), size);
 }
 
-void *
-qcalloc (struct memtype *mt, size_t size)
+void *qcalloc(struct memtype *mt, size_t size)
 {
-  return mt_checkalloc (mt, calloc (size, 1), size);
+       return mt_checkalloc(mt, calloc(size, 1), size);
 }
 
-void *
-qrealloc (struct memtype *mt, void *ptr, size_t size)
+void *qrealloc(struct memtype *mt, void *ptr, size_t size)
 {
-  if (ptr)
-    mt_count_free (mt);
-  return mt_checkalloc (mt, ptr ? realloc (ptr, size) : malloc (size), size);
+       if (ptr)
+               mt_count_free(mt);
+       return mt_checkalloc(mt, ptr ? realloc(ptr, size) : malloc(size), size);
 }
 
-void *
-qstrdup (struct memtype *mt, const char *str)
+void *qstrdup(struct memtype *mt, const char *str)
 {
-  return mt_checkalloc (mt, strdup (str), strlen (str) + 1);
+       return mt_checkalloc(mt, strdup(str), strlen(str) + 1);
 }
 
-void
-qfree (struct memtype *mt, void *ptr)
+void qfree(struct memtype *mt, void *ptr)
 {
-  if (ptr)
-    mt_count_free (mt);
-  free (ptr);
+       if (ptr)
+               mt_count_free(mt);
+       free(ptr);
 }
 
-int
-qmem_walk (qmem_walk_fn *func, void *arg)
+int qmem_walk(qmem_walk_fn *func, void *arg)
 {
-  struct memgroup *mg;
-  struct memtype *mt;
-  int rv;
-
-  for (mg = mg_first; mg; mg = mg->next)
-    {
-      if ((rv = func (arg, mg, NULL)))
-        return rv;
-      for (mt = mg->types; mt; mt = mt->next)
-        if ((rv = func (arg, mg, mt)))
-          return rv;
-    }
-  return 0;
+       struct memgroup *mg;
+       struct memtype *mt;
+       int rv;
+
+       for (mg = mg_first; mg; mg = mg->next) {
+               if ((rv = func(arg, mg, NULL)))
+                       return rv;
+               for (mt = mg->types; mt; mt = mt->next)
+                       if ((rv = func(arg, mg, mt)))
+                               return rv;
+       }
+       return 0;
 }
 
-struct exit_dump_args
-{
-  const char *prefix;
-  int error;
+struct exit_dump_args {
+       const char *prefix;
+       int error;
 };
 
-static int
-qmem_exit_walker (void *arg, struct memgroup *mg, struct memtype *mt)
+static int qmem_exit_walker(void *arg, struct memgroup *mg, struct memtype *mt)
 {
-  struct exit_dump_args *eda = arg;
-
-  if (!mt)
-    {
-      fprintf (stderr, "%s: showing active allocations in memory group %s\n",
-               eda->prefix, mg->name);
-    }
-  else if (mt->n_alloc)
-    {
-      char size[32];
-      eda->error++;
-      snprintf (size, sizeof (size), "%10zu", mt->size);
-      fprintf (stderr, "%s: memstats:  %-30s: %6zu * %s\n",
-               eda->prefix, mt->name, mt->n_alloc,
-               mt->size == SIZE_VAR ? "(variably sized)" : size);
-    }
-  return 0;
+       struct exit_dump_args *eda = arg;
+
+       if (!mt) {
+               fprintf(stderr, "%s: showing active allocations in "
+                               "memory group %s\n",
+                               eda->prefix, mg->name);
+
+       } else if (mt->n_alloc) {
+               char size[32];
+               eda->error++;
+               snprintf(size, sizeof(size), "%10zu", mt->size);
+               fprintf(stderr, "%s: memstats:  %-30s: %6zu * %s\n",
+                               eda->prefix, mt->name, mt->n_alloc,
+                               mt->size == SIZE_VAR ? "(variably sized)" : size);
+       }
+       return 0;
 }
 
-void
-log_memstats_stderr (const char *prefix)
+void log_memstats_stderr(const char *prefix)
 {
-  struct exit_dump_args eda = { .prefix = prefix, .error = 0 };
-  qmem_walk (qmem_exit_walker, &eda);
+       struct exit_dump_args eda = { .prefix = prefix, .error = 0 };
+       qmem_walk(qmem_exit_walker, &eda);
 }
index 284a1b13c514fcd7715c170ee23dd5a90f112302..9e8803a8b2a6dbc1881df66e050cfe83c2072c4a 100644 (file)
 #define array_size(ar) (sizeof(ar) / sizeof(ar[0]))
 
 #define SIZE_VAR ~0UL
-struct memtype
-{
-  struct memtype *next, **ref;
-  const char *name;
-  _Atomic size_t n_alloc;
-  _Atomic size_t size;
+struct memtype {
+       struct memtype *next, **ref;
+       const char *name;
+       _Atomic size_t n_alloc;
+       _Atomic size_t size;
 };
 
-struct memgroup
-{
-  struct memgroup *next, **ref;
-  struct memtype *types, **insert;
-  const char *name;
+struct memgroup {
+       struct memgroup *next, **ref;
+       struct memtype *types, **insert;
+       const char *name;
 };
 
 #if defined(__clang__)
@@ -83,14 +81,14 @@ struct memgroup
  *    DEFINE_MGROUP(MYDAEMON, "my daemon memory")
  *    DEFINE_MTYPE(MYDAEMON, MYDAEMON_COMMON,
  *                   "this mtype is used in multiple files in mydaemon")
- *    foo = qmalloc (MTYPE_MYDAEMON_COMMON, sizeof (*foo))
+ *    foo = qmalloc(MTYPE_MYDAEMON_COMMON, sizeof(*foo))
  *
  *  mydaemon_io.c
- *    bar = qmalloc (MTYPE_MYDAEMON_COMMON, sizeof (*bar))
+ *    bar = qmalloc(MTYPE_MYDAEMON_COMMON, sizeof(*bar))
  *
  *    DEFINE_MTYPE_STATIC(MYDAEMON, MYDAEMON_IO,
  *                          "this mtype is used only in this file")
- *    baz = qmalloc (MTYPE_MYDAEMON_IO, sizeof (*baz))
+ *    baz = qmalloc(MTYPE_MYDAEMON_IO, sizeof(*baz))
  *
  *  Note:  Naming conventions (MGROUP_ and MTYPE_ prefixes are enforced
  *         by not having these as part of the macro arguments)
@@ -156,15 +154,15 @@ DECLARE_MGROUP(LIB)
 DECLARE_MTYPE(TMP)
 
 
-extern void *qmalloc (struct memtype *mt, size_t size)
+extern void *qmalloc(struct memtype *mt, size_t size)
        __attribute__ ((malloc, _ALLOC_SIZE(2), nonnull (1) _RET_NONNULL));
-extern void *qcalloc (struct memtype *mt, size_t size)
+extern void *qcalloc(struct memtype *mt, size_t size)
        __attribute__ ((malloc, _ALLOC_SIZE(2), nonnull (1) _RET_NONNULL));
-extern void *qrealloc (struct memtype *mt, void *ptr, size_t size)
+extern void *qrealloc(struct memtype *mt, void *ptr, size_t size)
        __attribute__ ((_ALLOC_SIZE(3), nonnull (1) _RET_NONNULL));
 extern void *qstrdup (struct memtype *mt, const char *str)
        __attribute__ ((malloc, nonnull (1) _RET_NONNULL));
-extern void qfree (struct memtype *mt, void *ptr)
+extern void qfree(struct memtype *mt, void *ptr)
        __attribute__ ((nonnull (1)));
 
 #define XMALLOC(mtype, size)           qmalloc(mtype, size)
@@ -184,10 +182,10 @@ static inline size_t mtype_stats_alloc(struct memtype *mt)
  *
  * return value: 0: continue, !0: abort walk.  qmem_walk will return the
  * last value from qmem_walk_fn. */
-typedef int qmem_walk_fn (void *arg, struct memgroup *mg, struct memtype *mt);
-extern int qmem_walk (qmem_walk_fn *func, void *arg);
-extern void log_memstats_stderr (const char *);
+typedef int qmem_walk_fn(void *arg, struct memgroup *mg, struct memtype *mt);
+extern int qmem_walk(qmem_walk_fn *func, void *arg);
+extern void log_memstats_stderr(const char *);
 
-extern void memory_oom (size_t size, const char *name);
+extern void memory_oom(size_t size, const char *name);
 
 #endif /* _QUAGGA_MEMORY_H */