genericopenlibs/openenvcore/libpthread/src/pthread_mutex_destroy.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : pthread_mutex_destroy.cpp
       
    15 // Part of     : pthread
       
    16 // Interface   : POSIX, pthread
       
    17 // POSIX implementation of mutexes on Symbian
       
    18 // Version     :
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 #include "mutextypes.h"
       
    24 
       
    25 EXPORT_C int pthread_mutex_destroy (pthread_mutex_t * mutex)
       
    26 {
       
    27 
       
    28     if(!mutex)
       
    29     {
       
    30         return EINVAL;
       
    31     }
       
    32 
       
    33     if(mutex->iState == _EDestroyed)
       
    34     {
       
    35         return EINVAL;
       
    36     }
       
    37 
       
    38     if(mutex->iState != _EInitialized)
       
    39     {
       
    40         return 0;
       
    41     }
       
    42 
       
    43     _pthread_mutex_t* pMutex = mutex->iPtr;
       
    44 
       
    45     if(pMutex->iDataLock.IsHeld())
       
    46     {
       
    47         return EBUSY;
       
    48     }
       
    49 
       
    50     pMutex->iDataLock.Wait();
       
    51     if(pMutex->iSemaphoreState != SEM_FREE)
       
    52     {
       
    53         pMutex->iDataLock.Signal();
       
    54         return EBUSY;
       
    55     }
       
    56 
       
    57     mutex->iState = _EDestroyed;
       
    58     pMutex->iDataLock.Signal();
       
    59     _closeMutex(mutex);
       
    60     return 0;
       
    61 }
       
    62 
       
    63 
       
    64 // End of File