Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS Common - Util MP - Spin Lock.h
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
//  »Keyword«   Spin-Lock;Lockless;Atomic
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, 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: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions 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. 
//  Neither the names of the copyright owner nor the names of its contributors may 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_SN_H_)
#define _TGS_COMMON_UTIL_MP_SN_H_
#pragma once


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
//  Type Definitions
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

typedef union TgALIGN(8)
{
    struct
    {
#if TgCOMPILE_LITTLE_ENDIAN
        volatile TgATOMIC_INT32                     niServed;
        volatile TgATOMIC_INT32                     iRequest;
#else
        volatile TgATOMIC_INT32                     iRequest;
        volatile TgATOMIC_INT32                     niServed;
#endif
    }                                           m;
    volatile TgATOMIC_INT64                     m_iData;
    TgUINT08                                    m_uiPad0[8];
} STg2_UTM_SN;
TgTYPE_PREFIX( STg2_UTM_SN );
TgCOMPILER_ASSERT(8 == sizeof(STg2_UTM_SN),0);

typedef struct TgALIGN(TgCOMPILE_CACHE_LINE_SIZE)
{
    STg2_UTM_SN                                 m_sLock;
#if TgCOMPILE_CACHE_LINE_SIZE > 8
    TgUINT08                                    m_uiPad[TgCOMPILE_CACHE_LINE_SIZE-8];
#endif
} STg2_UTM_SN_ISO;
TgTYPE_PREFIX( STg2_UTM_SN_ISO );


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

                                            // Spin locks start in a signaled state and it is not a counting lock (i.e. you can not
                                            // pre-signal the lock to allow thread permission).
TgINLINE TgRESULT                           tgCM_UTM_SN_Init( PCU_STg2_UTM_SN );
TgINLINE TgVOID                             tgCM_UTM_SN_Free( PCU_STg2_UTM_SN );

TgINLINE TgVOID                             tgCM_UTM_SN_Lock_Yield( PCU_STg2_UTM_SN );
TgINLINE TgVOID                             tgCM_UTM_SN_Lock_Spin( PCU_STg2_UTM_SN );
TgINLINE TgRESULT                           tgCM_UTM_SN_Lock_Test( PCU_STg2_UTM_SN );

TgINLINE TgVOID                             tgCM_UTM_SN_Signal( PCU_STg2_UTM_SN );


#endif //  END  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////