Skip to content

Commit

Permalink
locks: remove unused conditional switch to spin_lock code (#2007)
Browse files Browse the repository at this point in the history
* locks: remove ununsed conditional switch to spin_lock code

use of spin_locks is depend on the variable use_spinlocks
but the same is commented in the current code base through
https://review.gluster.org/#/c/glusterfs/+/14763/. So it is
of no use to have conditional switching to spin_lock or
mutex. Removing the dead code as part of the patch

Fixes: #1996
Change-Id: Ib005dd86969ce33d3409164ef3e1011bb3169129
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>

* locks: remove unused conditional switch to spin_lock code

use of spin_locks is depend on the variable use_spinlocks
but the same is commented in the current code base through
https://review.gluster.org/#/c/glusterfs/+/14763/. So it is
of no use to have conditional switching to spin_lock or
mutex. Removing the dead code as part of the patch

Fixes: #1996
Change-Id: Ib005dd86969ce33d3409164ef3e1011bb3169129
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>

* locks: remove unused conditional switch to spin_lock code

use of spin_locks is depend on the variable use_spinlocks
but the same is commented in the current code base through
https://review.gluster.org/#/c/glusterfs/+/14763/. So it is
of no use to have conditional switching to spin_lock or
mutex. Removing the dead code as part of the patch

Fixes: #1996
Change-Id: Ib005dd86969ce33d3409164ef3e1011bb3169129
Signed-off-by: Vinayakswami Hariharmath <vharihar@redhat.com>
  • Loading branch information
vh05 committed Jan 19, 2021
1 parent 981fea1 commit 5b690a8
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 91 deletions.
7 changes: 0 additions & 7 deletions configure.ac
Expand Up @@ -639,13 +639,6 @@ AC_CHECK_HEADERS([linux/falloc.h])

AC_CHECK_HEADERS([linux/oom.h], AC_DEFINE(HAVE_LINUX_OOM_H, 1, [have linux/oom.h]))

dnl Mac OS X does not have spinlocks
AC_CHECK_FUNC([pthread_spin_init], [have_spinlock=yes])
if test "x${have_spinlock}" = "xyes"; then
AC_DEFINE(HAVE_SPINLOCK, 1, [define if found spinlock])
fi
AC_SUBST(HAVE_SPINLOCK)

dnl some os may not have GNU defined strnlen function
AC_CHECK_FUNC([strnlen], [have_strnlen=yes])
if test "x${have_strnlen}" = "xyes"; then
Expand Down
2 changes: 1 addition & 1 deletion libglusterfs/src/Makefile.am
Expand Up @@ -35,7 +35,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
strfd.c parse-utils.c $(CONTRIBDIR)/mount/mntent.c \
$(CONTRIBDIR)/libexecinfo/execinfo.c quota-common-utils.c rot-buffs.c \
$(CONTRIBDIR)/timer-wheel/timer-wheel.c \
$(CONTRIBDIR)/timer-wheel/find_last_bit.c default-args.c locking.c \
$(CONTRIBDIR)/timer-wheel/find_last_bit.c default-args.c \
$(CONTRIBDIR)/xxhash/xxhash.c \
throttle-tbf.c monitoring.c async.c

Expand Down
5 changes: 0 additions & 5 deletions libglusterfs/src/common-utils.c
Expand Up @@ -865,11 +865,6 @@ gf_dump_config_flags()
gf_msg_plain_nomem(GF_LOG_ALERT, "setfsid 1");
#endif

/* define if found spinlock */
#ifdef HAVE_SPINLOCK
gf_msg_plain_nomem(GF_LOG_ALERT, "spinlock 1");
#endif

/* Define to 1 if you have the <sys/epoll.h> header file. */
#ifdef HAVE_SYS_EPOLL_H
gf_msg_plain_nomem(GF_LOG_ALERT, "epoll.h 1");
Expand Down
51 changes: 0 additions & 51 deletions libglusterfs/src/glusterfs/locking.h
Expand Up @@ -22,55 +22,6 @@
#define pthread_spin_init(l, v) (*l = v)
#endif

#if defined(HAVE_SPINLOCK)

typedef union {
pthread_spinlock_t spinlock;
pthread_mutex_t mutex;
} gf_lock_t;

#if !defined(LOCKING_IMPL)
extern int use_spinlocks;

/*
* Using a dispatch table would be unpleasant because we're dealing with two
* different types. If the dispatch contains direct pointers to pthread_xx
* or mutex_xxx then we have to hope that every possible union alternative
* starts at the same address as the union itself. I'm old enough to remember
* compilers where this was not the case (for alignment reasons) so I'm a bit
* paranoid about that. Also, I don't like casting arguments through "void *"
* which we'd also have to do to avoid type errors. The other alternative would
* be to define actual functions which pick out the right union member, and put
* those in the dispatch tables. Now we have a pointer dereference through the
* dispatch table plus a function call, which is likely to be worse than the
* branching here from the ?: construct. If it were a clear win it might be
* worth the extra complexity, but for now this way seems preferable.
*/

#define LOCK_INIT(x) \
(use_spinlocks ? pthread_spin_init(&((x)->spinlock), 0) \
: pthread_mutex_init(&((x)->mutex), 0))

#define LOCK(x) \
(use_spinlocks ? pthread_spin_lock(&((x)->spinlock)) \
: pthread_mutex_lock(&((x)->mutex)))

#define TRY_LOCK(x) \
(use_spinlocks ? pthread_spin_trylock(&((x)->spinlock)) \
: pthread_mutex_trylock(&((x)->mutex)))

#define UNLOCK(x) \
(use_spinlocks ? pthread_spin_unlock(&((x)->spinlock)) \
: pthread_mutex_unlock(&((x)->mutex)))

#define LOCK_DESTROY(x) \
(use_spinlocks ? pthread_spin_destroy(&((x)->spinlock)) \
: pthread_mutex_destroy(&((x)->mutex)))

#endif

#else

typedef pthread_mutex_t gf_lock_t;

#define LOCK_INIT(x) pthread_mutex_init(x, 0)
Expand All @@ -79,6 +30,4 @@ typedef pthread_mutex_t gf_lock_t;
#define UNLOCK(x) pthread_mutex_unlock(x)
#define LOCK_DESTROY(x) pthread_mutex_destroy(x)

#endif /* HAVE_SPINLOCK */

#endif /* _LOCKING_H */
27 changes: 0 additions & 27 deletions libglusterfs/src/locking.c

This file was deleted.

0 comments on commit 5b690a8

Please sign in to comment.