mirror of
https://github.com/ChronosX88/mta-mono.git
synced 2024-11-22 10:12:20 +00:00
Осталось от модуля из примера
This commit is contained in:
parent
7758538bf0
commit
7a155160f8
@ -1,134 +0,0 @@
|
|||||||
/*********************************************************
|
|
||||||
*
|
|
||||||
* Multi Theft Auto: San Andreas - Deathmatch
|
|
||||||
*
|
|
||||||
* ml_base, External lua add-on module
|
|
||||||
*
|
|
||||||
* Copyright © 2003-2008 MTA. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Grand Theft Auto is © 2002-2003 Rockstar North
|
|
||||||
*
|
|
||||||
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
|
|
||||||
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
|
|
||||||
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
|
|
||||||
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
|
|
||||||
* PROVIDED WITH THIS PACKAGE.
|
|
||||||
*
|
|
||||||
*********************************************************/
|
|
||||||
|
|
||||||
#include "CThread.h"
|
|
||||||
|
|
||||||
CThread::CThread ( void )
|
|
||||||
{
|
|
||||||
m_pThreadData = NULL;
|
|
||||||
m_pArg = NULL;
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
m_hThread = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CThread::~CThread ( void )
|
|
||||||
{
|
|
||||||
Stop ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CThread::Start ( CThreadData *pData )
|
|
||||||
{
|
|
||||||
if ( pData == NULL ) // pData HAS to be valid
|
|
||||||
return false;
|
|
||||||
|
|
||||||
Stop ();
|
|
||||||
Arg ( pData );
|
|
||||||
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
m_hThread = CreateThread ( NULL, 0, &CThread::EntryPoint, this, 0, NULL );
|
|
||||||
return m_hThread != NULL;
|
|
||||||
#else // POSIX threads
|
|
||||||
if ( pthread_create ( &m_hThread, NULL, CThread::EntryPoint, this ) )
|
|
||||||
{
|
|
||||||
// something bad happened
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CThread::Stop ( void )
|
|
||||||
{
|
|
||||||
if ( m_hThread )
|
|
||||||
{
|
|
||||||
// TerminateThread ( m_hThread, 0 );
|
|
||||||
if ( m_pThreadData != NULL )
|
|
||||||
m_pThreadData->bAbortThread = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CThread::TryLock ( ThreadMutex * Mutex )
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
if ( TryEnterCriticalSection ( Mutex ) != 0 )
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
if ( pthread_mutex_trylock ( Mutex ) == 0 )
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CThread::Lock ( ThreadMutex * Mutex )
|
|
||||||
{
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
EnterCriticalSection ( Mutex );
|
|
||||||
#else // POSIX threads
|
|
||||||
pthread_mutex_lock ( Mutex );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CThread::Unlock ( ThreadMutex * Mutex )
|
|
||||||
{
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
LeaveCriticalSection ( Mutex );
|
|
||||||
#else // POSIX threads
|
|
||||||
pthread_mutex_unlock ( Mutex );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int CThread::Run ( CThreadData* arg )
|
|
||||||
{
|
|
||||||
return Execute ( arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
DWORD CThread::EntryPoint ( void* pThis )
|
|
||||||
{
|
|
||||||
CThread* pt = (CThread*)pThis;
|
|
||||||
return pt->Run ( pt->Arg () );
|
|
||||||
}
|
|
||||||
#else // POSIX threads
|
|
||||||
void* CThread::EntryPoint ( void* pThis )
|
|
||||||
{
|
|
||||||
CThread* pt = (CThread*)pThis;
|
|
||||||
pt->Run ( pt->Arg () );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
CThreadData* CThread::Arg ( void ) const
|
|
||||||
{
|
|
||||||
return m_pThreadData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CThread::Arg ( CThreadData* pData )
|
|
||||||
{
|
|
||||||
m_pThreadData = pData;
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
/*********************************************************
|
|
||||||
*
|
|
||||||
* Multi Theft Auto: San Andreas - Deathmatch
|
|
||||||
*
|
|
||||||
* ml_base, External lua add-on module
|
|
||||||
*
|
|
||||||
* Copyright © 2003-2008 MTA. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Grand Theft Auto is © 2002-2003 Rockstar North
|
|
||||||
*
|
|
||||||
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
|
|
||||||
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
|
|
||||||
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
|
|
||||||
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
|
|
||||||
* PROVIDED WITH THIS PACKAGE.
|
|
||||||
*
|
|
||||||
*********************************************************/
|
|
||||||
|
|
||||||
/** And remember.. threads on Win32 and POSIX are not similar at all. **/
|
|
||||||
|
|
||||||
#ifndef __CTHREAD_H
|
|
||||||
#define __CTHREAD_H
|
|
||||||
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
#define _WIN32_WINNT 0x400
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
typedef HANDLE ThreadHandle;
|
|
||||||
typedef CRITICAL_SECTION ThreadMutex;
|
|
||||||
#else // POSIX threads
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
typedef pthread_t ThreadHandle;
|
|
||||||
typedef pthread_mutex_t ThreadMutex;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "CThreadData.h"
|
|
||||||
|
|
||||||
// Base thread class
|
|
||||||
class CThread
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CThread ( void );
|
|
||||||
virtual ~CThread ( void );
|
|
||||||
|
|
||||||
bool Start ( CThreadData *pData );
|
|
||||||
void Stop ( void );
|
|
||||||
|
|
||||||
static bool TryLock ( ThreadMutex * Mutex );
|
|
||||||
static void Lock ( ThreadMutex * Mutex );
|
|
||||||
static void Unlock ( ThreadMutex * Mutex );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int Run ( CThreadData* arg );
|
|
||||||
|
|
||||||
virtual int Execute ( CThreadData* pData ) = 0;
|
|
||||||
|
|
||||||
CThreadData* Arg ( void ) const;
|
|
||||||
void Arg ( CThreadData* pData );
|
|
||||||
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
static DWORD WINAPI EntryPoint ( void* );
|
|
||||||
#else // POSIX threads
|
|
||||||
static void* EntryPoint ( void* );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
void* m_pArg;
|
|
||||||
CThreadData* m_pThreadData;
|
|
||||||
ThreadHandle m_hThread;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||||||
/*********************************************************
|
|
||||||
*
|
|
||||||
* Multi Theft Auto: San Andreas - Deathmatch
|
|
||||||
*
|
|
||||||
* ml_base, External lua add-on module
|
|
||||||
*
|
|
||||||
* Copyright © 2003-2008 MTA. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Grand Theft Auto is © 2002-2003 Rockstar North
|
|
||||||
*
|
|
||||||
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
|
|
||||||
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
|
|
||||||
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
|
|
||||||
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
|
|
||||||
* PROVIDED WITH THIS PACKAGE.
|
|
||||||
*
|
|
||||||
*********************************************************/
|
|
||||||
|
|
||||||
#include "CThreadData.h"
|
|
||||||
|
|
||||||
CThreadData::CThreadData ( void )
|
|
||||||
{
|
|
||||||
bAbortThread = false;
|
|
||||||
|
|
||||||
// Initialize the mutexes
|
|
||||||
#ifdef WIN32 // Win32 threads
|
|
||||||
InitializeCriticalSection ( &MutexPrimary );
|
|
||||||
InitializeCriticalSection ( &MutexLogical );
|
|
||||||
#else // POSIX threads
|
|
||||||
pthread_mutex_init ( &MutexPrimary, NULL );
|
|
||||||
pthread_mutex_init ( &MutexLogical, NULL );
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
CThreadData::~CThreadData ( void )
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
DeleteCriticalSection ( &MutexPrimary );
|
|
||||||
DeleteCriticalSection ( &MutexLogical );
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*********************************************************
|
|
||||||
*
|
|
||||||
* Multi Theft Auto: San Andreas - Deathmatch
|
|
||||||
*
|
|
||||||
* ml_base, External lua add-on module
|
|
||||||
*
|
|
||||||
* Copyright © 2003-2008 MTA. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Grand Theft Auto is © 2002-2003 Rockstar North
|
|
||||||
*
|
|
||||||
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
|
|
||||||
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
|
|
||||||
* OPEN SOURCE FILES. THESE FILES MAY BE USED AS LONG
|
|
||||||
* AS THE DEVELOPER AGREES TO THE LICENSE THAT IS
|
|
||||||
* PROVIDED WITH THIS PACKAGE.
|
|
||||||
*
|
|
||||||
*********************************************************/
|
|
||||||
|
|
||||||
class CThreadData;
|
|
||||||
|
|
||||||
#ifndef __CTHREADDATA_H
|
|
||||||
#define __CTHREADDATA_H
|
|
||||||
|
|
||||||
#include "CThread.h"
|
|
||||||
|
|
||||||
class CThreadData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CThreadData ( void );
|
|
||||||
~CThreadData ( void );
|
|
||||||
|
|
||||||
bool bAbortThread;
|
|
||||||
ThreadMutex MutexPrimary; // primary mutex for suspend/resume operations
|
|
||||||
ThreadMutex MutexLogical; // logical mutex for proper CThreadData sync
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user