projects
/
model-checker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
04cbde1
)
schedule: use STL list class instead of custom queue
author
Brian Norris
<banorris@uci.edu>
Thu, 15 Mar 2012 05:52:42 +0000
(22:52 -0700)
committer
Brian Norris
<banorris@uci.edu>
Thu, 15 Mar 2012 05:53:23 +0000
(22:53 -0700)
schedule.cc
patch
|
blob
|
history
schedule.h
patch
|
blob
|
history
diff --git
a/schedule.cc
b/schedule.cc
index 4f5f3de7d70ddf881e15ac6bd39cb27c795c728e..687d30612d2e2c3549caf4e922210885fad94941 100644
(file)
--- a/
schedule.cc
+++ b/
schedule.cc
@@
-5,67
+5,27
@@
#include "common.h"
#include "model.h"
#include "common.h"
#include "model.h"
-struct thread_list_node {
- struct thread *t;
- struct thread_list_node *next;
- int live;
-};
-
-#define NUM_LIST_NODES 32
-
-struct thread_list_node *head, *tail;
-struct thread_list_node nodes[NUM_LIST_NODES];
struct thread *current;
struct thread *current;
-
static void enqueue
_thread(struct thread *t)
+
void DefaultScheduler::add
_thread(struct thread *t)
{
{
- int i;
- struct thread_list_node *node;
-
- for (node = nodes, i = 0; node->live && i < NUM_LIST_NODES; i++, node++);
- if (i >= NUM_LIST_NODES) {
- printf("ran out of nodes\n");
- exit(1);
- }
- node->t = t;
- node->next = NULL;
- node->live = 1;
-
- if (tail)
- tail->next = node;
- else
- head = node;
- tail = node;
+ DEBUG("thread %d\n", t->id);
+ queue.push_back(t);
}
}
-st
atic struct thread *dequeue
_thread(void)
+st
ruct thread *DefaultScheduler::next
_thread(void)
{
{
- struct thread *
pop
;
+ struct thread *
t
;
- if (
!head
)
+ if (
queue.empty()
)
return NULL;
return NULL;
- pop = head->t;
- head->live = 0;
- if (head == tail)
- tail = NULL;
- head = head->next;
+ t = queue.front();
+ queue.pop_front();
- /* Set new current thread */
- current = pop;
+ current = t;
- return pop;
-}
-
-void DefaultScheduler::add_thread(struct thread *t)
-{
- DEBUG("thread %d\n", t->id);
- enqueue_thread(t);
-}
-
-struct thread *DefaultScheduler::next_thread(void)
-{
- return dequeue_thread();
+ return t;
}
struct thread *DefaultScheduler::get_current_thread(void)
}
struct thread *DefaultScheduler::get_current_thread(void)
diff --git
a/schedule.h
b/schedule.h
index eb0f68c74be5cdf101fca6f6c6166680c6f21d90..762e16818ed220dfc3a313a0b297638d7e9bfddd 100644
(file)
--- a/
schedule.h
+++ b/
schedule.h
@@
-1,6
+1,8
@@
#ifndef __SCHEDULE_H__
#define __SCHEDULE_H__
#ifndef __SCHEDULE_H__
#define __SCHEDULE_H__
+#include <list>
+
#include "libthreads.h"
#include "model.h"
#include "libthreads.h"
#include "model.h"
@@
-16,6
+18,8
@@
public:
void add_thread(struct thread *t);
struct thread * next_thread(void);
struct thread * get_current_thread(void);
void add_thread(struct thread *t);
struct thread * next_thread(void);
struct thread * get_current_thread(void);
+private:
+ std::list<struct thread *> queue;
};
#endif /* __SCHEDULE_H__ */
};
#endif /* __SCHEDULE_H__ */