summaryrefslogtreecommitdiff
path: root/lib/tevent
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2014-07-30 09:56:54 -0700
committerKarolin Seeger <kseeger@samba.org>2014-08-07 16:43:09 +0200
commitf1cd12254405460bede46ab0e365c831f35e52b2 (patch)
tree9825929ec3a6e9e8fad63591a57e72189b868c11 /lib/tevent
parentc8eea31756d80688044b44e040454588f45f3c03 (diff)
downloadsamba-f1cd12254405460bede46ab0e365c831f35e52b2.tar.gz
lib: tevent: make TEVENT_SIG_INCREMENT atomic.
On arm platforms incrementing a variable is not an atomic operation, so may be interrupted by signal processing (if a signal interrupts another signal handler). Use compiler built-ins to make this atomic. __sync_fetch_and_add() works on gcc, llvm, IBM xlC on AIX, and Intel icc (10.1 and above). atomic_add_32() works on Oracle Solaris. Based on an inital patch from kamei@osstech.co.jp. Bug #10640 - smbd is not responding - tevent_common_signal_handler() increments non-atomic variables https://bugzilla.samba.org/show_bug.cgi?id=10640 Back-ported from master 536c799f00d7bdd6a574b6bdbc0e9c742eeef8b5 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <Volker.Lendecke@SerNet.DE>
Diffstat (limited to 'lib/tevent')
-rw-r--r--lib/tevent/tevent_signal.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c
index 0fdf646c8d..95a099d6ab 100644
--- a/lib/tevent/tevent_signal.c
+++ b/lib/tevent/tevent_signal.c
@@ -42,7 +42,13 @@ struct tevent_sigcounter {
uint32_t seen;
};
+#if defined(HAVE___SYNC_FETCH_AND_ADD)
+#define TEVENT_SIG_INCREMENT(s) __sync_fetch_and_add(&((s).count), 1)
+#elif defined(HAVE_ATOMIC_ADD_32)
+#define TEVENT_SIG_INCREMENT(s) atomic_add_32(&((s).count), 1)
+#else
#define TEVENT_SIG_INCREMENT(s) (s).count++
+#endif
#define TEVENT_SIG_SEEN(s, n) (s).seen += (n)
#define TEVENT_SIG_PENDING(s) ((s).seen != (s).count)