Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Util SP - Queue.inl
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_UTIL_SP_QU_INL)
#define TGS_COMMON_UTIL_SP_QU_INL
#pragma once


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- Spin-Lock Queue --------------------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- tgCM_UTS_QU_Init ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT tgCM_UTS_QU_Init( PC_STg2_UTS_QU psMP_QU )
{
    psMP_QU->m_sNode.m_pNext_Node = &psMP_QU->m_sNode;
    psMP_QU->m_psTail_Node = &psMP_QU->m_sNode;
    return (KTgS_OK);
}


/* ---- tgCM_UTS_QU_Free ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_QU_Free( PC_STg2_UTS_QU psMP_QU )
{
    TgERROR(tgCM_UTS_QU_Is_Empty( psMP_QU ));
}


/* ---- tgCM_UTS_QU_Enqueue --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_QU_Enqueue( PC_STg2_UTS_QU psMP_QU, PC_STg2_UTS_QU_Node psNode )
{
    P_STg2_UTS_QU_Node                  psTailNode;

    psTailNode = psNode;
    while (nullptr != psTailNode->m_pNext_Node)
    {
        psTailNode = psTailNode->m_pNext_Node;
    } 

    psMP_QU->m_psTail_Node->m_pNext_Node = psNode;
    psMP_QU->m_psTail_Node = psTailNode;
    psMP_QU->m_psTail_Node->m_pNext_Node = &psMP_QU->m_sNode;
}


/* ---- tgCM_UTS_QU_Merge ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_QU_Merge( PC_STg2_UTS_QU psMP_QU0, PC_STg2_UTS_QU psMP_QU1 )
{
    P_STg2_UTS_QU_Node                  psTailNode;
    P_STg2_UTS_QU_Node                  psNode;

    if( TgTRUE == tgCM_UTS_QU_Is_Empty( psMP_QU1 ))
    {
        return;
    };

    psNode = psMP_QU1->m_sNode.m_pNext_Node;

    psTailNode = psMP_QU1->m_psTail_Node;
    psTailNode->m_pNext_Node = &psMP_QU0->m_sNode;

    psMP_QU0->m_psTail_Node->m_pNext_Node = psNode;
    psMP_QU0->m_psTail_Node = psTailNode;

    psMP_QU1->m_sNode.m_pNext_Node = &psMP_QU1->m_sNode;
    psMP_QU1->m_psTail_Node = &psMP_QU1->m_sNode;
}


/* ---- tgCM_UTS_QU_Dequeue --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_STg2_UTS_QU_Node tgCM_UTS_QU_Dequeue( PC_STg2_UTS_QU psMP_QU )
{
    P_STg2_UTS_QU_Node                  psNode;

    psNode = psMP_QU->m_sNode.m_pNext_Node;
    if (&psMP_QU->m_sNode == psNode)
    {
        return (nullptr);
    };

    psMP_QU->m_sNode.m_pNext_Node = psNode->m_pNext_Node;

    if (&psMP_QU->m_sNode == psNode->m_pNext_Node)
    {
        psMP_QU->m_psTail_Node = &psMP_QU->m_sNode;
    };

    psNode->m_pNext_Node = nullptr;
    return (psNode);
}


/* ---- tgCM_UTS_QU_Is_Empty -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_QU_Is_Empty( PC_STg2_UTS_QU psMP_QU )
{
    return (&psMP_QU->m_sNode == psMP_QU->m_sNode.m_pNext_Node ? TgTRUE : TgFALSE);
}


/* ---- tgCM_UTS_QU_Is_Valid -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_QU_Is_Valid( PC_STg2_UTS_QU psMP_QU )
{
    P_STg2_UTS_QU_Node                  psNode;

    if ((nullptr == psMP_QU->m_psTail_Node) || (psMP_QU->m_psTail_Node->m_pNext_Node != &psMP_QU->m_sNode))
    {
        return (TgFALSE);
    };

    psNode = psMP_QU->m_sNode.m_pNext_Node;
    do
    {
        if (psNode == psMP_QU->m_psTail_Node)
        {
            return (TgTRUE);
        };
        psNode = psNode->m_pNext_Node;
    }
    while (psNode != &psMP_QU->m_sNode);
    return (TgFALSE);
}


/* ---- tgCM_UTS_QU_In_Queue -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_QU_In_Queue( PC_STg2_UTS_QU psMP_QU, PC_STg2_UTS_QU_Node psTest )
{
    P_STg2_UTS_QU_Node                  psNode;

    psNode = psMP_QU->m_sNode.m_pNext_Node;
    do
    {
        if (psNode == psTest)
        {
            return (TgTRUE);
        };
        if (psNode == psMP_QU->m_psTail_Node)
        {
            break;
        };
        psNode = psNode->m_pNext_Node;
    }
    while (psNode != &psMP_QU->m_sNode);
    return (TgFALSE);
}


/* ====================================================================================================================================================================== */
#endif