[stgt] [PATCH 1/3] Change lock that protects tgt_events_list to rwlock
Chandra Seetharaman
sekharan at us.ibm.com
Fri Oct 15 06:58:11 CEST 2010
Convert the lock tgt_events_lock to a read write lock tgt_events_rwlock.
This will help with performance as there are more walk-thru the list
than the add/delete operations.
Signed-off-by: Chandra Seetharaman <sekharan at us.ibm.com>
---
usr/tgtd.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
Index: tgt-thread/usr/tgtd.c
===================================================================
--- tgt-thread.orig/usr/tgtd.c
+++ tgt-thread/usr/tgtd.c
@@ -167,14 +167,14 @@ int do_tgt_event_add(int efd, struct lis
return err;
}
-static pthread_mutex_t tgt_events_lock;
+static pthread_rwlock_t tgt_events_rwlock;
int tgt_event_add(int fd, int events, event_handler_t handler, void *data)
{
int ret;
- pthread_mutex_lock(&tgt_events_lock);
+ pthread_rwlock_wrlock(&tgt_events_rwlock);
ret = do_tgt_event_add(ep_fd, &tgt_events_list, fd, events, handler,
data);
- pthread_mutex_unlock(&tgt_events_lock);
+ pthread_rwlock_unlock(&tgt_events_rwlock);
return ret;
}
@@ -210,9 +210,9 @@ void do_tgt_event_del(int efd, struct li
void tgt_event_del(int fd)
{
- pthread_mutex_lock(&tgt_events_lock);
+ pthread_rwlock_wrlock(&tgt_events_rwlock);
do_tgt_event_del(ep_fd, &tgt_events_list, fd);
- pthread_mutex_unlock(&tgt_events_lock);
+ pthread_rwlock_unlock(&tgt_events_rwlock);
}
int do_tgt_event_modify(int efd, struct list_head *list, int fd, int events)
@@ -236,9 +236,9 @@ int do_tgt_event_modify(int efd, struct
int tgt_event_modify(int fd, int events)
{
int ret;
- pthread_mutex_lock(&tgt_events_lock);
+ pthread_rwlock_rdlock(&tgt_events_rwlock);
ret = do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events);
- pthread_mutex_unlock(&tgt_events_lock);
+ pthread_rwlock_unlock(&tgt_events_rwlock);
return ret;
}
@@ -469,7 +469,7 @@ int main(int argc, char **argv)
sigaction(SIGINT, &sa_new, &sa_old);
sigaction(SIGPIPE, &sa_new, &sa_old);
sigaction(SIGTERM, &sa_new, &sa_old);
- pthread_mutex_init(&tgt_events_lock, NULL);
+ pthread_rwlock_init(&tgt_events_rwlock, NULL);
pagesize = sysconf(_SC_PAGESIZE);
for (pageshift = 0;; pageshift++)
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list