Skip to content

Commit

Permalink
Cleanup svc_rqst_clean_idle()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Malahal Naineni committed Apr 22, 2019
1 parent 52bb2d5 commit a588e51
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/svc_rqst.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,24 +884,23 @@ static void
svc_rqst_clean_idle(int timeout)
{
struct svc_rqst_clean_arg acc;
static mutex_t active_mtx = MUTEX_INITIALIZER;
static uint32_t active;
static int32_t active;

if (mutex_trylock(&active_mtx) != 0)
return;

if (active > 0)
goto unlock;

++active;
/* Allow only one thread to do this work at any time. active
* starts with 0 and a thread that moves it from 0 to 1 is the
* only one that is allowed to do the work. Others just return
* without doing anything.
*/
if (atomic_postinc_int32_t(&active) != 0)
goto out;

#ifdef _HAVE_GSSAPI
/* trim gss context cache */
authgss_ctx_gc_idle();
#endif /* _HAVE_GSSAPI */

if (timeout <= 0)
goto unlock;
goto out;

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

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

unlock:
--active;
mutex_unlock(&active_mtx);
return;
out:
(void)atomic_postdec_int32_t(&active);
}

#ifdef TIRPC_EPOLL
Expand Down

0 comments on commit a588e51

Please sign in to comment.