context switching between two functions
This commit is contained in:
31
main.cc
31
main.cc
@@ -33,10 +33,6 @@ Ticketlock koutlock;
|
||||
// TextStream(0 ,0 ,0, 0,false),
|
||||
//};
|
||||
|
||||
Context test1;
|
||||
uint8_t test1_stack[256];
|
||||
Application application = Application(test1_stack);
|
||||
|
||||
|
||||
|
||||
TextStream dout[Core::MAX] = {
|
||||
@@ -74,17 +70,32 @@ OutputStream* copyout[Core::MAX]{
|
||||
|
||||
unsigned int testx, testy;
|
||||
|
||||
Context test1;
|
||||
uint8_t test1_stack[256];
|
||||
Thread test1_thread = Thread(&test1_stack[sizeof(test1_stack)-1]);
|
||||
//Application application = Application(test1_stack);
|
||||
|
||||
Context test2;
|
||||
uint8_t test2_stack[256];
|
||||
Thread test2_thread = Thread(&test2_stack[sizeof(test2_stack)-1]);
|
||||
|
||||
void test_func1(){
|
||||
while(1){
|
||||
DBG << "test 1\n";
|
||||
//context_switch(Context *next, Context *current);
|
||||
{
|
||||
Guarded g = Guard::enter();
|
||||
g.vault().kout << "test 1\n" << flush;
|
||||
}
|
||||
context_switch(&test2, &test1);
|
||||
}
|
||||
}
|
||||
|
||||
void test_func2(){
|
||||
while(1){
|
||||
DBG << "test 2\n";
|
||||
//context_switch(Context *next, Context *current);
|
||||
{
|
||||
Guarded g = Guard::enter();
|
||||
g.vault().kout << "test 2\n" << flush;
|
||||
}
|
||||
context_switch(&test1, &test2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +126,9 @@ extern "C" int main() {
|
||||
PS2Controller::drainBuffer();
|
||||
|
||||
DBG << "Main CPU " << static_cast<int>(LAPIC::getID()) << endl << flush;
|
||||
prepareContext(&test1_stack[sizeof(test1_stack)-1], test1, (void(*)(void*)) &(Application::kickoff),(Thread*)&application);
|
||||
|
||||
prepareContext(&test1_stack[sizeof(test1_stack)-1], test1, (void(*)(void*)) &(test_func1));
|
||||
prepareContext(&test2_stack[sizeof(test2_stack)-1], test2, (void(*)(void*)) &(test_func2));
|
||||
|
||||
context_launch(&test1);
|
||||
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
typedef void (*kickoff_t)(void*);
|
||||
|
||||
void Thread::kickoff(Thread* object) {
|
||||
//Guard::leave();
|
||||
object->action(); }
|
||||
|
||||
Thread::Thread(void* tos) {
|
||||
volatile bool kill_flag;
|
||||
Context context;
|
||||
Thread* queue_link;
|
||||
object->action();
|
||||
}
|
||||
|
||||
void Thread::resume(Thread* next) { (void)next; }
|
||||
Thread::Thread(void* tos) {
|
||||
}
|
||||
|
||||
void Thread::go() {}
|
||||
void Thread::resume(Thread* next) {
|
||||
|
||||
}
|
||||
|
||||
void Thread::go() {
|
||||
|
||||
}
|
||||
|
||||
void Thread::action() {}
|
||||
|
||||
@@ -36,9 +36,12 @@ class Thread {
|
||||
*
|
||||
* \param object Thread to be started
|
||||
*/
|
||||
/// \todo(14) Implement Method
|
||||
static void kickoff(Thread* object);
|
||||
|
||||
volatile bool kill_flag;
|
||||
Context context;
|
||||
Thread* queue_link;
|
||||
|
||||
public:
|
||||
/*! \brief Marker for a dying thread
|
||||
*/
|
||||
|
||||
@@ -35,17 +35,17 @@ void activeWaitDelay(uint64_t cycles) {
|
||||
void Application::action() { // NOLINT
|
||||
uint16_t cnt = 0;
|
||||
while (1) {
|
||||
//koutlock.lock();
|
||||
//koutlock.lock();
|
||||
{
|
||||
Guarded g = Guard::enter();
|
||||
//g.vault();
|
||||
g.vault().kout.setPos((unsigned)0,(unsigned)Core::getID()*2+1);
|
||||
|
||||
g.vault().kout << cnt++ << flush;
|
||||
|
||||
//g.vault().kout << endl << flush;
|
||||
//Guard::leave();
|
||||
//koutlock.unlock();
|
||||
Guarded g = Guard::enter();
|
||||
//g.vault();
|
||||
g.vault().kout.setPos((unsigned)0,(unsigned)Core::getID()*2+1);
|
||||
|
||||
g.vault().kout << cnt++ << flush;
|
||||
|
||||
//g.vault().kout << endl << flush;
|
||||
//Guard::leave();
|
||||
//koutlock.unlock();
|
||||
}
|
||||
Core::pause();
|
||||
//activeWaitDelay(1000000000);
|
||||
|
||||
Reference in New Issue
Block a user