// Include #include "gamesrv.h" #include "playernamepool.h" // Local definitions // Global data cPlayerNamePool* cPlayerNamePool::mpPlayerNamePool = NULL; // PlayerNameCmpWChar Prototype int WINAPI PlayerNameCmpWChar(void* arg1, void* arg2) { return wcscmp( ((PerPlayerName*)arg1)->name, ((PerPlayerName*)arg2)->name ); } // PlayerNameCmpValue Prototype int WINAPI PlayerNameCmpValue(void* arg1, void* arg2) { return wcscmp( ((PerPlayerName*)arg1)->name, (wchar_t*)arg2 ); } // cPlayerNamePool Constructor cPlayerNamePool::cPlayerNamePool( ) { // Global Variable mpPlayerNamePool = this; // Pool Usage Pointer mNonPagedPoolUsage = NULL; mPlayerNameRoot.pool = NULL; mPlayerNameRoot.root = NULL; } // ~cPlayerNamePool Destructor. cPlayerNamePool::~cPlayerNamePool(void) { // cPlayerNamePool¸¦ ÇØÁ¦. Shutdown(); // Global Variable mpPlayerNamePool = NULL; } // Shutdown Method void cPlayerNamePool::Shutdown() { PerPlayerName* temp; // Pool Usage Shutdown - NonPagedPoolUsage while ( mNonPagedPoolUsage != NULL ) { temp = mNonPagedPoolUsage; mNonPagedPoolUsage = (PerPlayerName*)mNonPagedPoolUsage->next; MEMORY_POOL->FreeNode( (void**)&temp ); } } // Search Method PerPlayerName* cPlayerNamePool::Search(wchar_t* name) { return (PerPlayerName*)MEMORY_POOL->SearchNode( &mPlayerNameRoot, name, &PlayerNameCmpValue ); } // GetPlayerName Method - ¼±Çü¸®½ºÆ®ÀÇ HEAD¸¦ ³Ñ°ÜÁØ´Ù. // ReleasePlayerName¿Í ÇÔ²² LIFO¸¦ ÀÌ·é´Ù. LIFO´Â Context Switching¸¦ ÃÖ¼ÒÈ­ Çϱâ À§ÇØ »ç¿ë PerPlayerName* cPlayerNamePool::GetPlayerName(ULONG connectionIdx, ULONG characterIdx, wchar_t* name) { PerPlayerName* perPlayerName = (PerPlayerName*)MEMORY_POOL->GetPool( (PerNode**)&mNonPagedPoolUsage, sizeof(PerPlayerName) ); if ( perPlayerName ) { perPlayerName->connectionIdx = connectionIdx; perPlayerName->characterIdx = characterIdx; wcscpy( perPlayerName->name, name ); // BST-¿¬°á½Ãµµ. if ( MEMORY_POOL->AttachBst( &mPlayerNameRoot.root, perPlayerName, PlayerNameCmpWChar ) ) { MEMORY_POOL->AttachPool( (PerNode**)&mPlayerNameRoot.pool, perPlayerName ); return perPlayerName; // ¿¬°á¼º°ø. } else { MEMORY_POOL->AttachPool( (PerNode**)&mNonPagedPoolUsage, perPlayerName ); return NULL; // ¿¬°á½ÇÆÐ. } } return perPlayerName; } // ReleasePlayerName Method - ¼±Çü¸®½ºÆ®ÀÇ HEAD·Î ȸ¼öÇÑ´Ù. // GetPlayerName¿Í ÇÔ²² LIFO¸¦ ÀÌ·é´Ù. LIFO´Â Context Switching¸¦ ÃÖ¼ÒÈ­ Çϱâ À§ÇØ »ç¿ë void cPlayerNamePool::ReleasePlayerName(PerPlayerName* perPlayerName) { // BST - ¿¬°áÁ¾·á. MEMORY_POOL->DetachBst( (PerNode**)&mPlayerNameRoot.root, (PerNode*)perPlayerName ); // ÆäÀÌÁö µÈ Ç® »ç¿ë·®À» Â÷°¨. MEMORY_POOL->DetachPool( (PerNode**)&mPlayerNameRoot.pool, (PerNode*)perPlayerName ); // ÆäÀÌÁö ¾ÈµÈ Ç® »ç¿ë·®À» Áõ°¨. MEMORY_POOL->ReleasePool( (PerNode**)&mNonPagedPoolUsage, (PerNode*)perPlayerName ); }