⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutex.cpp

📁 Jabber code library, developed with c
💻 CPP
字号:
/*  Copyright (c) 2007-2008 by Jakob Schroeter <js@camaya.net>  This file is part of the gloox library. http://camaya.net/gloox  This software is distributed under a license. The full license  agreement can be found in the file LICENSE in this distribution.  This software may not be copied, modified, sold or distributed  other than expressed in the named license agreement.  This software is distributed without any warranty.*/#include "mutex.h"#if !defined( _WIN32 ) && !defined( _WIN32_WCE )# include "config.h"#endif#ifdef _WIN32# include <windows.h>#endif#ifdef _WIN32_WCE# include <winbase.h>#endif#ifdef HAVE_PTHREAD# include <pthread.h>#endifnamespace gloox{  class MutexImpl  {    public:      MutexImpl();      ~MutexImpl();      void lock();      void unlock();    private:      MutexImpl( const MutexImpl& );      MutexImpl& operator=( const MutexImpl& );#ifdef _WIN32      CRITICAL_SECTION m_cs;#elif defined( HAVE_PTHREAD )      pthread_mutex_t m_mutex;#endif  };  MutexImpl::MutexImpl()  {#ifdef _WIN32    InitializeCriticalSection( &m_cs );#elif defined( HAVE_PTHREAD )    pthread_mutex_init( &m_mutex, 0 );#endif  }  MutexImpl::~MutexImpl()  {#ifdef _WIN32    DeleteCriticalSection( &m_cs );#elif defined( HAVE_PTHREAD )    pthread_mutex_destroy( &m_mutex );#endif  }  void MutexImpl::lock()  {#ifdef _WIN32    EnterCriticalSection( &m_cs );#elif defined( HAVE_PTHREAD )    pthread_mutex_lock( &m_mutex );#endif  }  void MutexImpl::unlock()  {#ifdef _WIN32    LeaveCriticalSection( &m_cs );#elif defined( HAVE_PTHREAD )    pthread_mutex_unlock( &m_mutex );#endif  }  Mutex::Mutex()    : m_mutex( new MutexImpl() )  {  }  Mutex::~Mutex()  {    delete m_mutex;  }  void Mutex::lock()  {    m_mutex->lock();  }  void Mutex::unlock()  {    m_mutex->unlock();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -