view TaskManager/kernel/ppe/HTaskInfo.cc @ 47:8266445bdac2

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 13:09:58 +0900
parents f154d9d07a42
children 90523ccc4dff
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include "HTaskInfo.h"

HTaskInfo::HTaskInfo(void)
    :htaskPool(NULL), freeHTask(NULL) {}

HTaskInfo::~HTaskInfo(void) { destroy(); }

int
HTaskInfo::init(int num)
{
    if (htaskPool == NULL) {
	return extend_pool(num);
    }
    return 0;
}

/**
 * Fix me
 *   extend できる限界を設定するべき?
 */
int
HTaskInfo::extend_pool(int num)
{
    HTaskPtr q = NULL;

    q = (HTaskPtr)malloc(sizeof(HTask)*(num+1));

    if (q == NULL) {
	return -1;
    }
    q->next = htaskPool;
    htaskPool = q;

    /* Connect all free queue in the pool */
    for (q = htaskPool + 1; --num > 0; q++) {
	q->next = q + 1;
    }
    q->next = freeHTask;
    freeHTask = htaskPool + 1;

    return 0;
}

HTaskPtr
HTaskInfo::create(int cmd, int size,
		  unsigned long long in_addr,
		  unsigned long long out_addr)
{
    HTaskPtr q;
    
    if (freeHTask == NULL) {
	extend_pool(100);
    }

    q = freeHTask;
    freeHTask = freeHTask->next;

    q->command  = cmd;
    q->in_addr  = in_addr;
    q->out_addr = out_addr;
    q->in_size  = size;
    q->wait_me  = NULL;
    q->wait_i   = NULL;
    q->post_func = NULL;

    return q;
}

void
HTaskInfo::free(HTaskPtr q)
{
    q->next = freeHTask;
    freeHTask = q;
}

void
HTaskInfo::destroy(void)
{
    HTaskPtr q;

    for (q = htaskPool; q; q = q->next) {
	free(q);
    }
    freeHTask = htaskPool = NULL;
}