Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Ordonnancement
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ASE-2021
Ordonnancement
Commits
14d1d975
Commit
14d1d975
authored
4 years ago
by
Thierno souleymane Bah
Browse files
Options
Downloads
Patches
Plain Diff
feat(create_ctx and yield done but ctx don't finish softly)
parent
d2da3691
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+5
-2
5 additions, 2 deletions
Makefile
pingpongpang.c
+48
-0
48 additions, 0 deletions
pingpongpang.c
try.c
+32
-2
32 additions, 2 deletions
try.c
try.h
+6
-1
6 additions, 1 deletion
try.h
with
91 additions
and
5 deletions
Makefile
+
5
−
2
View file @
14d1d975
OPTION
=
-m32
OPTION
=
-m32
all
:
display_stack try_mul pingpong
all
:
display_stack try_mul pingpong
pingpongpang
display_stack
:
display_stack.o
display_stack
:
display_stack.o
gcc
$(
OPTION
)
-o
$@
$^
gcc
$(
OPTION
)
-o
$@
$^
...
@@ -11,8 +11,11 @@ try_mul : try.o try_mul.o
...
@@ -11,8 +11,11 @@ try_mul : try.o try_mul.o
pingpong
:
try.o pingpong.o
pingpong
:
try.o pingpong.o
gcc
$(
OPTION
)
-o
$@
$^
gcc
$(
OPTION
)
-o
$@
$^
pingpongpang
:
try.o pingpongpang.o
gcc
$(
OPTION
)
-o
$@
$^
%.o
:
%.c
%.o
:
%.c
gcc
$(
OPTION
)
-c
$<
gcc
$(
OPTION
)
-c
$<
clean
:
clean
:
rm
-f
*
.o
*
.s display_stack try_mul pingpong
rm
-f
*
.o
*
.s display_stack try_mul pingpong
pingpongpang
This diff is collapsed.
Click to expand it.
pingpongpang.c
0 → 100644
+
48
−
0
View file @
14d1d975
#include
<stdio.h>
#include
<stdlib.h>
#include
"try.h"
#define STACK 16384
void
f_ping
(
void
*
args
);
void
f_pong
(
void
*
args
);
void
f_pang
(
void
*
args
);
int
main
(
int
argc
,
char
*
argv
[])
{
ctx_t
*
pang_ctx
=
create_ctx
(
STACK
,
f_pang
,
NULL
);
ctx_t
*
pong_ctx
=
create_ctx
(
STACK
,
f_pong
,
NULL
);
ctx_t
*
ping_ctx
=
create_ctx
(
STACK
,
f_ping
,
NULL
);
printf
(
"Begin
\n
"
);
yield
();
printf
(
"End
\n
"
);
exit
(
EXIT_SUCCESS
);
}
void
f_ping
(
void
*
args
)
{
printf
(
"A"
);
yield
();
printf
(
"B"
);
yield
();
printf
(
"C"
);
yield
();
}
void
f_pong
(
void
*
args
)
{
printf
(
"1"
);
yield
();
printf
(
"2"
);
yield
();
}
void
f_pang
(
void
*
args
)
{
printf
(
"("
);
yield
();
printf
(
":"
);
yield
();
printf
(
")"
);
yield
();
}
This diff is collapsed.
Click to expand it.
try.c
+
32
−
2
View file @
14d1d975
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
#include
<assert.h>
#include
<assert.h>
#include
"try.h"
#include
"try.h"
static
ctx_t
*
current_ctx
=
NULL
;
static
ctx_t
*
ring_ctx
=
NULL
;
int
try
(
ctx_t
*
pctx
,
func_t
*
f
,
int
arg
)
int
try
(
ctx_t
*
pctx
,
func_t
*
f
,
int
arg
)
{
{
asm
(
"movl %%esp, %0"
asm
(
"movl %%esp, %0"
...
@@ -38,7 +41,6 @@ int init_ctx(ctx_t *pctx, int stack_size, funct_t f, void *args)
...
@@ -38,7 +41,6 @@ int init_ctx(ctx_t *pctx, int stack_size, funct_t f, void *args)
pctx
->
status
=
CTX_INIT
;
pctx
->
status
=
CTX_INIT
;
}
}
static
ctx_t
*
current_ctx
=
NULL
;
void
switch_to_ctx
(
ctx_t
*
pctx
)
void
switch_to_ctx
(
ctx_t
*
pctx
)
{
{
assert
(
pctx
->
status
!=
CTX_END
);
assert
(
pctx
->
status
!=
CTX_END
);
...
@@ -67,5 +69,33 @@ void start_ctx()
...
@@ -67,5 +69,33 @@ void start_ctx()
current_ctx
->
status
=
CTX_EXEC
;
current_ctx
->
status
=
CTX_EXEC
;
current_ctx
->
f
(
current_ctx
->
args
);
current_ctx
->
f
(
current_ctx
->
args
);
current_ctx
->
status
=
CTX_END
;
current_ctx
->
status
=
CTX_END
;
free
(
current_ctx
->
stack
);
yield
();
}
ctx_t
*
create_ctx
(
int
stack_size
,
funct_t
f
,
void
*
args
)
{
ctx_t
*
new_ctx
=
malloc
(
sizeof
(
ctx_t
));
if
(
ring_ctx
==
NULL
)
{
new_ctx
->
next_ctx
=
new_ctx
;
ring_ctx
=
new_ctx
;
}
else
{
new_ctx
->
next_ctx
=
ring_ctx
->
next_ctx
;
ring_ctx
->
next_ctx
=
new_ctx
;
}
init_ctx
(
new_ctx
,
stack_size
,
f
,
args
);
return
new_ctx
;
}
void
yield
()
{
assert
(
ring_ctx
!=
NULL
||
current_ctx
!=
NULL
);
if
(
current_ctx
==
NULL
)
switch_to_ctx
(
ring_ctx
->
next_ctx
);
else
switch_to_ctx
(
current_ctx
->
next_ctx
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
try.h
+
6
−
1
View file @
14d1d975
...
@@ -11,7 +11,7 @@ typedef enum
...
@@ -11,7 +11,7 @@ typedef enum
CTX_END
CTX_END
}
ctx_status_t
;
}
ctx_status_t
;
typedef
struct
typedef
struct
ctx_s
{
{
void
*
esp
;
void
*
esp
;
void
*
ebp
;
void
*
ebp
;
...
@@ -19,6 +19,7 @@ typedef struct
...
@@ -19,6 +19,7 @@ typedef struct
funct_t
*
f
;
funct_t
*
f
;
void
*
args
;
void
*
args
;
ctx_status_t
status
;
ctx_status_t
status
;
struct
ctx_s
*
next_ctx
;
}
ctx_t
;
}
ctx_t
;
int
try
(
ctx_t
*
,
func_t
*
,
int
);
int
try
(
ctx_t
*
,
func_t
*
,
int
);
...
@@ -31,4 +32,8 @@ void switch_to_ctx(ctx_t *);
...
@@ -31,4 +32,8 @@ void switch_to_ctx(ctx_t *);
void
start_ctx
();
void
start_ctx
();
ctx_t
*
create_ctx
(
int
,
funct_t
,
void
*
);
void
yield
();
#endif // TRY
#endif // TRY
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment