fix pstats mutex leaking

This commit is contained in:
David Rose 2009-01-22 00:17:07 +00:00
parent a9f3242305
commit 574403a39f
5 changed files with 21 additions and 18 deletions

View File

@ -26,7 +26,9 @@
#include "pStatCollector.h" #include "pStatCollector.h"
#include "geomEnums.h" #include "geomEnums.h"
#include "lightReMutex.h" #include "lightReMutex.h"
#include "lightReMutexHolder.h"
#include "lightMutex.h" #include "lightMutex.h"
#include "lightMutexHolder.h"
#include "config_pgraph.h" #include "config_pgraph.h"
#include "deletedChain.h" #include "deletedChain.h"
#include "simpleHashMap.h" #include "simpleHashMap.h"

View File

@ -148,9 +148,10 @@ do_acquire(Thread *current_thread) {
// In this case, it's not a real mutex. Just watch it go by. // In this case, it's not a real mutex. Just watch it go by.
MissedThreads::iterator mi = _missed_threads.insert(MissedThreads::value_type(current_thread, 0)).first; MissedThreads::iterator mi = _missed_threads.insert(MissedThreads::value_type(current_thread, 0)).first;
if ((*mi).second == 0) { if ((*mi).second == 0) {
thread_cat.info() ostringstream ostr;
<< *current_thread << " not stopped by " << *this << " (held by " ostr << *current_thread << " not stopped by " << *this << " (held by "
<< *_locking_thread << ")\n"; << *_locking_thread << ")\n";
nassert_raise(ostr.str());
} else { } else {
if (!_allow_recursion) { if (!_allow_recursion) {
ostringstream ostr; ostringstream ostr;

View File

@ -75,7 +75,7 @@ get_max_rate() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int PStatClient:: INLINE int PStatClient::
get_num_collectors() const { get_num_collectors() const {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
return _num_collectors; return _num_collectors;
} }
@ -99,7 +99,7 @@ get_collector_def(int index) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE int PStatClient:: INLINE int PStatClient::
get_num_threads() const { get_num_threads() const {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
return _num_threads; return _num_threads;
} }
@ -211,7 +211,7 @@ resume_after_pause() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool PStatClient:: INLINE bool PStatClient::
client_connect(string hostname, int port) { client_connect(string hostname, int port) {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
client_disconnect(); client_disconnect();
return get_impl()->client_connect(hostname, port); return get_impl()->client_connect(hostname, port);
} }
@ -261,7 +261,7 @@ has_impl() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE PStatClientImpl *PStatClient:: INLINE PStatClientImpl *PStatClient::
get_impl() { get_impl() {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (_impl == (PStatClientImpl *)NULL) { if (_impl == (PStatClientImpl *)NULL) {
_impl = new PStatClientImpl(this); _impl = new PStatClientImpl(this);
} }

View File

@ -164,7 +164,7 @@ get_collector_fullname(int index) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PStatThread PStatClient:: PStatThread PStatClient::
get_thread(int index) const { get_thread(int index) const {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
nassertr(index >= 0 && index < _num_threads, PStatThread()); nassertr(index >= 0 && index < _num_threads, PStatThread());
return PStatThread((PStatClient *)this, index); return PStatThread((PStatClient *)this, index);
} }
@ -370,7 +370,7 @@ thread_tick(const string &sync_name) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PStatClient:: void PStatClient::
client_main_tick() { client_main_tick() {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (has_impl()) { if (has_impl()) {
if (!_impl->client_is_connected()) { if (!_impl->client_is_connected()) {
client_disconnect(); client_disconnect();
@ -400,7 +400,7 @@ client_main_tick() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PStatClient:: void PStatClient::
client_thread_tick(const string &sync_name) { client_thread_tick(const string &sync_name) {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (has_impl()) { if (has_impl()) {
MultiThingsByName::const_iterator ni = MultiThingsByName::const_iterator ni =
@ -423,7 +423,7 @@ client_thread_tick(const string &sync_name) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PStatClient:: void PStatClient::
client_disconnect() { client_disconnect() {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (has_impl()) { if (has_impl()) {
_impl->client_disconnect(); _impl->client_disconnect();
delete _impl; delete _impl;
@ -484,7 +484,7 @@ get_global_pstats() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PStatCollector PStatClient:: PStatCollector PStatClient::
make_collector_with_relname(int parent_index, string relname) { make_collector_with_relname(int parent_index, string relname) {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
if (relname.empty()) { if (relname.empty()) {
relname = "Unnamed"; relname = "Unnamed";
@ -524,7 +524,7 @@ make_collector_with_relname(int parent_index, string relname) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PStatCollector PStatClient:: PStatCollector PStatClient::
make_collector_with_name(int parent_index, const string &name) { make_collector_with_name(int parent_index, const string &name) {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
nassertr(parent_index >= 0 && parent_index < _num_collectors, nassertr(parent_index >= 0 && parent_index < _num_collectors,
PStatCollector()); PStatCollector());
@ -593,7 +593,7 @@ do_get_current_thread() const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
PStatThread PStatClient:: PStatThread PStatClient::
make_thread(Thread *thread) { make_thread(Thread *thread) {
LightReMutexHolder holder(_lock); ReMutexHolder holder(_lock);
return do_make_thread(thread); return do_make_thread(thread);
} }
@ -1144,7 +1144,7 @@ activate_hook(Thread *thread) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PStatClient::Collector:: void PStatClient::Collector::
make_def(const PStatClient *client, int this_index) { make_def(const PStatClient *client, int this_index) {
LightReMutexHolder holder(client->_lock); ReMutexHolder holder(client->_lock);
if (_def == (PStatCollectorDef *)NULL) { if (_def == (PStatCollectorDef *)NULL) {
_def = new PStatCollectorDef(this_index, _name); _def = new PStatCollectorDef(this_index, _name);
if (_parent_index != this_index) { if (_parent_index != this_index) {

View File

@ -20,9 +20,9 @@
#include "pStatFrameData.h" #include "pStatFrameData.h"
#include "pStatClientImpl.h" #include "pStatClientImpl.h"
#include "pStatCollectorDef.h" #include "pStatCollectorDef.h"
#include "lightReMutex.h" #include "reMutex.h"
#include "lightMutex.h" #include "lightMutex.h"
#include "lightReMutexHolder.h" #include "reMutexHolder.h"
#include "lightMutexHolder.h" #include "lightMutexHolder.h"
#include "pmap.h" #include "pmap.h"
#include "thread.h" #include "thread.h"
@ -144,7 +144,7 @@ private:
private: private:
// This mutex protects everything in this class. // This mutex protects everything in this class.
LightReMutex _lock; ReMutex _lock;
typedef pmap<string, int> ThingsByName; typedef pmap<string, int> ThingsByName;
typedef pmap<string, vector_int> MultiThingsByName; typedef pmap<string, vector_int> MultiThingsByName;