Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Util SP - List.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_MP_LT_INL)
#define TGS_COMMON_UTIL_MP_LT_INL
#pragma once


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

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

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

/* ---- tgCM_UTS_LT_Init ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgRESULT tgCM_UTS_LT_Init( PCU_STg2_UTS_LT psMP_LT )
{
    TgPARAM_CHECK(psMP_LT);
    psMP_LT->m_sNode.m_pPrev_Node = &psMP_LT->m_sNode;
    psMP_LT->m_sNode.m_pNext_Node = &psMP_LT->m_sNode;
    return (KTgS_OK);
}


/* ---- tgCM_UTS_LT_Free ------------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_LT_Free( PCU_STg2_UTS_LT psMP_LT )
{
    TgPARAM_CHECK(psMP_LT);
    TgERROR(tgCM_UTS_LT_Is_Empty( psMP_LT ));
}


/* ---- tgCM_UTS_LT_Push_Front ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_LT_Push_Front( PCU_STg2_UTS_LT psMP_LT, PC_STg2_UTS_LT_Node psNode )
{
    TgPARAM_CHECK(psMP_LT && psNode);
    psNode->m_pPrev_Node = &psMP_LT->m_sNode;
    psNode->m_pNext_Node = psMP_LT->m_sNode.m_pNext_Node;
    psMP_LT->m_sNode.m_pNext_Node->m_pPrev_Node = psNode;
    psMP_LT->m_sNode.m_pNext_Node = psNode;
}


/* ---- tgCM_UTS_LT_Push_Back ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_LT_Push_Back( PCU_STg2_UTS_LT psMP_LT, PC_STg2_UTS_LT_Node psNode )
{
    TgPARAM_CHECK(psMP_LT && psNode);
    psNode->m_pPrev_Node = psMP_LT->m_sNode.m_pPrev_Node;
    psNode->m_pNext_Node = &psMP_LT->m_sNode;
    psMP_LT->m_sNode.m_pPrev_Node->m_pNext_Node = psNode;
    psMP_LT->m_sNode.m_pPrev_Node = psNode;
}


/* ---- tgCM_UTS_LT_Pop_Front ------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_STg2_UTS_LT_Node tgCM_UTS_LT_Pop_Front( PCU_STg2_UTS_LT psMP_LT )
{
    P_STg2_UTS_LT_Node                  psNode;

    TgPARAM_CHECK(psMP_LT && psMP_LT->m_sNode.m_pNext_Node);
    psNode = psMP_LT->m_sNode.m_pNext_Node;
    if (&psMP_LT->m_sNode == psNode)
        return (nullptr);

    psNode->m_pNext_Node->m_pPrev_Node = psNode->m_pPrev_Node;
    psMP_LT->m_sNode.m_pNext_Node = psNode->m_pNext_Node;

    return (psNode);
}


/* ---- tgCM_UTS_LT_Pop_Back -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE P_STg2_UTS_LT_Node tgCM_UTS_LT_Pop_Back( PCU_STg2_UTS_LT psMP_LT )
{
    P_STg2_UTS_LT_Node                  psNode;

    TgPARAM_CHECK(psMP_LT && psMP_LT->m_sNode.m_pPrev_Node);
    psNode = psMP_LT->m_sNode.m_pPrev_Node;
    if (&psMP_LT->m_sNode == psNode)
        return (nullptr);

    psNode->m_pPrev_Node->m_pNext_Node = psNode->m_pNext_Node;
    psMP_LT->m_sNode.m_pPrev_Node = psNode->m_pPrev_Node;

    return (psNode);
}


/* ---- tgCM_UTS_LT_Insert ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_LT_Insert( PC_STg2_UTS_LT_Node psNodeAt, PC_STg2_UTS_LT_Node psNewNode )
{
    TgPARAM_CHECK(psNodeAt && psNewNode);
    psNewNode->m_pPrev_Node = psNodeAt->m_pPrev_Node;
    psNewNode->m_pNext_Node = psNodeAt;
    psNodeAt->m_pPrev_Node->m_pNext_Node = psNewNode;
    psNodeAt->m_pPrev_Node = psNewNode;
}


/* ---- tgCM_UTS_LT_Remove ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgCM_UTS_LT_Remove( PC_STg2_UTS_LT_Node psNode )
{
    TgPARAM_CHECK(psNode && psNode->m_pPrev_Node && psNode->m_pNext_Node);
    psNode->m_pPrev_Node->m_pNext_Node = psNode->m_pNext_Node;
    psNode->m_pNext_Node->m_pPrev_Node = psNode->m_pPrev_Node;
    psNode->m_pNext_Node = nullptr;
    psNode->m_pPrev_Node = nullptr;
}


/* ---- tgCM_UTS_LT_Is_Empty -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgCM_UTS_LT_Is_Empty( PCU_STg2_UTS_LT psMP_LT )
{
    TgPARAM_CHECK(psMP_LT);
    return (psMP_LT->m_sNode.m_pPrev_Node == &psMP_LT->m_sNode ? TgTRUE : TgFALSE);
}


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