mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
add mutex
This commit is contained in:
parent
750bae7b34
commit
49915c3080
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include "lru.h"
|
#include "lru.h"
|
||||||
|
|
||||||
|
|
||||||
#define HIGH_PRIORITY_SCALE 4
|
#define HIGH_PRIORITY_SCALE 4
|
||||||
#define LOW_PRIORITY_RANGE 25
|
#define LOW_PRIORITY_RANGE 25
|
||||||
|
|
||||||
@ -106,6 +105,11 @@ Lru::Lru (int maximum_memory, int maximum_pages, int maximum_page_types)
|
|||||||
{
|
{
|
||||||
this -> _m.page_type_statistics_array = new PageTypeStatistics [maximum_page_types];
|
this -> _m.page_type_statistics_array = new PageTypeStatistics [maximum_page_types];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MUTEX
|
||||||
|
this -> _m.mutex = new Mutex ( );
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +167,14 @@ Lru::~Lru ( )
|
|||||||
{
|
{
|
||||||
delete this -> _m.page_type_statistics_array;
|
delete this -> _m.page_type_statistics_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MUTEX
|
||||||
|
if (this -> _m.mutex)
|
||||||
|
{
|
||||||
|
delete this -> _m.mutex;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -336,6 +348,8 @@ void Lru::free_page (LruPage *lru_page)
|
|||||||
{
|
{
|
||||||
if (lru_page)
|
if (lru_page)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
this -> update_start_update_lru_page (lru_page);
|
this -> update_start_update_lru_page (lru_page);
|
||||||
|
|
||||||
if (lru_page -> _m.in_cache)
|
if (lru_page -> _m.in_cache)
|
||||||
@ -381,6 +395,8 @@ void Lru::add_page (LruPagePriority priority, LruPage *lru_page)
|
|||||||
{
|
{
|
||||||
if (lru_page)
|
if (lru_page)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
LruPage *first_lru_page;
|
LruPage *first_lru_page;
|
||||||
|
|
||||||
lru_page -> _m.priority = priority;
|
lru_page -> _m.priority = priority;
|
||||||
@ -408,6 +424,8 @@ void Lru::add_cached_page (LruPagePriority priority, LruPage *lru_page)
|
|||||||
{
|
{
|
||||||
if (lru_page)
|
if (lru_page)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
lru_page -> _m.in_cache = true;
|
lru_page -> _m.in_cache = true;
|
||||||
|
|
||||||
if (lru_page -> _m.size > this -> _m.available_memory)
|
if (lru_page -> _m.size > this -> _m.available_memory)
|
||||||
@ -433,12 +451,14 @@ void Lru::add_cached_page (LruPagePriority priority, LruPage *lru_page)
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void Lru::remove_page (LruPage *lru_page)
|
void Lru::remove_page (LruPage *lru_page)
|
||||||
{
|
{
|
||||||
if (lru_page)
|
if (this)
|
||||||
{
|
{
|
||||||
if (this -> _m.total_pages > 0)
|
if (this -> _m.total_pages > 0)
|
||||||
{
|
{
|
||||||
if (lru_page)
|
if (lru_page)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
this -> update_start_update_lru_page (lru_page);
|
this -> update_start_update_lru_page (lru_page);
|
||||||
|
|
||||||
if (lru_page -> _m.previous)
|
if (lru_page -> _m.previous)
|
||||||
@ -471,6 +491,12 @@ void Lru::remove_page (LruPage *lru_page)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
// ERROR: Lru == 0, this should not happen
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -525,6 +551,8 @@ void Lru::access_page (LruPage *lru_page)
|
|||||||
|
|
||||||
state = true;
|
state = true;
|
||||||
|
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
// check memory usage
|
// check memory usage
|
||||||
if (lru_page -> _m.size > this -> _m.available_memory)
|
if (lru_page -> _m.size > this -> _m.available_memory)
|
||||||
{
|
{
|
||||||
@ -548,6 +576,7 @@ void Lru::access_page (LruPage *lru_page)
|
|||||||
// CHANGE THE PAGE PRIORITY FROM LPP_PageOut TO LPP_New
|
// CHANGE THE PAGE PRIORITY FROM LPP_PageOut TO LPP_New
|
||||||
this -> remove_page (lru_page);
|
this -> remove_page (lru_page);
|
||||||
this -> add_page (LPP_New, lru_page);
|
this -> add_page (LPP_New, lru_page);
|
||||||
|
lru_page -> _m.average_frame_utilization = 1.0f;
|
||||||
|
|
||||||
this -> _m.total_lifetime_page_ins++;
|
this -> _m.total_lifetime_page_ins++;
|
||||||
}
|
}
|
||||||
@ -870,6 +899,8 @@ void Lru::update_entire_lru ( )
|
|||||||
int index;
|
int index;
|
||||||
LruPage *lru_page;
|
LruPage *lru_page;
|
||||||
|
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
for (index = 0; index < LPP_TotalPriorities; index++)
|
for (index = 0; index < LPP_TotalPriorities; index++)
|
||||||
{
|
{
|
||||||
LruPage *next_lru_page;
|
LruPage *next_lru_page;
|
||||||
@ -906,6 +937,8 @@ void Lru::partial_lru_update (int maximum_updates)
|
|||||||
int start_priority;
|
int start_priority;
|
||||||
LruPage *lru_page;
|
LruPage *lru_page;
|
||||||
|
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
start_priority = this -> _m.start_priority_index;
|
start_priority = this -> _m.start_priority_index;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1072,6 +1105,8 @@ bool Lru::page_out_lru (int memory_required)
|
|||||||
attempts = 0;
|
attempts = 0;
|
||||||
if (this -> _m.total_pages > 0)
|
if (this -> _m.total_pages > 0)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
@ -1146,6 +1181,8 @@ void Lru::count_priority_level_pages (void)
|
|||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
for (index = 0; index < LPP_TotalPriorities; index++)
|
for (index = 0; index < LPP_TotalPriorities; index++)
|
||||||
{
|
{
|
||||||
int total_pages;
|
int total_pages;
|
||||||
@ -1167,8 +1204,15 @@ void Lru::count_priority_level_pages (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Lru::calculate_lru_statistics
|
||||||
|
// Access: Public
|
||||||
|
// Description: Debug function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
void Lru::calculate_lru_statistics (void)
|
void Lru::calculate_lru_statistics (void)
|
||||||
{
|
{
|
||||||
|
LruMutexHolder (this -> _m.mutex);
|
||||||
|
|
||||||
if (this -> _m.maximum_page_types > 0)
|
if (this -> _m.maximum_page_types > 0)
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
@ -1183,7 +1227,7 @@ void Lru::calculate_lru_statistics (void)
|
|||||||
lru_page = this -> _m.lru_page_array [index];
|
lru_page = this -> _m.lru_page_array [index];
|
||||||
while (lru_page)
|
while (lru_page)
|
||||||
{
|
{
|
||||||
volatile int type;
|
int type;
|
||||||
|
|
||||||
next_lru_page = lru_page -> _m.next;
|
next_lru_page = lru_page -> _m.next;
|
||||||
|
|
||||||
|
@ -19,6 +19,15 @@
|
|||||||
#ifndef LRU_H
|
#ifndef LRU_H
|
||||||
#define LRU_H
|
#define LRU_H
|
||||||
|
|
||||||
|
#define ENABLE_MUTEX 1
|
||||||
|
|
||||||
|
#if ENABLE_MUTEX
|
||||||
|
#include "pmutex.h"
|
||||||
|
#include "mutexHolder.h"
|
||||||
|
#define LruMutexHolder(mutex) MutexHolder(mutex)
|
||||||
|
#else
|
||||||
|
#define LruMutexHolder(mutex)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MAXIMUM_LRU_PAGE_TYPES 8
|
#define MAXIMUM_LRU_PAGE_TYPES 8
|
||||||
#define FRAME_MAXIMUM_PRIORITY_CHANGES 256
|
#define FRAME_MAXIMUM_PRIORITY_CHANGES 256
|
||||||
@ -220,6 +229,10 @@ public:
|
|||||||
LruPage **lru_page_free_pool;
|
LruPage **lru_page_free_pool;
|
||||||
|
|
||||||
PageTypeStatistics *page_type_statistics_array;
|
PageTypeStatistics *page_type_statistics_array;
|
||||||
|
|
||||||
|
#if ENABLE_MUTEX
|
||||||
|
Mutex *mutex;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
LruVariables;
|
LruVariables;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user