我有以下标题:
#if !defined(_SPIN_LOCK_H_INCLUDED_)
#define _SPIN_LOCK_H_INCLUDED_
#include <windows.h>
class spin_lock
{
public:
spin_lock();
virtual ~spin_lock();
void lock( void );
void unlock( void );
private:
CRITICAL_SECTION m_lock;
spin_lock( const spin_lock& that );
const spin_lock& operator = ( const spin_lock& that );
};
有可能在Linux上以最小的更改移植它吗?
我发表评论后发现此错误:
在../sources/utils.11.0/MyPDFLibUtils.cpp:43:0中包含的文件中: ../sources/utils.11.0/spin_lock.h:39:2:错误:'CRITICAL_SECTION'没有命名类型 CRITICAL_SECTION m_lock;
CRITICAL_SECTION在Microsoft SDK的WinBase.h部分中声明
这是实施:
#include <windows.h>
#include "spin_lock.h"
spin_lock::spin_lock()
{
::InitializeCriticalSection( &m_lock );
}
spin_lock::~spin_lock()
{
::DeleteCriticalSection( &m_lock );
}
void spin_lock::lock( void )
{
::EnterCriticalSection( &m_lock );
}
void spin_lock:: unlock( void )
{
::LeaveCriticalSection( &m_lock );
}