From 48f5ecb709098a144375005c0c62c9ef5b18ae98 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Tue, 13 Nov 2018 17:39:22 +0100
Subject: [PATCH] Make the star formation task lock it's part of the tree.

---
 src/task.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/task.c b/src/task.c
index 9d4be3aaa5..6bc29730ed 100644
--- a/src/task.c
+++ b/src/task.c
@@ -380,6 +380,11 @@ void task_unlock(struct task *t) {
       cell_munlocktree(cj);
       break;
 
+    case task_type_star_formation:
+      cell_unlocktree(ci);
+      cell_sunlocktree(ci);
+      cell_gunlocktree(ci);
+
     default:
       break;
   }
@@ -518,6 +523,21 @@ int task_lock(struct task *t) {
         cell_munlocktree(ci);
         return 0;
       }
+      break;
+
+    case task_type_star_formation:
+      /* Lock the gas, gravity and star particles */
+      if (ci->hydro.hold || ci->stars.hold || ci->grav.phold) return 0;
+      if (cell_locktree(ci) != 0) return 0;
+      if (cell_slocktree(ci) != 0) {
+        cell_unlocktree(ci);
+        return 0;
+      }
+      if (cell_glocktree(ci) != 0) {
+        cell_unlocktree(ci);
+        cell_sunlocktree(ci);
+        return 0;
+      }
 
     default:
       break;
-- 
GitLab