From e9b4f9a9f117e29ba47eebdc1241d44e7e880d64 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Sun, 8 Mar 2009 00:03:13 +0100 Subject: [PATCH] improving actors systems, environment class interface --- actors/actor.cpp | 5 ++++- actors/actor.h | 12 ++++++++---- actors/director.cpp | 4 ++-- actors/director.h | 9 +++++---- actors/{actor.h => environment.h} | 37 +++++++++++++++---------------------- actors/roundrobin.cpp | 4 ++-- actors/roundrobin.h | 2 +- manes/start.cpp | 5 +++-- resources/pio.cpp | 25 +++++++++++++++---------- resources/pio.h | 8 ++++++-- services/kernel_state.cpp | 9 --------- services/kernel_state.h | 9 --------- services/timer.cpp | 10 ++++++---- services/timer.h | 8 +++++++- 14 files changed, 74 insertions(+), 73 deletions(-) copy actors/{actor.h => environment.h} (67%) diff --git a/actors/actor.cpp b/actors/actor.cpp index 86e4c24..d7f8515 100644 --- a/actors/actor.cpp +++ b/actors/actor.cpp @@ -32,6 +32,8 @@ using namespace actors; actor::actor() : tss_selector(0) {} void actor::set(delegate _start) { + assert("actor: unknown entry point", _start.null()); + start = _start; delegate del_start(start); @@ -39,7 +41,8 @@ void actor::set(delegate _start) { } void actor::execute() { - manes::manec::state()->switch_actor(this); + assert("actor: unknown entry point", start.null()); + arch::jump_tss(tss_selector); } diff --git a/actors/actor.h b/actors/actor.h index 8948c4e..31fb608 100644 --- a/actors/actor.h +++ b/actors/actor.h @@ -24,21 +24,25 @@ #define _ACTOR_H_ #include "libs/delegate.h" +#include "libs/pointer.h" #include "manes/implementation.h" namespace actors { class actor : public manes::implementation { private: - delegate start; + p parent; + delegate start; unsigned int tss_selector; + + p env; public: actor(); - unsigned int get_tss(); + virtual unsigned int get_tss(); - void execute(); - void set(delegate); + virtual void execute(); + virtual void set(delegate); static void register_type(); }; diff --git a/actors/director.cpp b/actors/director.cpp index 9b8f7f3..17dada9 100644 --- a/actors/director.cpp +++ b/actors/director.cpp @@ -45,11 +45,11 @@ void director::execution_flow() { while(1) asm("cli\nhlt"); } -void director::start(actor *process) { +void director::start(p process) { execution_list.push(process); } -void director::launch(actor *process) { +void director::launch(p process) { start(process); execution_flow(); diff --git a/actors/director.h b/actors/director.h index 7ed7ef6..895d825 100644 --- a/actors/director.h +++ b/actors/director.h @@ -27,13 +27,14 @@ #include "actor.h" #include "libs/fifo.h" +#include "libs/pointer.h" #include "libs/delegate.h" namespace actors { class director : public manes::creator { protected: - fifo execution_list; - actor * volatile current; + fifo > execution_list; + p current; virtual void execution_flow(); @@ -41,8 +42,8 @@ namespace actors { bool initialize(); bool type_added(manes::type_name); - virtual void start(actor *); - virtual void launch(actor *); + virtual void start(p); + virtual void launch(p); static void register_type(); }; diff --git a/actors/actor.h b/actors/environment.h similarity index 67% copy from actors/actor.h copy to actors/environment.h index 8948c4e..8d16f1d 100644 --- a/actors/actor.h +++ b/actors/environment.h @@ -1,8 +1,8 @@ /* Quarn OS * - * Actor + * Environment * - * Copyright (C) 2008-2009 Pawel Dziepak + * Copyright (C) 2009 Pawel Dziepak * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,28 +20,21 @@ * */ -#ifndef _ACTOR_H_ -#define _ACTOR_H_ - -#include "libs/delegate.h" -#include "manes/implementation.h" - namespace actors { - class actor : public manes::implementation { + class environment { private: - delegate start; - - unsigned int tss_selector; - public: - actor(); + p stdio; + p errors; - unsigned int get_tss(); + /* Typed envs?? */ + list names; + list values; - void execute(); - void set(delegate); - - static void register_type(); - }; + list arguments; + public: + virtual void legacy(p parent); + virtual void arguments(string args); + virtual void set_env(string env, string value); + virtual void get_env(string env, string value); + } } - -#endif diff --git a/actors/roundrobin.cpp b/actors/roundrobin.cpp index fb7dc8e..a0bda06 100644 --- a/actors/roundrobin.cpp +++ b/actors/roundrobin.cpp @@ -33,7 +33,7 @@ void roundrobin::on_time_tick() { if (time_left > 0 || execution_list.empty()) return; - actor *old = current; + p old = current; current = execution_list.pop(); execution_list.push(old); @@ -42,7 +42,7 @@ void roundrobin::on_time_tick() { current->execute(); } -void roundrobin::launch(actor *process) { +void roundrobin::launch(p process) { delegate timetick; timetick.method(this, &roundrobin::on_time_tick); diff --git a/actors/roundrobin.h b/actors/roundrobin.h index 2f0db2d..6cac647 100644 --- a/actors/roundrobin.h +++ b/actors/roundrobin.h @@ -35,7 +35,7 @@ namespace actors { void on_time_tick(); public: - void launch(actor *process); + void launch(p process); static void register_type(); }; diff --git a/manes/start.cpp b/manes/start.cpp index 688c6dd..71b2238 100644 --- a/manes/start.cpp +++ b/manes/start.cpp @@ -203,11 +203,12 @@ void next() { pio *str = main->get("/pio"); + char buffer[] = "\n\xdHello World!!!"; str->set_dep(ttyS); - str->send_packet((void*)"\n\xdHello World!!!",14); + str->send_packet(buffer,strlen(buffer)); str->set_speed(3); delegate nul; -// str->start(false, &nul); +// str->start(false, nul); while (1) __asm__("hlt"); } diff --git a/resources/pio.cpp b/resources/pio.cpp index ca497db..bb63b46 100644 --- a/resources/pio.cpp +++ b/resources/pio.cpp @@ -29,36 +29,40 @@ using namespace manes; using namespace resources; void pio::send_packet(void *data, int _size) { + assert("pio: incorrect buffer size", _size < 1); + buffer = (char*)data; size = _size; } void pio::set_speed(int v) { + assert("pio: too high transmission speed", v > 1000); + if (v != 0) speed = 1000 / v; else speed = 0; } -void pio::set_dep(stream *_dep) { +void pio::set_dep(p _dep) { dep = _dep; } void pio::send_data_next() { if (ptr >= size) { ready = true; - notice_user(); + if (!notice_user.null()) + notice_user(); return; } - ((stream*)dep)->write_bytes(&(buffer[ptr++]),1); + dep->write_bytes(&(buffer[ptr++]),1); - manec::get()->get("/timer")->set_timer(speed, snd_dt_nxt); + tm->set_timer(speed, snd_dt_nxt); } -bool pio::start(bool *_wait, delegate* _notice) { - bool wait = *_wait; - delegate notice = *_notice; - notice_user = notice; +bool pio::start(bool wait, delegate notice) { + tm = manec::get()->get("/timer"); + ready = false; if (speed != 0) { ptr = 0; @@ -66,8 +70,9 @@ bool pio::start(bool *_wait, delegate* _notice) { send_data_next(); } else { for (int i = 0; i < size; i++) - ((stream*)dep)->write_bytes(&(buffer[i]),1); - notice(); + dep->write_bytes(&(buffer[i]),1); + if (!notice.null()) + notice(); return true; } if (!wait) return true; diff --git a/resources/pio.h b/resources/pio.h index 8c73742..5a7e60a 100644 --- a/resources/pio.h +++ b/resources/pio.h @@ -25,10 +25,14 @@ #include "socket.h" #include "stream.h" +#include "libs/pointer.h" +#include "services/timer.h" namespace resources { class pio : public socket { private: + services::timer *tm; + stream *dep; char *buffer; int size, ptr; @@ -42,8 +46,8 @@ namespace resources { public: void send_packet(void *data, int size); void set_speed(int); - void set_dep(stream*); - bool start(bool *wait, delegate*); + void set_dep(p); + bool start(bool wait, delegate); static void register_type(); }; diff --git a/services/kernel_state.cpp b/services/kernel_state.cpp index 16e954e..df799cd 100644 --- a/services/kernel_state.cpp +++ b/services/kernel_state.cpp @@ -29,7 +29,6 @@ #include "kernel_state.h" #include "manes/error.h" -using namespace actors; using namespace manes; using namespace resources; using namespace services; @@ -98,14 +97,6 @@ memm *kernel_state::get_memalloc() const { return memory_allocator; } -actor *kernel_state::current_actor() const { - return process; -} - -void kernel_state::switch_actor(actor *act) { - process = act; -} - extern bool _static_mem_off; void kernel_state::set_memory_allocator(memm *memalloc) { diff --git a/services/kernel_state.h b/services/kernel_state.h index a9f11f9..8fb76ad 100644 --- a/services/kernel_state.h +++ b/services/kernel_state.h @@ -34,10 +34,6 @@ #include "libs/list.h" #include "libs/delegate.h" -namespace actors{ -class actor; -} - namespace manes { class error; } @@ -83,8 +79,6 @@ namespace services { */ list > time_tick_call; - actors::actor *process; - resources::memm *memory_allocator; public: @@ -104,9 +98,6 @@ namespace services { virtual manes::error *new_error(const char *x); - virtual actors::actor *current_actor() const; - virtual void switch_actor(actors::actor *); - static void register_type(); }; } diff --git a/services/timer.cpp b/services/timer.cpp index 1641949..cb42c22 100644 --- a/services/timer.cpp +++ b/services/timer.cpp @@ -31,23 +31,25 @@ void timer::set_timer(int wait, delegate _call) { assert("timer: incorrect wait argument", wait < 1); assert("timer: incorrect alarm delegate", _call.null()); + ks = manec::state(); + delegate ptr_time_tick; ptr_time_tick.method(this,&timer::time_tick); call = _call; - start = manec::state()->get_time(); + start = ks->get_time(); end = start + wait; - manec::state()->add_time_tick_call(ptr_time_tick); + ks->add_time_tick_call(ptr_time_tick); } void timer::time_tick() { - if (end != manec::state()->get_time()) return; + if (end != ks->get_time()) return; delegate ptr_time_tick; ptr_time_tick.method(this, &timer::time_tick); - manec::state()->del_time_tick_call(ptr_time_tick); + ks->del_time_tick_call(ptr_time_tick); call(); } diff --git a/services/timer.h b/services/timer.h index 6b40d46..22f275a 100644 --- a/services/timer.h +++ b/services/timer.h @@ -20,13 +20,18 @@ * */ -#include "manes/implementation.h" +#ifndef _TIMER_H_ +#define _TIMER_H_ +#include "manes/implementation.h" +#include "kernel_state.h" #include "libs/delegate.h" namespace services { class timer : public manes::implementation { private: + kernel_state *ks; + int start, end; delegate call; @@ -38,3 +43,4 @@ namespace services { }; } +#endif -- 2.11.4.GIT