eapol/eapol_framework/eapol_common/am/common/abs_eap_am_mutex.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 1 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 
       
    29 #include "eap_am_memory.h"
       
    30 #include "abs_eap_am_mutex.h"
       
    31 
       
    32 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    33 
       
    34 EAP_FUNC_EXPORT abs_eap_am_mutex_c::~abs_eap_am_mutex_c()
       
    35 {
       
    36 }
       
    37 
       
    38 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    39 
       
    40 EAP_FUNC_EXPORT abs_eap_am_mutex_c::abs_eap_am_mutex_c()
       
    41 {
       
    42 }
       
    43 
       
    44 
       
    45 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    46 
       
    47 EAP_FUNC_EXPORT eap_am_mutex_reference_c::~eap_am_mutex_reference_c()
       
    48 {
       
    49 }
       
    50 
       
    51 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    52 
       
    53 EAP_FUNC_EXPORT eap_am_mutex_reference_c::eap_am_mutex_reference_c()
       
    54 	: m_reference_count(0u)
       
    55 	, m_is_reserved(false)
       
    56 {
       
    57 }
       
    58 
       
    59 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    60 
       
    61 EAP_FUNC_EXPORT void eap_am_mutex_reference_c::add_reference()
       
    62 {
       
    63 	++m_reference_count;
       
    64 }
       
    65 
       
    66 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    67 
       
    68 EAP_FUNC_EXPORT void eap_am_mutex_reference_c::remove_reference()
       
    69 {
       
    70 	--m_reference_count;
       
    71 }
       
    72 
       
    73 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    74 
       
    75 EAP_FUNC_EXPORT u32_t eap_am_mutex_reference_c::get_reference_count()
       
    76 {
       
    77 	return m_reference_count;
       
    78 }
       
    79 
       
    80 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    81 
       
    82 EAP_FUNC_EXPORT void eap_am_mutex_reference_c::set_is_reserved(const bool is_reserved)
       
    83 {
       
    84 	m_is_reserved = is_reserved;
       
    85 }
       
    86 
       
    87 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    88 
       
    89 EAP_FUNC_EXPORT bool eap_am_mutex_reference_c::get_is_reserved()
       
    90 {
       
    91 #if defined(NO_EAP_MUTEX)
       
    92 	return true;
       
    93 #else
       
    94 	return m_is_reserved;
       
    95 #endif
       
    96 }
       
    97 
       
    98 // - - - - - - - - - - - - - - - - - - - - - - - -
       
    99 
       
   100 EAP_FUNC_EXPORT eap_am_mutex_base_c::~eap_am_mutex_base_c()
       
   101 {
       
   102 	if (m_reference != 0)
       
   103 	{
       
   104 		m_reference->remove_reference();
       
   105 
       
   106 		if (m_reference->get_reference_count() == 0u)
       
   107 		{
       
   108 			delete m_reference;
       
   109 		}
       
   110 	}
       
   111 }
       
   112 
       
   113 // - - - - - - - - - - - - - - - - - - - - - - - -
       
   114 
       
   115 EAP_FUNC_EXPORT eap_am_mutex_base_c::eap_am_mutex_base_c()
       
   116 	: m_reference(0)
       
   117 	, m_is_valid(false)
       
   118 {
       
   119 	m_reference = new eap_am_mutex_reference_c();
       
   120 	if (m_reference == 0)
       
   121 	{
       
   122 		return;
       
   123 	}
       
   124 	m_reference->add_reference();
       
   125 	m_is_valid = true;
       
   126 }
       
   127 
       
   128 // - - - - - - - - - - - - - - - - - - - - - - - -
       
   129 
       
   130 EAP_FUNC_EXPORT eap_am_mutex_base_c::eap_am_mutex_base_c(const eap_am_mutex_base_c * const owner)
       
   131 	: m_reference(0)
       
   132 	, m_is_valid(false)
       
   133 {
       
   134 	m_reference = owner->get_reference();
       
   135 	m_reference->add_reference();
       
   136 	m_is_valid = true;
       
   137 }
       
   138 
       
   139 // - - - - - - - - - - - - - - - - - - - - - - - -
       
   140 
       
   141 EAP_FUNC_EXPORT eap_am_mutex_reference_c * eap_am_mutex_base_c::get_reference() const
       
   142 {
       
   143 	return m_reference;
       
   144 }
       
   145 
       
   146 // - - - - - - - - - - - - - - - - - - - - - - - -
       
   147 
       
   148 /// This function is used in debug asserts.
       
   149 /// Those will check the mutex is really reserved when critical code is entered.
       
   150 EAP_FUNC_EXPORT bool eap_am_mutex_base_c::get_is_reserved() const
       
   151 {
       
   152 	// In Symbian we need this object to test reference flag,
       
   153 	// because each thread has own duplicated mutex object.
       
   154 	return m_reference->get_is_reserved();
       
   155 }
       
   156 
       
   157 // - - - - - - - - - - - - - - - - - - - - - - - -
       
   158 
       
   159 /// Returns the validity of the mutex.
       
   160 EAP_FUNC_EXPORT bool eap_am_mutex_base_c::get_is_valid() const
       
   161 {
       
   162 	return m_is_valid;
       
   163 }
       
   164 
       
   165 // ---------------------------------------------
       
   166 
       
   167 
       
   168 
       
   169 // End.