Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
my-kernel
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
my-kernel
Commits
5acd350c
Commit
5acd350c
authored
4 years ago
by
Thierno souleymane Bah
Browse files
Options
Downloads
Patches
Plain Diff
feat(semanphore implementation done)
parent
d1532c84
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/sem.h
+19
-0
19 additions, 0 deletions
include/sem.h
src/sem.c
+44
-0
44 additions, 0 deletions
src/sem.c
with
63 additions
and
0 deletions
include/sem.h
0 → 100644
+
19
−
0
View file @
5acd350c
#if !defined(SEM_H)
#define SEM_H
#include
"context.h"
#define SEM_MAGIC 0xCAFEBABE
typedef
struct
sem_s
{
int
cpt
;
ctx_t
*
first_ctx
;
int
magic
;
}
sem_t
;
int
sem_init
(
sem_t
*
sem
,
int
val
);
void
sem_up
(
sem_t
*
sem
);
void
sem_down
(
sem_t
*
sem
);
#endif
This diff is collapsed.
Click to expand it.
src/sem.c
0 → 100644
+
44
−
0
View file @
5acd350c
#include
"sem.h"
#include
"context.h"
#include
"utils.h"
extern
ctx_t
*
current_ctx
;
int
sem_init
(
sem_t
*
sem
,
int
val
)
{
assert
(
sem
->
magic
!=
SEM_MAGIC
);
sem
->
magic
=
SEM_MAGIC
;
sem
->
cpt
=
val
;
sem
->
first_ctx
=
NULL
;
return
0
;
}
void
sem_up
(
sem_t
*
sem
)
{
assert
(
sem
->
magic
==
SEM_MAGIC
);
irq_disable
();
if
((
++
sem
->
cpt
)
<=
0
)
{
sem
->
first_ctx
->
status
=
CTX_EXEC
;
sem
->
first_ctx
=
sem
->
first_ctx
->
sem_next_ctx
;
}
irq_enable
();
}
void
sem_down
(
sem_t
*
sem
)
{
assert
(
sem
->
magic
==
SEM_MAGIC
);
irq_disable
();
if
((
++
sem
->
cpt
)
<
0
)
{
current_ctx
->
status
=
CTX_WAIT
;
current_ctx
->
sem_next_ctx
=
sem
->
first_ctx
;
sem
->
first_ctx
=
current_ctx
;
yield
();
}
irq_enable
();
}
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