view TaskManager/kernel/ppe/HTask.h @ 941:0c11c2fd7e63

add no_auto_free flag on HTask
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 31 Jul 2010 17:50:38 +0900
parents bed529c55eda
children a9c7784e5dae
line wrap: on
line source

#ifndef INCLUDED_HTASK
#define INCLUDED_HTASK

#include "base.h"
#include "types.h"
#include "Task.h"
#include "TaskQueueInfo.h"
#include <stdio.h>

class TaskManagerImpl;
class SchedTask;

typedef void (*PostFunction)(SchedTask *s, void *read, void *write);

/*!
  @class
  
  @brief
  
  Cerium の Task で、spawn() でキューに格納されて順次実行される。
  cpu の指定があれば並列に実行される。
  特定の Task を待ち合わせる事が可能。
  Task の入出力は dma などで copy される。
 */

#include "SimpleTask.h"

class HTask : public SimpleTask {
public:
    BASE_NEW_DELETE(HTask);

    TaskQueueInfo *wait_me;  // List of task waiting for me
    TaskQueueInfo *wait_i;   // List of task for which I am waiting
    PostFunction post_func;
    void *post_arg1;
    void *post_arg2;
    CPU_TYPE cpu_type;
    TaskManagerImpl *mimpl;

    HTask *waiter;
    HTask *next;
    HTask *prev;

    struct {
	unsigned no_auto_free:1;        //      bit 0    auto free flag (0 .. auto, 1 manual)
    } flag;

    void spawn();
    void wait_for(HTask *);
    void set_cpu(CPU_TYPE type);    
    void set_post(PostFunction func, void *read, void *write);
    Task *create_task_array(int task_id, int num_task, int num_param, int num_inData, int num_outData);
    Task *next_task_array(int task_id, Task *t);
    void spawn_task_array(Task *t);


    private:

    int param_index;
    int in_index;
    int out_index;

// compatibility
    public: // functions
    void add_inData_t(memaddr addr, int size) {
	Task *t = (Task*)rbuf;
	t->set_inData_t(in_index++, addr,size);
    }
    void add_outData_t(memaddr addr, int size) {
	Task *t = (Task*)rbuf;
	t->set_outData_t(out_index++, addr,size);
    }
    void set_inData_t(int index, memaddr addr, int size) {
      if ((unsigned long)addr&0xf) {
	  printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n", 
		 command, index, (unsigned long)addr, size);
	}
	Task *t = (Task*)rbuf;
	t->set_inData_t(index, addr,size);
    }
    void set_outData_t(int index, memaddr addr, int size) { 
      if ((unsigned long)addr&0xf) {
	  printf("inData is not aligned. command = %d, index = %d, addr = 0x%lx, size = %d\n", 
		 command, index, (unsigned long)addr, size);
	}
	Task *t = (Task*)rbuf;
	t->set_outData_t(index, addr,size);
    }
    void add_param_t(memaddr param) {
	Task *t = (Task*)rbuf;
	t->set_param_t(param_index++, param);
    }
    void set_param_t(int index, memaddr param) {
	Task *t = (Task*)rbuf;
	t->set_param_t(index, param);
    }

    void no_auto_free() {
	flag.no_auto_free = 1;
    }

    void init(int cmd) {
	next = prev = NULL;
	waiter = NULL;

	command  = cmd;
	param_index = 0;
	in_index = 0;
	out_index = 0;
	flag.no_auto_free = 0;
	self = (memaddr) this;

	post_func = NULL;
	mimpl     = NULL;
	cpu_type  = CPU_PPE;
    }
#define add_param(param) add_param_t((memaddr)(param))
#define set_param(index,param) set_param_t(index, (memaddr) (param))

#define add_inData(addr, size)                  \
    add_inData_t((memaddr)(addr), (size));
#define add_outData(addr, size)                 \
    add_outData_t((memaddr)(addr), (size));


}  __attribute__ ((aligned (DEFAULT_ALIGNMENT)));

typedef HTask* HTaskPtr;

#endif