From f74f7cc959d461dce9172ce8c09e0a483b298548 Mon Sep 17 00:00:00 2001
From: Bah Thierno-Souleymane <thiernosouleymane.bah.etu@univ-lille.fr>
Date: Tue, 20 Apr 2021 14:41:21 +0200
Subject: [PATCH] feat(switch_to_ctx function updated to take into account
 semanphore, CTX_WAIT status used)

---
 src/context.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/context.c b/src/context.c
index bf0d435..298e91f 100644
--- a/src/context.c
+++ b/src/context.c
@@ -42,20 +42,23 @@ int init_ctx(ctx_t *pctx, funct_t f, void *args)
 
 void switch_to_ctx(ctx_t *pctx)
 {
-    if (pctx->status == CTX_END)
+    if (pctx->status == CTX_END || pctx->status == CTX_WAIT)
     {
-        // Si c'est l'unique ctx
-        if (pctx == pctx->next_ctx)
-            ring_ctx = NULL;
-        else
-            current_ctx->next_ctx = pctx->next_ctx;
-
-        free_ctx(pctx);
+        if (pctx->status == CTX_END)
+        {
+            // Si c'est l'unique ctx
+            if (pctx == pctx->next_ctx)
+                ring_ctx = NULL;
+            else
+                current_ctx->next_ctx = pctx->next_ctx;
+
+            free_ctx(pctx);
+        }
         yield();
         return;
     }
 
-    assert(pctx->status != CTX_END);
+    assert(pctx->status != CTX_END && pctx->status != CTX_WAIT);
     if (current_ctx != NULL)
     {
         // Sauvegarder où on en est avec le ctx courant
-- 
GitLab