eapol/eapol_framework/eapol_symbian/am/common/symbian/eap_am_mutex_symbian.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 602 
       
    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 // INCLUDES
       
    30 #include "eap_am_memory.h"
       
    31 #include "eap_am_mutex_symbian.h"
       
    32 #include "abs_eap_am_mutex.h"
       
    33 
       
    34 //--------------------------------------------------
       
    35 
       
    36 //
       
    37 EAP_FUNC_EXPORT eap_am_mutex_symbian_c::~eap_am_mutex_symbian_c()
       
    38 {
       
    39 	m_mutex.Close();
       
    40 	m_owner_thread.Close();
       
    41 }
       
    42 
       
    43 //--------------------------------------------------
       
    44 
       
    45 //
       
    46 EAP_FUNC_EXPORT eap_am_mutex_symbian_c::eap_am_mutex_symbian_c()
       
    47 	: m_is_valid(false)
       
    48 {
       
    49 	if (eap_am_mutex_base_c::get_is_valid() == false)
       
    50 	{
       
    51 		return;
       
    52 	}
       
    53 
       
    54 	m_mutex.CreateLocal();
       
    55 
       
    56 	RThread thisThread; // Generic handle meaning "the current thread"
       
    57 
       
    58 	TInt err = thisThread.Duplicate(thisThread);    // a specific handle
       
    59 	if (err == KErrNone)
       
    60 	{
       
    61 		m_is_valid = true;
       
    62 	}
       
    63 
       
    64 	m_owner_thread = thisThread;
       
    65 }
       
    66 
       
    67 //--------------------------------------------------
       
    68 
       
    69 //
       
    70 EAP_FUNC_EXPORT eap_am_mutex_symbian_c::eap_am_mutex_symbian_c(const eap_am_mutex_symbian_c * const owner)
       
    71 	: eap_am_mutex_base_c(owner)
       
    72 	, m_is_valid(false)
       
    73 {
       
    74 	if (eap_am_mutex_base_c::get_is_valid() == false)
       
    75 	{
       
    76 		return;
       
    77 	}
       
    78 
       
    79 	m_mutex = *(owner->get_mutex());
       
    80 	m_mutex.Duplicate(*(owner->get_owner_thread()));
       
    81 
       
    82 	RThread thisThread; // Generic handle meaning "the current thread"  
       
    83 
       
    84 	TInt err = thisThread.Duplicate(thisThread);    // a specific handle 
       
    85 	if (err == KErrNone)
       
    86 	{
       
    87 		m_is_valid = true;
       
    88 	}
       
    89 
       
    90 	m_owner_thread = thisThread;
       
    91 }
       
    92 
       
    93 //--------------------------------------------------
       
    94 
       
    95 //
       
    96 EAP_FUNC_EXPORT const RMutex * eap_am_mutex_symbian_c::get_mutex() const
       
    97 {
       
    98 	return &m_mutex;
       
    99 }
       
   100 
       
   101 //--------------------------------------------------
       
   102 
       
   103 //
       
   104 EAP_FUNC_EXPORT const RThread * eap_am_mutex_symbian_c::get_owner_thread() const
       
   105 {
       
   106 	return &m_owner_thread;
       
   107 }
       
   108 
       
   109 //--------------------------------------------------
       
   110 
       
   111 //
       
   112 EAP_FUNC_EXPORT eap_status_e eap_am_mutex_symbian_c::mutex_enter()
       
   113 {
       
   114 #if !defined(NO_EAP_MUTEX)
       
   115 	m_mutex.Wait();
       
   116 	get_reference()->set_is_reserved(true);
       
   117 #endif //#if !defined(NO_EAP_MUTEX)
       
   118 
       
   119 	return eap_status_ok;
       
   120 }
       
   121 
       
   122 //--------------------------------------------------
       
   123 
       
   124 //
       
   125 EAP_FUNC_EXPORT eap_status_e eap_am_mutex_symbian_c::mutex_leave(abs_eap_am_tools_c * const m_am_tools)
       
   126 {
       
   127 	EAP_UNREFERENCED_PARAMETER(m_am_tools);
       
   128 
       
   129 #if !defined(NO_EAP_MUTEX)
       
   130 	EAP_ASSERT(get_reference()->get_is_reserved() == true);
       
   131 
       
   132 	get_reference()->set_is_reserved(false);
       
   133 	m_mutex.Signal();
       
   134 #endif //#if !defined(NO_EAP_MUTEX)
       
   135 
       
   136 	return eap_status_ok;
       
   137 }
       
   138 
       
   139 //--------------------------------------------------
       
   140 
       
   141 //
       
   142 // The mutex handle must be dublicated in Symbian operating system for each thread.
       
   143 EAP_FUNC_EXPORT abs_eap_am_mutex_c * eap_am_mutex_symbian_c::dublicate_mutex()
       
   144 {
       
   145 	eap_am_mutex_symbian_c *dublicate = new eap_am_mutex_symbian_c(this);
       
   146 	return dublicate;
       
   147 }
       
   148 
       
   149 //--------------------------------------------------
       
   150 
       
   151 //
       
   152 // This is used in debug asserts. Those will check the mutex is really reserved when critical code is entered.
       
   153 EAP_FUNC_EXPORT bool eap_am_mutex_symbian_c::get_is_reserved() const
       
   154 {
       
   155 	// In Symbian we need this object to test reference flag,
       
   156 	// because each thread has own duplicated mutex object.
       
   157 	return get_reference()->get_is_reserved();
       
   158 }
       
   159 
       
   160 //--------------------------------------------------
       
   161 
       
   162 //
       
   163 EAP_FUNC_EXPORT bool eap_am_mutex_symbian_c::get_is_valid() const
       
   164 {
       
   165 	return m_is_valid;
       
   166 }
       
   167 
       
   168 //--------------------------------------------------
       
   169 
       
   170 
       
   171 
       
   172 // End of file