77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#include "StdAfx.h"
|
|
#include "static_cola.h"
|
|
//*******************************************************************************
|
|
Cstatic_cola::Cstatic_cola()
|
|
{
|
|
capacidad=z=0;
|
|
ini=fin=0;
|
|
buf=NULL;
|
|
elemento=NULL;
|
|
|
|
}
|
|
//*******************************************************************************
|
|
Cstatic_cola::~Cstatic_cola(void)
|
|
{
|
|
if(buf)
|
|
free(buf);
|
|
if (elemento)
|
|
free(elemento);
|
|
|
|
}
|
|
//*******************************************************************************
|
|
BOOL Cstatic_cola::add( BYTE *e )
|
|
{
|
|
cerrojo.entro();//<<<<<<<<<<<<<<<<<
|
|
//vemos si se puede----------------------
|
|
if (ini==(fin+1)%capacidad)
|
|
{
|
|
cerrojo.salgo();//>>>>>>>>>>>>>>
|
|
return FALSE;
|
|
}
|
|
//ponemos sms----------------------------
|
|
memcpy(&buf[fin*z],e,z);
|
|
fin=(fin+1)%capacidad;
|
|
cerrojo.salgo();//>>>>>>>>>>>>>>
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL Cstatic_cola::add( int t,BYTE *e )
|
|
{
|
|
cerrojo.entro();//<<<<<<<<<<<<<<<<<
|
|
//vemos si se puede----------------------
|
|
if (ini==(fin+1)%capacidad)
|
|
{
|
|
cerrojo.salgo();//>>>>>>>>>>>>>>
|
|
return FALSE;
|
|
}
|
|
//ponemos sms----------------------------
|
|
memcpy(&buf[fin*z],&t,sizeof(int));
|
|
memcpy(&buf[fin*z+sizeof(int)],e,z);
|
|
fin=(fin+1)%capacidad;
|
|
cerrojo.salgo();//>>>>>>>>>>>>>>
|
|
return TRUE;
|
|
}
|
|
|
|
//*******************************************************************************
|
|
void Cstatic_cola::inicia( int cap,int size )
|
|
{
|
|
z=size;
|
|
capacidad=cap;
|
|
ini=fin=0;
|
|
buf=(BYTE*)malloc(capacidad*z);
|
|
elemento=(BYTE*)malloc(z);
|
|
}
|
|
//*******************************************************************************
|
|
BYTE* Cstatic_cola::get()
|
|
{
|
|
//vemos si hay pendientes---------------------
|
|
if (ini==fin)
|
|
return NULL;
|
|
//pillamos------------------------------------
|
|
memcpy(elemento,&buf[ini*z],z);
|
|
ini=(ini+1)%capacidad;
|
|
return elemento;
|
|
}
|
|
|
|
//*******************************************************************************
|