summaryrefslogtreecommitdiff
path: root/Ports/citron/patches/0002-Make-fiber-a-noop.patch
blob: c76f6354e976fd518a127262c45a76c176ba4496 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
From 9dd73dc37156e39a03cbf4c2af0d754bf84882ab Mon Sep 17 00:00:00 2001
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
Date: Fri, 11 Feb 2022 16:32:42 +0330
Subject: [PATCH 2/9] Make fiber a noop

Serenity doesn't have ucontext.
---
 src/fiber.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/fiber.c b/src/fiber.c
index e8a99f1..23afae6 100644
--- a/src/fiber.c
+++ b/src/fiber.c
@@ -49,6 +49,7 @@ extern int waitForAllFibers();
 #endif
 /* <HEADER */
 
+#ifndef __serenity__
 #include <malloc.h>
 #include <ucontext.h>
 
@@ -76,21 +77,25 @@ static int numFibers = 0;
 
 // The "main" execution context
 static ucontext_t mainContext;
+#endif
 
 // Sets all the fibers to be initially inactive
 void initFibers()
 {
+#ifndef __serenity__
     int i;
     for (i = 0; i < MAX_FIBERS; ++i) {
         fiberList[i].active = 0;
     }
 
     return;
+#endif
 }
 
 // Switches from a fiber to main or from main to a fiber
 void fiberYield()
 {
+#ifndef __serenity__
     // If we are in a fiber, switch to the main process
     if (inFiber) {
         // Switch to the main context
@@ -129,6 +134,7 @@ void fiberYield()
             fiberList[numFibers].active = 0;
         }
     }
+#endif
     return;
 }
 
@@ -137,16 +143,21 @@ void fiberYield()
 // context of execution.
 static void fiberStart(ctr_object* block)
 {
+#ifndef __serenity__
     fiberList[currentFiber].active = 1;
     ctr_block_run_here(block, NULL, block);
     fiberList[currentFiber].active = 0;
 
     // Yield control, but because active == 0, this will free the fiber
     fiberYield();
+#endif
 }
 
 int spawnFiber(ctr_object* block)
 {
+#ifdef __serenity__
+    return 0;
+#else
     if (numFibers == MAX_FIBERS)
         return LF_MAXFIBERS;
 
@@ -171,10 +182,12 @@ int spawnFiber(ctr_object* block)
     ++numFibers;
 
     return LF_NOERROR;
+#endif
 }
 
 int waitForAllFibers()
 {
+#ifndef __serenity__
     int fibersRemaining = 0;
 
     // If we are in a fiber, wait for all the *other* fibers to quit
@@ -187,12 +200,14 @@ int waitForAllFibers()
     // Execute the fibers until they quit
     while (numFibers > fibersRemaining)
         fiberYield();
+#endif
 
     return LF_NOERROR;
 }
 
 int waitForFiber(int id)
 {
+#ifndef __serenity__
     int fibersRemaining = id;
 
     // If we are in a fiber, wait for all the *other* fibers to quit
@@ -205,15 +220,18 @@ int waitForFiber(int id)
     // Execute the fibers until they quit
     while (numFibers > fibersRemaining)
         fiberYield();
+#endif
 
     return LF_NOERROR;
 }
 
 int yieldNTimes(int n)
 {
+#ifndef __serenity__
     while (--n != 0) {
         fiberYield();
     }
+#endif
     return LF_NOERROR;
 }
 
@@ -258,7 +276,7 @@ ctr_object* ctr_fiber_spawn(ctr_object* myself, ctr_argument* argumentList)
     int fiber = spawnFiber(argumentList->object);
     ctr_internal_object_add_property(
         fiberObj, ctr_build_string_from_cstring("fiberId"),
-        ctr_build_number_from_float(numFibers), CTR_CATEGORY_PRIVATE_PROPERTY);
+        ctr_build_number_from_float(0), CTR_CATEGORY_PRIVATE_PROPERTY);
     return fiberObj;
 }
 
@@ -381,7 +399,7 @@ void ctr_fiber_begin_init()
         CtrStdFiber, ctr_build_string_from_cstring("unpack:"), &ctr_fiber_assign);
     ctr_internal_object_add_property(
         CtrStdFiber, ctr_build_string_from_cstring("fiberId"),
-        ctr_build_number_from_float(numFibers), CTR_CATEGORY_PRIVATE_PROPERTY);
+        ctr_build_number_from_float(0), CTR_CATEGORY_PRIVATE_PROPERTY);
     CtrStdFiber->info.sticky = 1;
 
     ctr_internal_object_add_property(
-- 
2.34.1