Skip to contentSkip to conversation

master - dmeventd: minimize locking time for get_imeout

PATCH Zdenek Kabelac 1 participant 1 message Oct 22, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=15dbd4b56a65dba2f19bb1685529731faa9894c6
Commit:        15dbd4b56a65dba2f19bb1685529731faa9894c6
Parent:        e2ea2a81476495f494915774c46c0b3c139d1c3f
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Thu Oct 22 12:38:26 2015 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Thu Oct 22 22:34:30 2015 +0200

dmeventd: minimize locking time for get_imeout

Don't hold lock when creating message (allocating memory). Thread cannot dissapear as it's only the same thread which may clean it.

---
 daemons/dmeventd/dmeventd.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
daemons/dmeventd/dmeventd.c +9 -9
index 2f5fe67..26e611d 100644
@@ -1292,18 +1292,18 @@ static int _get_timeout(struct message_data *message_data)
 	struct thread_status *thread;
 	struct dm_event_daemon_message *msg = message_data->msg;
 
-	dm_free(msg->data);
-
 	_lock_mutex();
-	if ((thread = _lookup_thread_status(message_data))) {
-		msg->size = dm_asprintf(&(msg->data), "%s %" PRIu32,
-					message_data->id, thread->timeout);
-	} else
-		msg->data = NULL;
-
+	thread = _lookup_thread_status(message_data);
 	_unlock_mutex();
 
-	return thread ? 0 : -ENODEV;
+	if (!thread)
+		return -ENODEV;
+
+	dm_free(msg->data);
+	msg->size = dm_asprintf(&(msg->data), "%s %" PRIu32,
+				message_data->id, thread->timeout);
+
+	return (msg->data && msg->size) ? 0 : -ENOMEM;
 }
 
 /* Open fifos used for client communication. */