mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-08 02:48:34 +00:00
Swapped out STL items with AMTL counterparts
This commit is contained in:
parent
a75627e048
commit
67659bf657
@ -577,7 +577,7 @@ void HTTPSessionManager::PluginUnloaded(IPlugin *plugin)
|
|||||||
if (!requests.empty())
|
if (!requests.empty())
|
||||||
{
|
{
|
||||||
// Run through requests queue
|
// Run through requests queue
|
||||||
for (std::deque<HTTPRequest>::iterator i(requests.begin()), end(requests.end()); i != end; ++i)
|
for (Queue<HTTPRequest>::iterator i(requests.begin()), end(requests.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
// Identify requests associated to (nearly) unmapped plugin context
|
// Identify requests associated to (nearly) unmapped plugin context
|
||||||
if (i->pCtx == plugin->GetBaseContext())
|
if (i->pCtx == plugin->GetBaseContext())
|
||||||
@ -595,7 +595,8 @@ void HTTPSessionManager::PluginUnloaded(IPlugin *plugin)
|
|||||||
// Wait for running requests to finish
|
// Wait for running requests to finish
|
||||||
if (!threads.empty())
|
if (!threads.empty())
|
||||||
{
|
{
|
||||||
for (std::list<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
//for (std::list<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
||||||
|
for (ke::LinkedList<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
if ((*i) != NULL)
|
if ((*i) != NULL)
|
||||||
{
|
{
|
||||||
@ -611,7 +612,9 @@ void HTTPSessionManager::PluginUnloaded(IPlugin *plugin)
|
|||||||
if (!callbacks.empty())
|
if (!callbacks.empty())
|
||||||
{
|
{
|
||||||
// Run through callback queue
|
// Run through callback queue
|
||||||
for (std::deque<HTTPRequest>::iterator i(callbacks.begin()), end(callbacks.end()); i != end; ++i)
|
//for (std::deque<HTTPRequest>::iterator i(callbacks.begin()), end(callbacks.end()); i != end; ++i)
|
||||||
|
//for (ke::LinkedList<HTTPRequest>::iterator i(callbacks.begin()), end(callbacks.end()); i != end; ++i)
|
||||||
|
for (Queue<HTTPRequest>::iterator i(callbacks.begin()), end(callbacks.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
// Identify callbacks associated to (nearly) unmapped plugin context
|
// Identify callbacks associated to (nearly) unmapped plugin context
|
||||||
if (i->pCtx == plugin->GetBaseContext())
|
if (i->pCtx == plugin->GetBaseContext())
|
||||||
@ -644,7 +647,7 @@ void HTTPSessionManager::PostAndDownload(IPluginContext *pCtx,
|
|||||||
request.contextPack = contextPack;
|
request.contextPack = contextPack;
|
||||||
|
|
||||||
pRequestsLock->Lock();
|
pRequestsLock->Lock();
|
||||||
this->requests.push_front(request);
|
this->requests.push(request);
|
||||||
pRequestsLock->Unlock();
|
pRequestsLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,7 +665,7 @@ void HTTPSessionManager::Download(IPluginContext *pCtx,
|
|||||||
request.contextPack = contextPack;
|
request.contextPack = contextPack;
|
||||||
|
|
||||||
pRequestsLock->Lock();
|
pRequestsLock->Lock();
|
||||||
this->requests.push_front(request);
|
this->requests.push(request);
|
||||||
pRequestsLock->Unlock();
|
pRequestsLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,7 +696,7 @@ void HTTPSessionManager::RunFrame()
|
|||||||
{
|
{
|
||||||
if (!this->callbacks.empty())
|
if (!this->callbacks.empty())
|
||||||
{
|
{
|
||||||
HTTPRequest request = this->callbacks.front();
|
HTTPRequest request = this->callbacks.first();
|
||||||
IPluginContext *pCtx = request.pCtx;
|
IPluginContext *pCtx = request.pCtx;
|
||||||
|
|
||||||
// Is the requesting plugin still alive?
|
// Is the requesting plugin still alive?
|
||||||
@ -716,7 +719,7 @@ void HTTPSessionManager::RunFrame()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->callbacks.pop_front();
|
this->callbacks.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->pCallbacksLock->Unlock();
|
this->pCallbacksLock->Unlock();
|
||||||
@ -738,18 +741,19 @@ void HTTPSessionManager::RunFrame()
|
|||||||
{
|
{
|
||||||
// Create new thread object
|
// Create new thread object
|
||||||
HTTPAsyncRequestHandler *async =
|
HTTPAsyncRequestHandler *async =
|
||||||
new HTTPAsyncRequestHandler(this->requests.front());
|
new HTTPAsyncRequestHandler(this->requests.first());
|
||||||
// Skip requests with unloaded parent plugin
|
// Skip requests with unloaded parent plugin
|
||||||
if (this->requests.front().pCtx != NULL)
|
if (this->requests.first().pCtx != NULL)
|
||||||
{
|
{
|
||||||
// Create new thread
|
// Create new thread
|
||||||
IThreadHandle *pThread =
|
IThreadHandle *pThread =
|
||||||
threader->MakeThread(async, Thread_Default);
|
threader->MakeThread(async, Thread_Default);
|
||||||
// Save thread handle
|
// Save thread handle
|
||||||
this->threads.push_front(pThread);
|
//this->threads.push_front(pThread);
|
||||||
|
this->threads.append(pThread);
|
||||||
}
|
}
|
||||||
// Remove request as it's being handled now
|
// Remove request as it's being handled now
|
||||||
this->requests.pop_front();
|
this->requests.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -768,10 +772,7 @@ void HTTPSessionManager::Initialize()
|
|||||||
void HTTPSessionManager::Shutdown()
|
void HTTPSessionManager::Shutdown()
|
||||||
{
|
{
|
||||||
// Block until all running threads have finished
|
// Block until all running threads have finished
|
||||||
while (!this->threads.empty())
|
|
||||||
{
|
|
||||||
this->RemoveFinishedThreads();
|
this->RemoveFinishedThreads();
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy all remaining callback calls
|
// Destroy all remaining callback calls
|
||||||
this->pCallbacksLock->Lock();
|
this->pCallbacksLock->Lock();
|
||||||
@ -792,7 +793,8 @@ void HTTPSessionManager::Shutdown()
|
|||||||
void HTTPSessionManager::AddCallback(HTTPRequest request)
|
void HTTPSessionManager::AddCallback(HTTPRequest request)
|
||||||
{
|
{
|
||||||
this->pCallbacksLock->Lock();
|
this->pCallbacksLock->Lock();
|
||||||
this->callbacks.push_front(request);
|
//this->callbacks.push_front(request);
|
||||||
|
this->callbacks.push(request);
|
||||||
this->pCallbacksLock->Unlock();
|
this->pCallbacksLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,17 +803,15 @@ void HTTPSessionManager::RemoveFinishedThreads()
|
|||||||
// Do some quick "garbage collection" on finished threads
|
// Do some quick "garbage collection" on finished threads
|
||||||
if (!this->threads.empty())
|
if (!this->threads.empty())
|
||||||
{
|
{
|
||||||
for (std::list<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
//for (std::list<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
||||||
|
for (ke::LinkedList<IThreadHandle*>::iterator i(threads.begin()), end(threads.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
if ((*i) != NULL)
|
if ((*i) != NULL)
|
||||||
{
|
{
|
||||||
if ((*i)->GetState() == Thread_Done)
|
if ((*i)->GetState() == Thread_Done)
|
||||||
{
|
{
|
||||||
(*i)->DestroyThis();
|
(*i)->DestroyThis();
|
||||||
this->threads.remove((*i));
|
i = this->threads.erase(i);
|
||||||
// NOTE: this action breaks the iteration so we have
|
|
||||||
// to leave the loop and start over on next frame
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,8 +40,8 @@
|
|||||||
#include "smsdk_ext.h"
|
#include "smsdk_ext.h"
|
||||||
#include "IWebternet.h"
|
#include "IWebternet.h"
|
||||||
#include "IBaseDownloader.h"
|
#include "IBaseDownloader.h"
|
||||||
#include <queue>
|
#include <amtl/am-linkedlist.h>
|
||||||
#include <list>
|
#include <sm_queue.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,6 +229,10 @@ private:
|
|||||||
const char *url;
|
const char *url;
|
||||||
HTTPRequestCompletedContextPack contextPack;
|
HTTPRequestCompletedContextPack contextPack;
|
||||||
cell_t result;
|
cell_t result;
|
||||||
|
bool operator==(const HTTPRequest& lhs) const
|
||||||
|
{
|
||||||
|
return !memcmp(&lhs, this, sizeof(HTTPRequest));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void RemoveFinishedThreads();
|
void RemoveFinishedThreads();
|
||||||
@ -236,11 +240,14 @@ private:
|
|||||||
|
|
||||||
static const unsigned int iMaxRequestsPerFrame = 20;
|
static const unsigned int iMaxRequestsPerFrame = 20;
|
||||||
IMutex *pRequestsLock;
|
IMutex *pRequestsLock;
|
||||||
std::deque<HTTPRequest> requests;
|
Queue<HTTPRequest> requests;
|
||||||
// NOTE: this needs no lock since it's only accessed from main thread
|
// NOTE: this needs no lock since it's only accessed from main thread
|
||||||
std::list<IThreadHandle*> threads;
|
//std::list<IThreadHandle*> threads;
|
||||||
|
ke::LinkedList<IThreadHandle*> threads;
|
||||||
IMutex *pCallbacksLock;
|
IMutex *pCallbacksLock;
|
||||||
std::deque<HTTPRequest> callbacks;
|
//std::deque<HTTPRequest> callbacks;
|
||||||
|
//ke::LinkedList<HTTPRequest> callbacks;
|
||||||
|
Queue<HTTPRequest> callbacks;
|
||||||
|
|
||||||
class HTTPAsyncRequestHandler : public IThread
|
class HTTPAsyncRequestHandler : public IThread
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user