diff options
author | Mohit Agrawal <moagrawal@redhat.com> | 2018-12-19 08:14:44 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2018-12-20 16:44:26 +0000 |
commit | 0c7425d431b90c9c5c087511b34150e30dbe028a (patch) | |
tree | f334f8922ca58ac8d2cf5313398f7450e6397571 /rpc | |
parent | f2c2c906c0a81d24b14832974994604ea4569e0d (diff) |
rpc: Use adaptive mutex in rpcsvc_program_register
Adaptive mutexes are used to protect critical/shared data items that
are held for short periods.It provides a balance between spin locks
and traditional mutex.We have observed after use adaptive mutex in
rpcsvc_program_register got some improvement.
Change-Id: I7905744b32516ac4e4ca3c83c2e8e5e306093add
fixes: bz#1660701
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/rpc-lib/src/rpcsvc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index 273443d5619..dbb07be7fa2 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -2264,6 +2264,8 @@ rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, int ret = -1, i = 0; rpcsvc_program_t *newprog = NULL; char already_registered = 0; + pthread_mutexattr_t attr[EVENT_MAX_THREADS]; + pthread_mutexattr_t thr_attr; if (!svc) { goto out; @@ -2299,15 +2301,19 @@ rpcsvc_program_register(rpcsvc_t *svc, rpcsvc_program_t *program, memcpy(newprog, program, sizeof(*program)); INIT_LIST_HEAD(&newprog->program); + pthread_mutexattr_init(&thr_attr); + pthread_mutexattr_settype(&thr_attr, PTHREAD_MUTEX_ADAPTIVE_NP); for (i = 0; i < EVENT_MAX_THREADS; i++) { + pthread_mutexattr_init(&attr[i]); + pthread_mutexattr_settype(&attr[i], PTHREAD_MUTEX_ADAPTIVE_NP); INIT_LIST_HEAD(&newprog->request_queue[i].request_queue); - pthread_mutex_init(&newprog->request_queue[i].queue_lock, NULL); + pthread_mutex_init(&newprog->request_queue[i].queue_lock, &attr[i]); pthread_cond_init(&newprog->request_queue[i].queue_cond, NULL); newprog->request_queue[i].program = newprog; } - pthread_mutex_init(&newprog->thr_lock, NULL); + pthread_mutex_init(&newprog->thr_lock, &thr_attr); pthread_cond_init(&newprog->thr_cond, NULL); newprog->alive = _gf_true; |