Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
kernel
Commits
2ccc13d2
Commit
2ccc13d2
authored
8 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of
https://github.com/redox-os/kernel
parents
9bddf55e
9ca3559c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
context/mod.rs
+11
-1
11 additions, 1 deletion
context/mod.rs
scheme/debug.rs
+4
-4
4 additions, 4 deletions
scheme/debug.rs
scheme/mod.rs
+9
-6
9 additions, 6 deletions
scheme/mod.rs
with
24 additions
and
11 deletions
context/mod.rs
+
11
−
1
View file @
2ccc13d2
...
...
@@ -26,6 +26,7 @@ pub struct ContextList {
}
impl
ContextList
{
/// Create a new context list.
pub
fn
new
()
->
Self
{
ContextList
{
map
:
BTreeMap
::
new
(),
...
...
@@ -33,14 +34,17 @@ impl ContextList {
}
}
/// Get the nth context.
pub
fn
get
(
&
self
,
id
:
usize
)
->
Option
<&
RwLock
<
Context
>>
{
self
.map
.get
(
&
id
)
}
/// Get the current context.
pub
fn
current
(
&
self
)
->
Option
<&
RwLock
<
Context
>>
{
self
.map
.get
(
&
CONTEXT_ID
.load
(
Ordering
::
SeqCst
))
}
/// Create a new context.
pub
fn
new_context
(
&
mut
self
)
->
Result
<&
RwLock
<
Context
>>
{
if
self
.next_id
>=
CONTEXT_MAX_CONTEXTS
{
self
.next_id
=
1
;
...
...
@@ -56,10 +60,13 @@ impl ContextList {
let
id
=
self
.next_id
;
self
.next_id
+=
1
;
assert!
(
self
.map
.insert
(
id
,
RwLock
::
new
(
Context
::
new
(
id
)))
.is_none
());
Ok
(
self
.map
.get
(
&
id
)
.expect
(
"failed to insert new context"
))
Ok
(
self
.map
.get
(
&
id
)
.expect
(
"Failed to insert new context. ID is out of bounds."
))
}
/// Spawn a context from a function.
pub
fn
spawn
(
&
mut
self
,
func
:
extern
fn
())
->
Result
<&
RwLock
<
Context
>>
{
let
context_lock
=
self
.new_context
()
?
;
{
...
...
@@ -109,6 +116,9 @@ pub fn contexts_mut() -> RwLockWriteGuard<'static, ContextList> {
}
/// Switch to the next context
///
/// # Safety
///
/// Do not call this while holding locks!
pub
unsafe
fn
switch
()
{
use
core
::
ops
::
DerefMut
;
...
...
This diff is collapsed.
Click to expand it.
scheme/debug.rs
+
4
−
4
View file @
2ccc13d2
use
core
::
str
;
use
syscall
::
Result
;
use
super
::
Scheme
;
use
super
::
{
Scheme
,
Fd
}
;
pub
struct
DebugScheme
;
...
...
@@ -14,21 +14,21 @@ impl Scheme for DebugScheme {
/// Read the file `number` into the `buffer`
///
/// Returns the number of bytes read
fn
read
(
&
mut
self
,
_file
:
usize
,
_buffer
:
&
mut
[
u8
])
->
Result
<
usize
>
{
fn
read
(
&
mut
self
,
_file
:
Fd
,
_buffer
:
&
mut
[
u8
])
->
Result
<
usize
>
{
Ok
(
0
)
}
/// Write the `buffer` to the `file`
///
/// Returns the number of bytes written
fn
write
(
&
mut
self
,
_file
:
usize
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
{
fn
write
(
&
mut
self
,
_file
:
Fd
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
{
//TODO: Write bytes, do not convert to str
print!
(
"{}"
,
unsafe
{
str
::
from_utf8_unchecked
(
buffer
)
});
Ok
(
buffer
.len
())
}
/// Close the file `number`
fn
close
(
&
mut
self
,
_file
:
usize
)
->
Result
<
()
>
{
fn
close
(
&
mut
self
,
_file
:
Fd
)
->
Result
<
()
>
{
Ok
(())
}
}
This diff is collapsed.
Click to expand it.
scheme/mod.rs
+
9
−
6
View file @
2ccc13d2
...
...
@@ -17,8 +17,11 @@ use syscall::Result;
use
self
::
debug
::
DebugScheme
;
pub
use
self
::
fd
::
Fd
;
/// Debug scheme
pub
mod
debug
;
mod
fd
;
/// Scheme list type
pub
type
SchemeList
=
BTreeMap
<
Box
<
[
u8
]
>
,
Arc
<
Mutex
<
Box
<
Scheme
+
Send
>>>>
;
...
...
@@ -50,16 +53,16 @@ pub trait Scheme {
/// Returns a file descriptor or an error
fn
open
(
&
mut
self
,
path
:
&
[
u8
],
flags
:
usize
)
->
Result
<
usize
>
;
/// Read
the file `number`
into the `buffer`
/// Read
from some file descriptor
into the `buffer`
///
/// Returns the number of bytes read
fn
read
(
&
mut
self
,
f
ile
:
usize
,
buffer
:
&
mut
[
u8
])
->
Result
<
usize
>
;
fn
read
(
&
mut
self
,
f
d
:
Fd
,
buffer
:
&
mut
[
u8
])
->
Result
<
usize
>
;
/// Write the `buffer` to the
`
file
`
/// Write the `buffer` to the file
descriptor
///
/// Returns the number of bytes written
fn
write
(
&
mut
self
,
f
ile
:
usize
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
;
fn
write
(
&
mut
self
,
f
d
:
Fd
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
;
/// Close the file
`number`
fn
close
(
&
mut
self
,
f
ile
:
usize
)
->
Result
<
()
>
;
/// Close the file
descriptor
fn
close
(
&
mut
self
,
f
d
:
Fd
)
->
Result
<
()
>
;
}
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