- simplify the code by defining the new task status TASK_IDLE
git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@36 315a16e6-25f9-4109-90ae-ca3045a26c18
This commit is contained in:
parent
e5714b3e9e
commit
9839840e89
3 changed files with 36 additions and 12 deletions
|
@ -33,6 +33,7 @@ extern "C" {
|
|||
#define TASK_RUNNING 2
|
||||
#define TASK_BLOCKED 3
|
||||
#define TASK_FINISHED 4
|
||||
#define TASK_IDLE 5
|
||||
|
||||
typedef void* (STDCALL *entry_point_t)(void*);
|
||||
typedef unsigned int tid_t;
|
||||
|
@ -47,7 +48,6 @@ typedef struct {
|
|||
unsigned char blocked_tasks[MAX_TASKS];
|
||||
void* return_value;
|
||||
unsigned char status;
|
||||
unsigned char idle;
|
||||
} task_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -32,7 +32,10 @@
|
|||
#include <lwip/stats.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/tcp.h>
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/netif.h>
|
||||
#include <netif/etharp.h>
|
||||
//#include <drivers/pcnet.h>
|
||||
#endif
|
||||
|
||||
static sem_t consuming, producing;
|
||||
|
@ -116,6 +119,15 @@ void* STDCALL join_test(void* arg)
|
|||
#ifdef USE_LWIP
|
||||
void* STDCALL lwip_task(void* arg)
|
||||
{
|
||||
struct netif netif;
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
struct ip_addr gw;
|
||||
err_t err;
|
||||
|
||||
sleep(10);
|
||||
kputs("LWIP task is started\n");
|
||||
|
||||
stats_init(); /* Clears the structure where runtime statistics are gathered */
|
||||
sys_init();
|
||||
mem_init(); /* Initializes the dynamic memory heap defined by MEM_SIZE. */
|
||||
|
@ -126,10 +138,26 @@ void* STDCALL lwip_task(void* arg)
|
|||
udp_init(); /* Clears the UDP PCB list */
|
||||
tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */
|
||||
|
||||
kputs("LWIP task is started\n");
|
||||
/* Bring up the network interface */
|
||||
//if (!netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcnetif_init, ethernet_input)) {
|
||||
// kputs("Unable to add network interface\n");
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
while(1) {
|
||||
}
|
||||
/* This will bring the interface up and set its IP address when it can acquire one. */
|
||||
//err = dhcp_start(&netif);
|
||||
//if (err != ERR_OK) {
|
||||
// kprintf("Unable to get IP via DHCP: %s\n", lwip_strerr(err));
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
//if (netif_is_up(&netif)) {
|
||||
// kputs("Network interface is not up\n");
|
||||
// return NULL;
|
||||
//}
|
||||
|
||||
//while(1) {
|
||||
//}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -175,7 +203,7 @@ int main(void)
|
|||
create_kernel_task(&id1, foo, "Hello from foo1\n", 8192);
|
||||
create_kernel_task(&id2, join_test, NULL, 0);
|
||||
create_kernel_task(&id3, producer, NULL, 0);
|
||||
current_task->idle = 1;
|
||||
current_task->status = TASK_IDLE;
|
||||
schedule();
|
||||
|
||||
while(1) {
|
||||
|
|
|
@ -36,7 +36,6 @@ int multitasking_init(void) {
|
|||
task_table[0].stack = NULL;
|
||||
task_table[0].stack_size = 8192;
|
||||
task_table[0].status = TASK_RUNNING;
|
||||
task_table[0].idle = 0;
|
||||
current_task = task_table;
|
||||
return 0;
|
||||
}
|
||||
|
@ -122,7 +121,6 @@ int create_kernel_task(tid_t* id, entry_point_t ep, void* arg, size_t stack_size
|
|||
memset(task_table[i].blocked_tasks, 0x00, sizeof(unsigned char)*MAX_TASKS);
|
||||
task_table[i].return_value = NULL;
|
||||
task_table[i].status = TASK_READY;
|
||||
task_table[i].idle = 0;
|
||||
|
||||
if (id)
|
||||
*id = i;
|
||||
|
@ -145,7 +143,7 @@ int join_kernel_task(tid_t id, void** result)
|
|||
* idle tasks are not allowed to wait for another task
|
||||
* they should always run...
|
||||
*/
|
||||
if (BUILTIN_EXPECT(current_task->idle, 0))
|
||||
if (BUILTIN_EXPECT(current_task->status, TASK_IDLE))
|
||||
goto join_out;
|
||||
|
||||
/* a task is not able to wait for itself */
|
||||
|
@ -215,7 +213,7 @@ task_t* get_new_task(void)
|
|||
for(i=1; i <= MAX_TASKS; i++) {
|
||||
new_id = (current_task->id + i) % MAX_TASKS;
|
||||
|
||||
if (!task_table[new_id].idle && task_table[new_id].status == TASK_READY) {
|
||||
if (task_table[new_id].status == TASK_READY) {
|
||||
if (current_task->status == TASK_RUNNING)
|
||||
current_task->status = TASK_READY;
|
||||
task_table[new_id].status = TASK_RUNNING;
|
||||
|
@ -225,7 +223,7 @@ task_t* get_new_task(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (!(current_task->idle) && (current_task->status == TASK_RUNNING)) {
|
||||
if (current_task->status == TASK_RUNNING) {
|
||||
ret = current_task;
|
||||
goto get_task_out;
|
||||
}
|
||||
|
@ -234,8 +232,6 @@ task_t* get_new_task(void)
|
|||
* we switch to the idle task (id=0), if the current task terminates
|
||||
* and no other is ready
|
||||
*/
|
||||
task_table[0].status = TASK_RUNNING;
|
||||
|
||||
ret = task_table+0;
|
||||
|
||||
get_task_out:
|
||||
|
|
Loading…
Add table
Reference in a new issue