Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
2bec36ad
Commit
2bec36ad
authored
Jun 23, 2013
by
Pedro Gonnet
Browse files
use sorted list instead of heap in queue.
Former-commit-id: 8514635880d23ec505f29539432181e72d5237eb
parent
3f04182c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/queue.c
View file @
2bec36ad
...
...
@@ -103,14 +103,19 @@ void queue_insert ( struct queue *q , struct task *t ) {
q
->
count
+=
1
;
/* Shuffle up. */
for
(
int
k
=
q
->
count
-
1
;
k
>
0
;
k
=
(
k
-
1
)
/
2
)
/*
for ( int k = q->count - 1 ; k > 0 ; k = (k-1)/2 )
if ( q->tasks[ q->tid[k] ].weight > q->tasks[ q->tid[(k-1)/2] ].weight ) {
int temp = q->tid[k];
q->tid[k] = q->tid[(k-1)/2];
q->tid[(k-1)/2] = temp;
}
else
break
;
break; */
for
(
int
k
=
q
->
count
-
1
;
k
>
0
&&
q
->
tasks
[
q
->
tid
[
k
-
1
]
].
weight
<
q
->
tasks
[
q
->
tid
[
k
]
].
weight
;
k
--
)
{
int
temp
=
q
->
tid
[
k
];
q
->
tid
[
k
]
=
q
->
tid
[
k
-
1
];
q
->
tid
[
k
-
1
]
=
temp
;
}
/* Verify queue consistency. */
/* for ( int k = 1 ; k < q->count ; k++ )
...
...
@@ -161,7 +166,7 @@ void queue_init ( struct queue *q , struct task *tasks ) {
struct
task
*
queue_gettask
(
struct
queue
*
q
,
int
qid
,
int
blocking
)
{
int
k
,
i
,
temp
,
qcount
,
*
qtid
,
type
;
int
k
,
temp
,
qcount
,
*
qtid
,
type
;
lock_type
*
qlock
=
&
q
->
lock
;
struct
task
*
qtasks
,
*
res
=
NULL
;
struct
cell
*
ci
,
*
cj
;
...
...
@@ -233,7 +238,7 @@ struct task *queue_gettask ( struct queue *q , int qid , int blocking ) {
cj
->
super
->
owner
=
qid
;
/* Swap this task with the last task and re-heap. */
if
(
k
<
qcount
)
{
/*
if ( k < qcount ) {
qtid[ k ] = qtid[ qcount ];
while ( qtasks[ qtid[k] ].weight > qtasks[ qtid[(k-1)/2] ].weight ) {
int temp = q->tid[k];
...
...
@@ -253,6 +258,13 @@ struct task *queue_gettask ( struct queue *q , int qid , int blocking ) {
else
break;
}
} */
qtid
[
k
]
=
qtid
[
qcount
];
while
(
k
<
qcount
-
1
&&
qtasks
[
qtid
[
k
+
1
]
].
weight
>
qtasks
[
qtid
[
k
]
].
weight
)
{
temp
=
qtid
[
k
];
qtid
[
k
]
=
qtid
[
k
+
1
];
qtid
[
k
+
1
]
=
temp
;
k
+=
1
;
}
/* Verify queue consistency. */
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment