Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / system / util / include / blaze-data.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: blaze-data.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef _BLAZE_DATA_H_
#define _BLAZE_DATA_H_
#pragma ident "@(#)1.1 09/19/03 blaze-data.h"
#include <thread.h>
template <class T> class List1Node
{
T data;
List1Node* next;
public:
///////////////////////////////////////
static List1Node* CreateInstance (const char *from)
{
List1Node * p = (List1Node*) calloc (1, sizeof(List1Node));
if (p == NULL) {
if (from) {
fprintf (stderr, "<%s>: unable to allocate %d bytes \n",
from, sizeof(List1Node));
}
else {
fprintf (stderr, "<LIST1>: unable to allocate %d bytes \n",
sizeof(List1Node));
}
return NULL;
}
return p;
}
///////////////////////////////////////
static void AddTailProtected (List1Node **head, List1Node **tail, List1Node *instance, mutex_t *lock)
{
List1Node *ph;
List1Node *pt;
mutex_lock(lock);
ph = *head;
pt = *tail;
if (ph == NULL) {
*head = *tail = instance;
}
else {
pt->next = instance;
*tail = instance;
}
mutex_unlock(lock);
}
///////////////////////////////////////
static void AddTail (List1Node **head, List1Node **tail, List1Node *instance)
{
List1Node *ph = *head;
List1Node *pt = *tail;
if (ph == NULL) {
*head = *tail = instance;
}
else {
pt->next = instance;
*tail = instance;
}
}
static void AddTail (List1Node **head, List1Node *instance)
{
List1Node *ph = *head;
if (ph == NULL) {
*head = instance;
}
else {
List1Node * tail = *head;
while(tail->next)
tail = tail->next;
tail->next = instance;
instance->next = 0;
}
}
///////////////////////////////////////
static void AddHeadProtected (List1Node **head, List1Node *instance, mutex_t *lock )
{
List1Node *ph;
mutex_lock(lock);
ph = *head;
if (ph == NULL) {
*head = instance;
}
else {
instance->next = *head;
*head = instance;
}
mutex_unlock(lock);
}
///////////////////////////////////////
static void AddHead (List1Node **head, List1Node *instance)
{
List1Node *ph = *head;
if (ph == NULL) {
*head = instance;
}
else {
instance->next = *head;
*head = instance;
}
}
///////////////////////////////////////
static void DeleteHead (List1Node **head)
{
List1Node *ph = *head;
if (ph == NULL) {
return;
}
else {
*head = ph->next;
delete ph;
}
}
///////////////////////////////////////
static List1Node* GetHeadProtected (List1Node **head, mutex_t *lock)
{
List1Node *ph;
mutex_lock(lock);
ph = *head;
if (ph != NULL) {
*head = ph->next;
}
mutex_unlock(lock);
return ph;
}
///////////////////////////////////////
static List1Node* GetHead (List1Node **head)
{
List1Node *ph = *head;
if (ph != NULL) {
*head = ph->next;
}
return ph;
}
///////////////////////////////////////
static void DeleteNode (List1Node **head, List1Node *prv)
{
if (prv == NULL) {
List1Node *pinstance = (*head);
(*head) = pinstance->next;
delete pinstance;
return;
}
else {
List1Node *pinstance = prv->next;
prv->next = pinstance->next;
delete pinstance;
}
}
///////////////////////////////////////
T* GetData ()
{
return &data;
}
///////////////////////////////////////
List1Node *Next ()
{
return next;
}
///////////////////////////////////////
List1Node **GetNext ()
{
return &next;
}
///////////////////////////////////////
static void LinktoTail (List1Node *tail, List1Node *head)
{
tail->next = head;
}
};
#endif // _BLAZE_DATA_H_