Raised This Month: $32 Target: $400
 8% 

amxmodx not support dual Thread???


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
201724
Member
Join Date: May 2011
Old 12-28-2011 , 10:35   amxmodx not support dual Thread???
Reply With Quote #1


my write one modules, createthread running amxx code
but use the my dual thread modules ,amxx running error


the code:
Code:
 
#include "amxxmodule.h"
#include <windows.h>
typedef struct ThreadParam
{
 int fwd;
 LPVOID data_addr;
 int DataLen;
}ThreadParam,*lpThreadParam;
typedef HANDLE (__stdcall * fnOpenThread)
(
  DWORD dwDesiredAccess,  // access right
  BOOL bInheritHandle,    // handle inheritance option
  DWORD dwThreadId        // thread identifier
);
fnOpenThread OpenThread;
HANDLE g_MainThreadHandle;
//------------------------Params---------------------------------
lpThreadParam AllocParam()
{
 return (lpThreadParam)VirtualAlloc(0,sizeof(ThreadParam),MEM_COMMIT,PAGE_EXECUTE_READWRITE);
}
void FreeParam(lpThreadParam lpAddress)
{
 VirtualFree(lpAddress,sizeof(ThreadParam),MEM_DECOMMIT);
}
void* AllocData(int amxLen)
{
 return VirtualAlloc(0,(amxLen+1)*4,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
}
void FreeData(void* lpAddress,int amxLen)
{
 VirtualFree(lpAddress,(amxLen+1)*4,MEM_DECOMMIT);
}
int ReisgerFwd(AMX* amx,const char* handler)
{
 return MF_RegisterSPForwardByName(amx, handler, FP_ARRAY, FP_CELL,FP_DONE);
}
cell MakeData(void* DataAddr,int DataLen)
{
 return MF_PrepareCellArray((cell*)DataAddr,DataLen);
}
//-----------------------------EndParams---------------------------------
//-----------------------------NParams-----------------------------------
int ReisgerNFwd(AMX* amx,const char* handler)
{
 return MF_RegisterSPForwardByName(amx, handler,FP_DONE);
}
//-----------------------------EndNparams---------------------------------
VOID ThreadNParamCall(int fwd)
{
 SuspendThread(g_MainThreadHandle);
 MF_ExecuteForward(fwd);
 MF_UnregisterSPForward(fwd);
 ResumeThread(g_MainThreadHandle);
}
static cell AMX_NATIVE_CALL ThreadExec(AMX *amx, cell *params)
{
 int m_dwHandlerLen ;
 char* m_handler = MF_GetAmxString(amx,params[1],0,&m_dwHandlerLen);
 int fwd = ReisgerNFwd(amx,m_handler);
 if(fwd)
 {
  HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadNParamCall,(void*)fwd,0,NULL);
  SetThreadPriority(hThread,REALTIME_PRIORITY_CLASS);
  return (cell)hThread;
 }else
 {
  MF_UnregisterSPForward(fwd);
 }
 return -1;
}
//Use Param Call
VOID ThreadParamCall(lpThreadParam c_lpParam)
{
 cell data_addr = MakeData(c_lpParam->data_addr,c_lpParam->DataLen);
 MF_ExecuteForward(c_lpParam->fwd,data_addr,c_lpParam->DataLen);
 MF_UnregisterSPForward(c_lpParam->fwd);
 FreeData(c_lpParam->data_addr,c_lpParam->DataLen);
 FreeParam(c_lpParam);
}
static cell AMX_NATIVE_CALL ParamThread(AMX *amx, cell *params) 
{
 int m_dwHandlerLen ;
 char* m_handler = MF_GetAmxString(amx,params[1],0,&m_dwHandlerLen);
 lpThreadParam m_lpParam = AllocParam();
 m_lpParam->data_addr = AllocData(params[3]);
 m_lpParam->fwd = ReisgerFwd(amx,m_handler);
 if(m_lpParam->fwd)
 {
  memcpy(m_lpParam->data_addr,MF_GetAmxAddr(amx,params[2]),params[3]*4);
  m_lpParam->DataLen = params[3];
  HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadParamCall,m_lpParam,CREATE_SUSPENDED,NULL);
  SetThreadPriority(hThread,NORMAL_PRIORITY_CLASS);
  return (cell)hThread;
 }else
 {
  MF_UnregisterSPForward(m_lpParam->fwd);
  FreeData(m_lpParam->data_addr,params[3]);
  FreeParam(m_lpParam);
 }
 return -1;
}
static cell AMX_NATIVE_CALL API_Sleep(AMX *amx, cell *params) 
{
 Sleep(params[1]);
 return 1;
}
static cell AMX_NATIVE_CALL nv_TerminateThread(AMX *amx, cell *params)
{
 return TerminateThread((HANDLE)params[1],0);
}
static cell AMX_NATIVE_CALL nv_ResumeThread(AMX *amx,cell *params)
{
 return ResumeThread((HANDLE)params[1]);
}
AMX_NATIVE_INFO thread_ext[] = {
 {"ThreadExec",ThreadExec},
 {"ParamThread",ParamThread},
 {"TerminateThread",nv_TerminateThread},
 {"ResumeThread",nv_ResumeThread},
 {NULL,NULL}
};
void OnAmxxAttach()
{
 MF_AddNatives(thread_ext);
 OpenThread = (fnOpenThread)GetProcAddress(GetModuleHandle("kernel32.dll"),"OpenThread");
 g_MainThreadHandle = OpenThread(THREAD_ALL_ACCESS,FALSE,GetCurrentThreadId());
}
VOID OnAmxxDetach()
{
 CloseHandle(g_MainThreadHandle);
}
201724 is offline
Send a message via MSN to 201724
201724
Member
Join Date: May 2011
Old 12-28-2011 , 10:36   Re: amxmodx not support dual Thread???
Reply With Quote #2

OpenThread and SuspendThread and ResumeThread is my test add....

delete the 3 api amxx runtime error..
201724 is offline
Send a message via MSN to 201724
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-28-2011 , 14:55   Re: amxmodx not support dual Thread???
Reply With Quote #3

HLDS is not threaded and therefore AMX Mod X is also not threaded. You do realize that Half-Life is an ancient game right?
__________________

Last edited by fysiks; 12-28-2011 at 14:56.
fysiks is offline
201724
Member
Join Date: May 2011
Old 12-29-2011 , 02:39   Re: amxmodx not support dual Thread???
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
HLDS is not threaded and therefore AMX Mod X is also not threaded. You do realize that Half-Life is an ancient game right?

half-life and metamod dual thread call engine no problem ...
but only amxmodx dual thread bugs..
Should be accurate to say that amxmodx in the case of multi-threaded amxx plugins will appear inexplicable error

Last edited by 201724; 12-29-2011 at 02:43.
201724 is offline
Send a message via MSN to 201724
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 12-31-2011 , 00:53   Re: amxmodx not support dual Thread???
Reply With Quote #5

even srcds is single threaded, therefore the 64 slots server owner need to overclock theyre CPU in order to have smooth gameplay @ 40 players+
DjOptimuS is offline
sparky99
Junior Member
Join Date: Jan 2006
Old 12-31-2011 , 01:32   Re: amxmodx not support dual Thread???
Reply With Quote #6

Wasn't there a module for amx 2006 that enabled threads?
I'm pretty sure there was.

Last edited by sparky99; 12-31-2011 at 01:33.
sparky99 is offline
DjOptimuS
Senior Member
Join Date: Jan 2009
Old 12-31-2011 , 01:38   Re: amxmodx not support dual Thread???
Reply With Quote #7

@sparky99 - You confuse with the x64 module
DjOptimuS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode