[DTrace-devel] [PATCH v2 1/4] port: delete useless mutex.h and mutex_* wrappers
Nick Alcock
nick.alcock at oracle.com
Wed Nov 1 15:31:03 UTC 2023
These wrappers are crude abstractions of the Solaris pre-pthreads mutex API
to POSIX threads. They are completely useless, complicate audits, and are
mostly unused: there is only one use of any of the pieces of other than
MUTEX_HELD(), and even MUTEX_HELD() has two code paths only one of which
can ever be executed. All uses of MUTEX_HELD are on pthread locks anyway,
not on the mutex_t wrappers (which are only a typedef for pthread locks
in any case).
Simplify things, drop mutex.h and all its uses, and move to using pthreads
locks everywhere (rather than only almost everywhere).
Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
include/mutex.h | 30 ------------------------------
include/port.h | 5 ++---
libdtrace/dt_pid.c | 1 -
libdtrace/dt_proc.c | 2 --
libport/time.c | 10 +---------
libproc/Pcontrol.c | 1 -
libproc/Psymtab.c | 8 ++++----
7 files changed, 7 insertions(+), 50 deletions(-)
delete mode 100644 include/mutex.h
diff --git a/include/mutex.h b/include/mutex.h
deleted file mode 100644
index 2ade826d29638..0000000000000
--- a/include/mutex.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-
-#ifndef MUTEX_H
-#define MUTEX_H
-#include <pthread.h>
-
-#define mutex_t pthread_mutex_t
-
-#define DEFAULTMUTEX PTHREAD_MUTEX_INITIALIZER
-
-#define mutex_lock(mp) pthread_mutex_lock(mp)
-#define mutex_unlock(mp) pthread_mutex_unlock(mp)
-#define mutex_destroy(x) pthread_mutex_destroy(x)
-
-#if defined(HAVE_SEMAPHORE_ATOMIC_COUNT)
-#define mutex_is_locked(x) (atomic_read(&(x)->__data.__count) == 0)
-#else
-#define mutex_is_locked(x) ((x)->__data.__count == 0)
-#endif
-
-#define MUTEX_HELD(x) mutex_is_locked(x)
-
-extern int mutex_init(mutex_t *, int, void *);
-
-#endif
diff --git a/include/port.h b/include/port.h
index 4b87f4adf91c3..b74a33a988f70 100644
--- a/include/port.h
+++ b/include/port.h
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -9,7 +9,6 @@
#define _PORT_H
#include <pthread.h>
-#include <mutex.h>
#include <unistd.h>
#include <sys/compiler.h>
#include <sys/types.h>
@@ -26,7 +25,7 @@ hrtime_t gethrtime(void);
int p_online(int cpun);
-int mutex_init(mutex_t *m, int flags1, void *ptr);
+#define MUTEX_HELD(x) ((x)->__data.__count == 0)
int daemonize(int close_fds);
diff --git a/libdtrace/dt_pid.c b/libdtrace/dt_pid.c
index b0689aa8a4955..70e0330f6f77b 100644
--- a/libdtrace/dt_pid.c
+++ b/libdtrace/dt_pid.c
@@ -17,7 +17,6 @@
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
-#include <mutex.h>
#include <port.h>
#include <uprobes.h>
diff --git a/libdtrace/dt_proc.c b/libdtrace/dt_proc.c
index a3298fdbc68f2..ed142c3bfd46f 100644
--- a/libdtrace/dt_proc.c
+++ b/libdtrace/dt_proc.c
@@ -82,8 +82,6 @@
#include <poll.h>
#include <setjmp.h>
-#include <mutex.h>
-
#include <libproc.h>
#include <dt_proc.h>
#include <dt_pid.h>
diff --git a/libport/time.c b/libport/time.c
index 120e7357f7325..97f19f04563f9 100644
--- a/libport/time.c
+++ b/libport/time.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -9,7 +9,6 @@
#include <sys/dtrace_types.h>
#include <time.h>
#include <pthread.h>
-#include <mutex.h>
hrtime_t
gethrtime(void)
@@ -28,10 +27,3 @@ gethrtime(void)
return v;
}
-
-int
-mutex_init(mutex_t *m, int flags1, void *ptr)
-{
- return pthread_mutex_init(m, NULL);
-}
-
diff --git a/libproc/Pcontrol.c b/libproc/Pcontrol.c
index 3d79b638d6196..0cc1692f3b489 100644
--- a/libproc/Pcontrol.c
+++ b/libproc/Pcontrol.c
@@ -31,7 +31,6 @@
#include <dt_debug.h>
-#include <mutex.h>
#include <platform.h>
#include <port.h>
diff --git a/libproc/Psymtab.c b/libproc/Psymtab.c
index a95161884c27a..9191a7ab82c20 100644
--- a/libproc/Psymtab.c
+++ b/libproc/Psymtab.c
@@ -26,7 +26,7 @@
#include <port.h>
#include <setjmp.h>
-#include <mutex.h>
+#include <pthread.h>
#include <rtld_db.h>
@@ -976,7 +976,7 @@ Pmap_mapfile_name(struct ps_prochandle *P, const prmap_t *mapp)
/*
* We wouldn't need these if qsort(3C) took an argument for the callback...
*/
-static mutex_t sort_mtx = DEFAULTMUTEX;
+static pthread_mutex_t sort_mtx = PTHREAD_MUTEX_INITIALIZER;
static char *sort_strs;
static GElf_Sym *sort_syms;
@@ -1175,7 +1175,7 @@ optimize_symtab(sym_tbl_t *symtab)
/*
* Sort the two tables according to the appropriate criteria.
*/
- mutex_lock(&sort_mtx);
+ pthread_mutex_lock(&sort_mtx);
sort_strs = symtab->sym_strs;
sort_syms = syms;
@@ -1184,7 +1184,7 @@ optimize_symtab(sym_tbl_t *symtab)
sort_strs = NULL;
sort_syms = NULL;
- mutex_unlock(&sort_mtx);
+ pthread_mutex_unlock(&sort_mtx);
free(syms);
}
--
2.42.0.271.g85384428f1
More information about the DTrace-devel
mailing list