Skip to content

Commit a588e51

Browse files
author
Malahal Naineni
committed
Cleanup svc_rqst_clean_idle()
There is a mutex and a counter to allow only one thread at a time. There is no need for the 'active' counter as mutex guaranties that! Since other threads just bail out without waiting for the lock, we could simply use an atomic operation instead of a mutex here.
1 parent 52bb2d5 commit a588e51

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/svc_rqst.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -884,24 +884,23 @@ static void
884884
svc_rqst_clean_idle(int timeout)
885885
{
886886
struct svc_rqst_clean_arg acc;
887-
static mutex_t active_mtx = MUTEX_INITIALIZER;
888-
static uint32_t active;
887+
static int32_t active;
889888

890-
if (mutex_trylock(&active_mtx) != 0)
891-
return;
892-
893-
if (active > 0)
894-
goto unlock;
895-
896-
++active;
889+
/* Allow only one thread to do this work at any time. active
890+
* starts with 0 and a thread that moves it from 0 to 1 is the
891+
* only one that is allowed to do the work. Others just return
892+
* without doing anything.
893+
*/
894+
if (atomic_postinc_int32_t(&active) != 0)
895+
goto out;
897896

898897
#ifdef _HAVE_GSSAPI
899898
/* trim gss context cache */
900899
authgss_ctx_gc_idle();
901900
#endif /* _HAVE_GSSAPI */
902901

903902
if (timeout <= 0)
904-
goto unlock;
903+
goto out;
905904

906905
/* trim xprts (not sorted, not aggressive [but self limiting]) */
907906
(void)clock_gettime(CLOCK_MONOTONIC_FAST, &acc.ts);
@@ -910,10 +909,8 @@ svc_rqst_clean_idle(int timeout)
910909

911910
svc_xprt_foreach(svc_rqst_clean_func, (void *)&acc);
912911

913-
unlock:
914-
--active;
915-
mutex_unlock(&active_mtx);
916-
return;
912+
out:
913+
(void)atomic_postdec_int32_t(&active);
917914
}
918915

919916
#ifdef TIRPC_EPOLL

0 commit comments

Comments
 (0)