From 4a4aa4592e7d44fac69a26f7c495fa373a8c6da5 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sat, 14 Jul 2018 22:37:36 +0200
Subject: [PATCH] Lock and unlock both cells when trying to run the gravity M-M
 task.

---
 src/task.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/task.c b/src/task.c
index fad903b3de..03566868a5 100644
--- a/src/task.c
+++ b/src/task.c
@@ -317,11 +317,15 @@ void task_unlock(struct task *t) {
       cell_munlocktree(ci);
       break;
 
-    case task_type_grav_mm:
     case task_type_grav_long_range:
       cell_munlocktree(ci);
       break;
 
+    case task_type_grav_mm:
+      cell_munlocktree(ci);
+      cell_munlocktree(cj);
+      break;
+
     default:
       break;
   }
@@ -444,12 +448,20 @@ int task_lock(struct task *t) {
       break;
 
     case task_type_grav_long_range:
-    case task_type_grav_mm:
       /* Lock the m-poles */
       if (ci->mhold) return 0;
       if (cell_mlocktree(ci) != 0) return 0;
       break;
 
+    case task_type_grav_mm:
+      /* Lock both m-poles */
+      if (ci->mhold || cj->mhold) return 0;
+      if (cell_mlocktree(ci) != 0) return 0;
+      if (cell_mlocktree(cj) != 0) {
+        cell_munlocktree(ci);
+        return 0;
+      }
+
     default:
       break;
   }
-- 
GitLab