[stgt] [PATCH 02/12] Wrap the event list access list with a mutex

Chandra Seetharaman sekharan at us.ibm.com
Mon Sep 27 07:20:34 CEST 2010


Protect the global events list, tgt_events_list, with a mutex.

Signed-off-by: Chandra Seetharaman <sekharan at us.ibm.com>

---
 usr/tgtd.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Index: tgt-1.0.8.4/usr/tgtd.c
===================================================================
--- tgt-1.0.8.4.orig/usr/tgtd.c
+++ tgt-1.0.8.4/usr/tgtd.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <pthread.h>
 #include <sys/resource.h>
 #include <sys/epoll.h>
 
@@ -163,10 +164,15 @@ int do_tgt_event_add(int efd, struct lis
 	return err;
 }
 
+static pthread_mutex_t tgt_events_lock;
 int tgt_event_add(int fd, int events, event_handler_t handler, void *data)
 {
-	return do_tgt_event_add(ep_fd, &tgt_events_list, fd, events, handler,
+	int ret;
+	pthread_mutex_lock(&tgt_events_lock);
+	ret = do_tgt_event_add(ep_fd, &tgt_events_list, fd, events, handler,
 				data);
+	pthread_mutex_unlock(&tgt_events_lock);
+	return ret;
 }
 
 static struct event_data *tgt_event_lookup(struct list_head *list, int fd)
@@ -201,7 +207,9 @@ void do_tgt_event_del(int efd, struct li
 
 void tgt_event_del(int fd)
 {
+	pthread_mutex_lock(&tgt_events_lock);
 	do_tgt_event_del(ep_fd, &tgt_events_list, fd);
+	pthread_mutex_unlock(&tgt_events_lock);
 }
 
 int do_tgt_event_modify(int efd, struct list_head *list, int fd, int events)
@@ -224,7 +232,11 @@ int do_tgt_event_modify(int efd, struct 
 
 int tgt_event_modify(int fd, int events)
 {
-	return do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events);
+	int ret;
+	pthread_mutex_lock(&tgt_events_lock);
+	ret = do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events);
+	pthread_mutex_unlock(&tgt_events_lock);
+	return ret;
 }
 
 void tgt_init_sched_event(struct event_data *evt,
@@ -449,6 +461,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);
 
 	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