Skip to content

Commit 057c1c4

Browse files
committed
Comments
1 parent 6ce5276 commit 057c1c4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

coroutine.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ static Polls polls = {0};
7575
// TODO: ARM support
7676
// Requires modifications in all the @arch places
7777

78+
typedef enum {
79+
SM_NONE = 0,
80+
SM_READ,
81+
SM_WRITE,
82+
} Sleep_Mode;
7883

7984
// Linux x86_64 call convention
8085
// %rdi, %rsi, %rdx, %rcx, %r8, and %r9
@@ -91,7 +96,7 @@ void __attribute__((naked)) coroutine_yield(void)
9196
" pushq %r14\n"
9297
" pushq %r15\n"
9398
" movq %rsp, %rdi\n" // rsp
94-
" movq $0, %rsi\n" // sm
99+
" movq $0, %rsi\n" // sm = SM_NONE
95100
" jmp coroutine_switch_context\n");
96101
}
97102

@@ -109,7 +114,7 @@ void __attribute__((naked)) coroutine_sleep_read(int fd)
109114
" pushq %r15\n"
110115
" movq %rdi, %rdx\n" // fd
111116
" movq %rsp, %rdi\n" // rsp
112-
" movq $1, %rsi\n" // sm
117+
" movq $1, %rsi\n" // sm = SM_READ
113118
" jmp coroutine_switch_context\n");
114119
}
115120

@@ -127,16 +132,10 @@ void __attribute__((naked)) coroutine_sleep_write(int fd)
127132
" pushq %r15\n"
128133
" movq %rdi, %rdx\n" // fd
129134
" movq %rsp, %rdi\n" // rsp
130-
" movq $2, %rsi\n" // sm
135+
" movq $2, %rsi\n" // sm = SM_WRITE
131136
" jmp coroutine_switch_context\n");
132137
}
133138

134-
typedef enum {
135-
SM_NONE = 0,
136-
SM_READ,
137-
SM_WRITE,
138-
} Sleep_Mode;
139-
140139
void __attribute__((naked)) coroutine_restore_context(void *rsp)
141140
{
142141
// @arch
@@ -215,7 +214,7 @@ void coroutine_finish(void)
215214
free(dead.items);
216215
free(polls.items);
217216
free(asleep.items);
218-
memset(&contexts, 0, sizeof(contexts));
217+
memset(&contexts, 0, sizeof(contexts));
219218
memset(&active, 0, sizeof(active));
220219
memset(&dead, 0, sizeof(dead));
221220
memset(&polls, 0, sizeof(polls));

0 commit comments

Comments
 (0)