Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
taskscheduler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Schulcz Ferenc
taskscheduler
Commits
0ea98fa9
Commit
0ea98fa9
authored
Apr 4, 2018
by
sfphoton
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring, commenting
parent
08617608
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
src/Global.java
+1
-1
1 addition, 1 deletion
src/Global.java
src/Main.java
+1
-2
1 addition, 2 deletions
src/Main.java
src/RR.java
+14
-11
14 additions, 11 deletions
src/RR.java
src/SRTF.java
+4
-2
4 additions, 2 deletions
src/SRTF.java
with
20 additions
and
16 deletions
src/Global.java
+
1
−
1
View file @
0ea98fa9
...
@@ -21,7 +21,7 @@ public class Global {
...
@@ -21,7 +21,7 @@ public class Global {
public
void
tick
()
{
public
void
tick
()
{
if
(
srtf
.
isEmpty
()
&&
rr
.
isEmpty
())
{
Main
.
schedulersEmpty
=
true
;
return
;}
if
(
srtf
.
isEmpty
()
&&
rr
.
isEmpty
())
{
Main
.
schedulersEmpty
=
true
;
return
;}
else
if
(!
srtf
.
isEmpty
())
rr
.
stop
();
else
if
(!
srtf
.
isEmpty
())
rr
.
stop
();
//if there is a high priority task, we will choose that and not let the low priority scheduler work
srtf
.
tick
();
srtf
.
tick
();
rr
.
tick
();
rr
.
tick
();
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
1
−
2
View file @
0ea98fa9
...
@@ -63,10 +63,9 @@ public class Main {
...
@@ -63,10 +63,9 @@ public class Main {
scheduler
.
tick
();
scheduler
.
tick
();
}
}
//writing output
//writing output
//--------------
//--------------
System
.
out
.
println
(
scheduler
.
history
);
System
.
out
.
println
(
scheduler
.
history
);
System
.
out
.
print
(
runningTasks
.
get
(
0
).
name
+
":"
+
runningTasks
.
get
(
0
).
getWaitingTime
());
System
.
out
.
print
(
runningTasks
.
get
(
0
).
name
+
":"
+
runningTasks
.
get
(
0
).
getWaitingTime
());
...
...
This diff is collapsed.
Click to expand it.
src/RR.java
+
14
−
11
View file @
0ea98fa9
...
@@ -16,16 +16,28 @@ public class RR {
...
@@ -16,16 +16,28 @@ public class RR {
private
ArrayDeque
<
Task
>
waitingQueue
=
new
ArrayDeque
<>();
//inactive tasks
private
ArrayDeque
<
Task
>
waitingQueue
=
new
ArrayDeque
<>();
//inactive tasks
private
Task
activeTask
=
null
;
//the active task; null if there are none
private
Task
activeTask
=
null
;
//the active task; null if there are none
/**
* Constructor
* @param global the multilevel scheduler to which this one belongs
*/
public
RR
(
Global
global
)
{
public
RR
(
Global
global
)
{
this
.
global
=
global
;
this
.
global
=
global
;
}
}
/**
* Get back the right of scheduling tasks
*/
public
void
start
()
{
public
void
start
()
{
enabled
=
true
;
enabled
=
true
;
}
}
/**
* lose the right of scheduling tasks (e.g. because a higher priority task came in)
*/
public
void
stop
()
{
public
void
stop
()
{
enabled
=
false
;
enabled
=
false
;
//forcing the active task to sleep
runningFor
=
0
;
runningFor
=
0
;
if
(
activeTask
!=
null
)
waitingQueue
.
addLast
(
activeTask
);
if
(
activeTask
!=
null
)
waitingQueue
.
addLast
(
activeTask
);
activeTask
=
null
;
activeTask
=
null
;
...
@@ -39,8 +51,7 @@ public class RR {
...
@@ -39,8 +51,7 @@ public class RR {
* signals a processor tick
* signals a processor tick
*/
*/
public
void
tick
()
{
public
void
tick
()
{
if
(!
enabled
)
{
if
(!
enabled
)
{
//if not enabled, every task waits
//System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name));
if
(
activeTask
!=
null
)
activeTask
.
waitOne
();
if
(
activeTask
!=
null
)
activeTask
.
waitOne
();
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
return
;
return
;
...
@@ -59,9 +70,7 @@ public class RR {
...
@@ -59,9 +70,7 @@ public class RR {
runningFor
=
0
;
runningFor
=
0
;
}
}
if
(
runningFor
==
timeSlice
)
runningFor
=
0
;
if
(
runningFor
==
timeSlice
)
runningFor
=
0
;
//resetting runningFor even without swapping so that we will detect the next occasion when the time slice is over
//System.out.println("Running RR: " + ((activeTask == null) ? "null" : activeTask.name));
//registering time flow
//registering time flow
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
...
@@ -76,10 +85,4 @@ public class RR {
...
@@ -76,10 +85,4 @@ public class RR {
return
activeTask
==
null
&&
waitingQueue
.
size
()==
0
;
return
activeTask
==
null
&&
waitingQueue
.
size
()==
0
;
}
}
private
String
wqs
()
{
String
ret
=
""
;
for
(
Task
t
:
waitingQueue
)
ret
+=
t
.
name
;
return
ret
;
}
}
}
This diff is collapsed.
Click to expand it.
src/SRTF.java
+
4
−
2
View file @
0ea98fa9
...
@@ -12,6 +12,10 @@ public class SRTF {
...
@@ -12,6 +12,10 @@ public class SRTF {
private
boolean
needSwap
=
true
;
//stores if the active task should be changed
private
boolean
needSwap
=
true
;
//stores if the active task should be changed
/**
* constructor
* @param global the multilevel scheduler to which this one belongs
*/
public
SRTF
(
Global
global
)
{
public
SRTF
(
Global
global
)
{
this
.
global
=
global
;
this
.
global
=
global
;
}
}
...
@@ -45,8 +49,6 @@ public class SRTF {
...
@@ -45,8 +49,6 @@ public class SRTF {
needSwap
=
false
;
needSwap
=
false
;
}
}
//System.out.print("SRTF interrupt: " + activeTask.name + " ");
//registering time flowing
//registering time flowing
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
for
(
Task
t
:
waitingQueue
)
t
.
waitOne
();
activeTask
.
runOne
();
activeTask
.
runOne
();
...
...
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