// Include #include "gamesrv.h" #include "itembillpool.h" // Local definitions // Global data cItemBillPool* cItemBillPool::mpItemBillPool = NULL; // ItemBillCmpIndex Prototype int WINAPI ItemBillCmpIndex(void* arg1, void* arg2) { return ((PerItemBill*)arg1)->inventoryIdx - ((PerItemBill*)arg2)->inventoryIdx; } // ItemBillCmpValue Prototype int WINAPI ItemBillCmpValue(void* arg1, void* arg2) { return ((PerItemBill*)arg1)->inventoryIdx - (*(long*)arg2); } // cItemBillPool Constructor cItemBillPool::cItemBillPool( ) { // Global Variable mpItemBillPool = this; // Pool Usage Pointer mNonPagedPoolUsage = NULL; } // ~cItemBillPool Destructor. cItemBillPool::~cItemBillPool(void) { // cItemBillPool¸¦ ÇØÁ¦. Shutdown(); // Global Variable mpItemBillPool = NULL; } // Shutdown Method void cItemBillPool::Shutdown() { PerItemBill* temp; // Pool Usage Shutdown - NonPagedPoolUsage while ( mNonPagedPoolUsage != NULL ) { temp = mNonPagedPoolUsage; mNonPagedPoolUsage = (PerItemBill*)mNonPagedPoolUsage->next; MEMORY_POOL->FreeNode( (void**)&temp ); } } // SearchItemBill Method PerItemBill* cItemBillPool::SearchItemBill(ItemBillRoot* root, long inventoryIdx) { return (PerItemBill*)MEMORY_POOL->SearchNode( root, &inventoryIdx, &ItemBillCmpValue ); } // GetItemBill Method - ¼±Çü¸®½ºÆ®ÀÇ HEAD¸¦ ³Ñ°ÜÁØ´Ù. // ReleaseItemBill¿Í ÇÔ²² LIFO¸¦ ÀÌ·é´Ù. LIFO´Â Context Switching¸¦ ÃÖ¼ÒÈ­ Çϱâ À§ÇØ »ç¿ë PerItemBill* cItemBillPool::GetItemBill(ItemBillRoot* root, long inventoryIdx) { PerItemBill* itemBill = (PerItemBill*)MEMORY_POOL->GetPool( (PerNode**)&mNonPagedPoolUsage, sizeof(PerItemBill) ); if ( itemBill ) { itemBill->inventoryIdx = inventoryIdx; // BST-¿¬°á½Ãµµ. if ( MEMORY_POOL->AttachBst( &root->root, itemBill, ItemBillCmpIndex ) ) { MEMORY_POOL->AttachPool( (PerNode**)&root->pool, itemBill ); return itemBill; // ¿¬°á¼º°ø. } else { MEMORY_POOL->AttachPool( (PerNode**)&mNonPagedPoolUsage, itemBill ); return NULL; // ¿¬°á½ÇÆÐ. } } return itemBill; } // ReleaseItemBill Method - ¼±Çü¸®½ºÆ®ÀÇ HEAD·Î ȸ¼öÇÑ´Ù. // GetItemBill¿Í ÇÔ²² LIFO¸¦ ÀÌ·é´Ù. LIFO´Â Context Switching¸¦ ÃÖ¼ÒÈ­ Çϱâ À§ÇØ »ç¿ë void cItemBillPool::ReleaseItemBill(ItemBillRoot* root, PerItemBill* itemBill) { itemBill->idx = 0; itemBill->type = 0; itemBill->validDate = 0; itemBill->validTime = 0; itemBill->inventoryIdx = 0; itemBill->timeBegin = 0; itemBill->timeEnd = 0; itemBill->apply = 0; // BST - ¿¬°áÁ¾·á. MEMORY_POOL->DetachBst( (PerNode**)&root->root, (PerNode*)itemBill ); // ÆäÀÌÁö µÈ Ç® »ç¿ë·®À» Â÷°¨. MEMORY_POOL->DetachPool( (PerNode**)&root->pool, (PerNode*)itemBill ); // ÆäÀÌÁö ¾ÈµÈ Ç® »ç¿ë·®À» Áõ°¨. MEMORY_POOL->ReleasePool( (PerNode**)&mNonPagedPoolUsage, (PerNode*)itemBill ); }