Changeset 38 in cheroxy for trunk/src/CRXMutex.cpp


Ignore:
Timestamp:
11/21/12 09:23:50 (11 years ago)
Author:
cheese
Message:

#1 more mutex interface and add debugging code to check connection port number

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CRXMutex.cpp

    r12 r38  
    33
    44CRXMutex::CRXMutex (void)
     5    : mIsCreated (false),
     6#ifdef _WIN32
     7      mMutex (NULL)
     8#endif
    59{
    6 #ifdef _WIN32
    7     mMutex = NULL;
    8 #endif
     10    /*----------------------------------------------------------------*/
     11    /*----------------------------------------------------------------*/
    912}
    1013
    1114CRXMutex::~CRXMutex (void)
    1215{
     16    /*----------------------------------------------------------------*/
    1317    this->Unlock ();
    1418    this->Destroy ();
    15 #ifdef _WIN32
    16 #else
    17 #endif
     19    /*----------------------------------------------------------------*/
    1820}
    1921
    20 int CRXMutex::Create (void)
     22bool
     23CRXMutex::IsCreated (void) const
    2124{
     25    /*----------------------------------------------------------------*/
     26    /*----------------------------------------------------------------*/
     27
     28    return mIsCreated;
     29}
     30
     31int
     32CRXMutex::Create (void)
     33{
     34    int     aResult = 0;
     35
     36    /*----------------------------------------------------------------*/
    2237#ifdef _WIN32
    2338    if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL)
    24         return GetLastError ();
    25     else
    26         return 0;
     39        aResult = GetLastError ();
    2740#else
    28     return pthread_mutex_init (&mMutex, NULL);
     41    aResult = pthread_mutex_init (&mMutex, NULL);
    2942#endif
     43
     44    mIsCreated = true;
     45    /*----------------------------------------------------------------*/
     46
     47    return aResult;
    3048}
    3149
    32 int CRXMutex::Destroy (void)
     50int
     51CRXMutex::Destroy (void)
    3352{
     53    int     aResult = 0;
     54
     55    /*----------------------------------------------------------------*/
    3456#ifdef _WIN32
    3557    if (::CloseHandle (mMutex))
    36         return GetLastError ();
    37     else
    38         return 0;
     58        aResult = GetLastError ();
    3959#else
    40     return pthread_mutex_destroy (&mMutex);
     60    aResult = pthread_mutex_destroy (&mMutex);
    4161#endif
     62
     63    mIsCreated = false;
     64    /*----------------------------------------------------------------*/
     65
     66    return aResult;
    4267}
    4368
    44 void CRXMutex::Lock (void)
     69void
     70CRXMutex::Lock (void)
    4571{
     72    /*----------------------------------------------------------------*/
    4673#ifdef _WIN32
    4774    ::WaitForSingleObject (mMutex, INFINITE);
     
    4976    pthread_mutex_lock (&mMutex);
    5077#endif
     78    /*----------------------------------------------------------------*/
    5179}
    5280
    53 void CRXMutex::Unlock (void)
     81void
     82CRXMutex::Unlock (void)
    5483{
     84    /*----------------------------------------------------------------*/
    5585#ifdef _WIN32
    5686    if (mMutex != NULL)
     
    5989    pthread_mutex_unlock (&mMutex);
    6090#endif
     91    /*----------------------------------------------------------------*/
    6192}
Note: See TracChangeset for help on using the changeset viewer.