// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Talina Gaming System (TgS) (∂)
//  »File«      TgS (XB2) Common - STg1_MP_MX.inl
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  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_CTG1_MP_MX_INL_)
#define _TGS_COMMON_CTG1_MP_MX_INL_
#pragma once


// START TGS ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

TgINLINE TgRESULT tgCM_MP_MX_Init( PCU_STg1_MP_MX ptgMX )
{
    return (( NULL == (ptgMX->m_hMutex = CreateMutex( NULL, FALSE, NULL )) ) ? TgE_FAIL : TgS_OK);
}


TgINLINE TgVOID tgCM_MP_MX_Free( PCU_STg1_MP_MX ptgMX )
{
    if (0 != ptgMX->m_hMutex)
    {
        CloseHandle( ptgMX->m_hMutex );
        ptgMX->m_hMutex = 0;
    };
}


TgINLINE TgVOID tgCM_MP_MX_Enter_Block( PCU_STg1_MP_MX ptgMX )
{
    while (WAIT_OBJECT_0 != WaitForSingleObject( ptgMX->m_hMutex, 0xFFFFFFFF ));
}


TgINLINE TgRESULT tgCM_MP_MX_Enter( PCU_STg1_MP_MX ptgMX )
{
    return( WAIT_OBJECT_0 == WaitForSingleObject( ptgMX->m_hMutex, 0 ) ? TgS_OK : TgE_FAIL );
}


TgINLINE TgVOID tgCM_MP_MX_Exit( PCU_STg1_MP_MX ptgMX )
{
    ReleaseMutex( ptgMX->m_hMutex );
}


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