Revert series of callout guard commits (#423)
* Revert "Fix callout stop deadlock"
This reverts commit 21943f41104efcd40e801d6542b110b5440b498d.
* Revert "Fix for missing timer wait wakeups"
This reverts commit faf6330b91d7e9768aa10f3f22484885a83e0f02.
* Revert "Fix for rescheduling a timer that is currently in progress."
This reverts commit d225e88dcafbbfc865c67589353c6a9ae3ce9bc8.
* Revert "Pull in missing guard for the currently executing callout (v2)"
This reverts commit 164ca603a26ebb870418fa5709f09bab9b61a3ab.
* Revert "Pull in missing guard for the currently executing callout"
This reverts commit a7c290275a0f8a164c132396b34f46e295c193f7.
diff --git a/usrsctplib/netinet/sctp_callout.c b/usrsctplib/netinet/sctp_callout.c
index a08d640..c6cffc7 100755
--- a/usrsctplib/netinet/sctp_callout.c
+++ b/usrsctplib/netinet/sctp_callout.c
@@ -77,27 +77,8 @@
* SCTP_TIMERQ_LOCK protects:
* - SCTP_BASE_INFO(callqueue)
* - sctp_os_timer_next: next timer to check
- * - sctp_os_timer_current: current callout callback in progress
- * - sctp_os_timer_current_tid: current callout thread id in progress
- * - sctp_os_timer_waiting: some thread is waiting for callout to complete
- * - sctp_os_timer_wait_ctr: incremented every time a thread wants to wait
- * for a callout to complete.
*/
static sctp_os_timer_t *sctp_os_timer_next = NULL;
-static sctp_os_timer_t *sctp_os_timer_current = NULL;
-static int sctp_os_timer_waiting = 0;
-static int sctp_os_timer_wait_ctr = 0;
-static userland_thread_id_t sctp_os_timer_current_tid;
-
-/*
- * SCTP_TIMERWAIT_LOCK (sctp_os_timerwait_mtx) protects:
- * - sctp_os_timer_wait_cond: waiting for callout to complete
- * - sctp_os_timer_done_ctr: value of "wait_ctr" after triggering "waiting"
- */
-userland_mutex_t sctp_os_timerwait_mtx;
-static userland_cond_t sctp_os_timer_wait_cond;
-static int sctp_os_timer_done_ctr = 0;
-
void
sctp_os_timer_init(sctp_os_timer_t *c)
@@ -115,21 +96,6 @@
SCTP_TIMERQ_LOCK();
/* check to see if we're rescheduling a timer */
- if (c == sctp_os_timer_current) {
- /*
- * We're being asked to reschedule a callout which is
- * currently in progress.
- */
- if (sctp_os_timer_waiting) {
- /*
- * This callout is already being stopped.
- * callout. Don't reschedule.
- */
- SCTP_TIMERQ_UNLOCK();
- return;
- }
- }
-
if (c->c_flags & SCTP_CALLOUT_PENDING) {
if (c == sctp_os_timer_next) {
sctp_os_timer_next = TAILQ_NEXT(c, tqe);
@@ -161,51 +127,13 @@
int
sctp_os_timer_stop(sctp_os_timer_t *c)
{
- int wakeup_cookie;
-
SCTP_TIMERQ_LOCK();
/*
* Don't attempt to delete a callout that's not on the queue.
*/
if (!(c->c_flags & SCTP_CALLOUT_PENDING)) {
c->c_flags &= ~SCTP_CALLOUT_ACTIVE;
- if (sctp_os_timer_current != c) {
- SCTP_TIMERQ_UNLOCK();
- return (0);
- } else {
- /*
- * Deleting the callout from the currently running
- * callout from the same thread, so just return
- */
- userland_thread_id_t tid;
- sctp_userspace_thread_id(&tid);
- if (sctp_userspace_thread_equal(tid,
- sctp_os_timer_current_tid)) {
- SCTP_TIMERQ_UNLOCK();
- return (0);
- }
-
- /* need to wait until the callout is finished */
- sctp_os_timer_waiting = 1;
- wakeup_cookie = ++sctp_os_timer_wait_ctr;
- SCTP_TIMERQ_UNLOCK();
- SCTP_TIMERWAIT_LOCK();
- /*
- * wait only if sctp_handle_tick didn't do a wakeup
- * in between the lock dance
- */
- if (wakeup_cookie - sctp_os_timer_done_ctr > 0) {
-#if defined (__Userspace_os_Windows)
- SleepConditionVariableCS(&sctp_os_timer_wait_cond,
- &sctp_os_timerwait_mtx,
- INFINITE);
-#else
- pthread_cond_wait(&sctp_os_timer_wait_cond,
- &sctp_os_timerwait_mtx);
-#endif
- }
- SCTP_TIMERWAIT_UNLOCK();
- }
+ SCTP_TIMERQ_UNLOCK();
return (0);
}
c->c_flags &= ~(SCTP_CALLOUT_ACTIVE | SCTP_CALLOUT_PENDING);
@@ -223,7 +151,6 @@
sctp_os_timer_t *c;
void (*c_func)(void *);
void *c_arg;
- int wakeup_cookie;
SCTP_TIMERQ_LOCK();
/* update our tick count */
@@ -236,26 +163,9 @@
c_func = c->c_func;
c_arg = c->c_arg;
c->c_flags &= ~SCTP_CALLOUT_PENDING;
- sctp_os_timer_current = c;
- sctp_userspace_thread_id(&sctp_os_timer_current_tid);
SCTP_TIMERQ_UNLOCK();
c_func(c_arg);
SCTP_TIMERQ_LOCK();
- sctp_os_timer_current = NULL;
- if (sctp_os_timer_waiting) {
- wakeup_cookie = sctp_os_timer_wait_ctr;
- SCTP_TIMERQ_UNLOCK();
- SCTP_TIMERWAIT_LOCK();
-#if defined (__Userspace_os_Windows)
- WakeAllConditionVariable(&sctp_os_timer_wait_cond);
-#else
- pthread_cond_broadcast(&sctp_os_timer_wait_cond);
-#endif
- sctp_os_timer_done_ctr = wakeup_cookie;
- SCTP_TIMERWAIT_UNLOCK();
- SCTP_TIMERQ_LOCK();
- sctp_os_timer_waiting = 0;
- }
c = sctp_os_timer_next;
} else {
c = TAILQ_NEXT(c, tqe);
@@ -310,14 +220,6 @@
*/
int rc;
-#if defined(__Userspace_os_Windows)
- InitializeConditionVariable(&sctp_os_timer_wait_cond);
-#else
- rc = pthread_cond_init(&sctp_os_timer_wait_cond, NULL);
- if (rc)
- SCTP_PRINTF("ERROR; return code from pthread_cond_init is %d\n", rc);
-#endif
-
rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(timer_thread), user_sctp_timer_iterate);
if (rc) {
SCTP_PRINTF("ERROR; return code from sctp_thread_create() is %d\n", rc);
diff --git a/usrsctplib/netinet/sctp_callout.h b/usrsctplib/netinet/sctp_callout.h
index 0f4dc6b..13279da 100755
--- a/usrsctplib/netinet/sctp_callout.h
+++ b/usrsctplib/netinet/sctp_callout.h
@@ -52,35 +52,22 @@
#define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
-extern userland_mutex_t sctp_os_timerwait_mtx;
-
#if defined(__Userspace__)
#if defined(__Userspace_os_Windows)
#define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx))
-
-#define SCTP_TIMERWAIT_LOCK() EnterCriticalSection(&sctp_os_timerwait_mtx)
-#define SCTP_TIMERWAIT_UNLOCK() LeaveCriticalSection(&sctp_os_timerwait_mtx)
-#define SCTP_TIMERWAIT_LOCK_INIT() InitializeCriticalSection(&sctp_os_timerwait_mtx)
-#define SCTP_TIMERWAIT_LOCK_DESTROY() DeleteCriticalSection(&sctp_os_timerwait_mtx)
#else
#ifdef INVARIANTS
#define SCTP_TIMERQ_LOCK() KASSERT(pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx already locked", __func__))
#define SCTP_TIMERQ_UNLOCK() KASSERT(pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx not locked", __func__))
-#define SCTP_TIMERWAIT_LOCK() KASSERT(pthread_mutex_lock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx already locked", __func__))
-#define SCTP_TIMERWAIT_UNLOCK() KASSERT(pthread_mutex_unlock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx not locked", __func__))
#else
#define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx))
-#define SCTP_TIMERWAIT_LOCK() (void)pthread_mutex_lock(&sctp_os_timerwait_mtx)
-#define SCTP_TIMERWAIT_UNLOCK() (void)pthread_mutex_unlock(&sctp_os_timerwait_mtx)
#endif
#define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), &SCTP_BASE_VAR(mtx_attr))
#define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx))
-#define SCTP_TIMERWAIT_LOCK_INIT() (void)pthread_mutex_init(&sctp_os_timerwait_mtx, &SCTP_BASE_VAR(mtx_attr))
-#define SCTP_TIMERWAIT_LOCK_DESTROY() (void)pthread_mutex_destroy(&sctp_os_timerwait_mtx)
#endif
#endif
diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h
index 9bc190d..f09cb8d 100755
--- a/usrsctplib/netinet/sctp_os_userspace.h
+++ b/usrsctplib/netinet/sctp_os_userspace.h
@@ -76,7 +76,6 @@
typedef CONDITION_VARIABLE userland_cond_t;
#endif
typedef HANDLE userland_thread_t;
-typedef DWORD userland_thread_id_t;
#define ADDRESS_FAMILY unsigned __int8
#define IPVERSION 4
#define MAXTTL 255
@@ -284,7 +283,6 @@
typedef pthread_mutex_t userland_mutex_t;
typedef pthread_cond_t userland_cond_t;
typedef pthread_t userland_thread_t;
-typedef pthread_t userland_thread_id_t;
#endif
#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
@@ -1037,9 +1035,6 @@
void
sctp_userspace_set_threadname(const char *name);
-int sctp_userspace_thread_id(userland_thread_id_t *thread);
-int sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2);
-
/*
* SCTP protocol specific mbuf flags.
*/
diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c
index 2220862..02779e5 100755
--- a/usrsctplib/netinet/sctp_pcb.c
+++ b/usrsctplib/netinet/sctp_pcb.c
@@ -6845,7 +6845,6 @@
#if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_)
/* allocate the lock for the callout/timer queue */
SCTP_TIMERQ_LOCK_INIT();
- SCTP_TIMERWAIT_LOCK_INIT();
TAILQ_INIT(&SCTP_BASE_INFO(callqueue));
#endif
#if defined(__Userspace__)
@@ -7041,7 +7040,6 @@
/* free the locks and mutexes */
#if defined(__APPLE__)
SCTP_TIMERQ_LOCK_DESTROY();
- SCTP_TIMERWAIT_LOCK_DESTROY();
#endif
#ifdef SCTP_PACKET_LOGGING
SCTP_IP_PKTLOG_DESTROY();
@@ -7068,7 +7066,6 @@
#endif
#if defined(__Userspace__)
SCTP_TIMERQ_LOCK_DESTROY();
- SCTP_TIMERWAIT_LOCK_DESTROY();
SCTP_ZONE_DESTROY(zone_mbuf);
SCTP_ZONE_DESTROY(zone_clust);
SCTP_ZONE_DESTROY(zone_ext_refcnt);
diff --git a/usrsctplib/netinet/sctp_userspace.c b/usrsctplib/netinet/sctp_userspace.c
index 7ff8a2d..28922b6 100755
--- a/usrsctplib/netinet/sctp_userspace.c
+++ b/usrsctplib/netinet/sctp_userspace.c
@@ -68,19 +68,6 @@
return 0;
}
-int
-sctp_userspace_thread_id(userland_thread_id_t *thread)
-{
- *thread = GetCurrentThreadId();
- return 0;
-}
-
-int
-sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2)
-{
- return (t1 == t2);
-}
-
#if defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif
@@ -91,19 +78,6 @@
{
return pthread_create(thread, NULL, start_routine, NULL);
}
-
-int
-sctp_userspace_thread_id(userland_thread_id_t *thread)
-{
- *thread = pthread_self();
- return 0;
-}
-
-int
-sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2)
-{
- return pthread_equal(t1, t2);
-}
#endif
void