mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
protect with a mutex
This commit is contained in:
parent
90902c5cca
commit
486680b144
@ -20,6 +20,7 @@
|
|||||||
#include "cMetaInterval.h"
|
#include "cMetaInterval.h"
|
||||||
#include "dcast.h"
|
#include "dcast.h"
|
||||||
#include "eventQueue.h"
|
#include "eventQueue.h"
|
||||||
|
#include "mutexHolder.h"
|
||||||
|
|
||||||
CIntervalManager *CIntervalManager::_global_ptr;
|
CIntervalManager *CIntervalManager::_global_ptr;
|
||||||
|
|
||||||
@ -66,6 +67,8 @@ CIntervalManager::
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
add_c_interval(CInterval *interval, bool external) {
|
add_c_interval(CInterval *interval, bool external) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
// First, check the name index. If we already have an interval by
|
// First, check the name index. If we already have an interval by
|
||||||
// this name, it gets finished and removed.
|
// this name, it gets finished and removed.
|
||||||
NameIndex::iterator ni = _name_index.find(interval->get_name());
|
NameIndex::iterator ni = _name_index.find(interval->get_name());
|
||||||
@ -123,6 +126,8 @@ add_c_interval(CInterval *interval, bool external) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
find_c_interval(const string &name) const {
|
find_c_interval(const string &name) const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
NameIndex::const_iterator ni = _name_index.find(name);
|
NameIndex::const_iterator ni = _name_index.find(name);
|
||||||
if (ni != _name_index.end()) {
|
if (ni != _name_index.end()) {
|
||||||
return (*ni).second;
|
return (*ni).second;
|
||||||
@ -137,6 +142,8 @@ find_c_interval(const string &name) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
CInterval *CIntervalManager::
|
CInterval *CIntervalManager::
|
||||||
get_c_interval(int index) const {
|
get_c_interval(int index) const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
nassertr(index >= 0 && index < (int)_intervals.size(), NULL);
|
nassertr(index >= 0 && index < (int)_intervals.size(), NULL);
|
||||||
return _intervals[index]._interval;
|
return _intervals[index]._interval;
|
||||||
}
|
}
|
||||||
@ -151,6 +158,8 @@ get_c_interval(int index) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CIntervalManager::
|
void CIntervalManager::
|
||||||
remove_c_interval(int index) {
|
remove_c_interval(int index) {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
nassertv(index >= 0 && index < (int)_intervals.size());
|
nassertv(index >= 0 && index < (int)_intervals.size());
|
||||||
IntervalDef &def = _intervals[index];
|
IntervalDef &def = _intervals[index];
|
||||||
nassertv(def._interval != (CInterval *)NULL);
|
nassertv(def._interval != (CInterval *)NULL);
|
||||||
@ -178,6 +187,8 @@ remove_c_interval(int index) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
interrupt() {
|
interrupt() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
int num_paused = 0;
|
int num_paused = 0;
|
||||||
|
|
||||||
NameIndex::iterator ni;
|
NameIndex::iterator ni;
|
||||||
@ -241,6 +252,8 @@ interrupt() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
get_num_intervals() const {
|
get_num_intervals() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
return _name_index.size();
|
return _name_index.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +269,8 @@ get_num_intervals() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
get_max_index() const {
|
get_max_index() const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
return _intervals.size();
|
return _intervals.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +290,8 @@ get_max_index() const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CIntervalManager::
|
void CIntervalManager::
|
||||||
step() {
|
step() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
NameIndex::iterator ni;
|
NameIndex::iterator ni;
|
||||||
ni = _name_index.begin();
|
ni = _name_index.begin();
|
||||||
while (ni != _name_index.end()) {
|
while (ni != _name_index.end()) {
|
||||||
@ -318,6 +335,8 @@ step() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
get_next_event() {
|
get_next_event() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
while (_next_event_index < (int)_intervals.size()) {
|
while (_next_event_index < (int)_intervals.size()) {
|
||||||
IntervalDef &def = _intervals[_next_event_index];
|
IntervalDef &def = _intervals[_next_event_index];
|
||||||
if (def._interval != (CInterval *)NULL) {
|
if (def._interval != (CInterval *)NULL) {
|
||||||
@ -355,6 +374,8 @@ get_next_event() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
int CIntervalManager::
|
int CIntervalManager::
|
||||||
get_next_removal() {
|
get_next_removal() {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
if (!_removed.empty()) {
|
if (!_removed.empty()) {
|
||||||
int index = _removed.back();
|
int index = _removed.back();
|
||||||
_removed.pop_back();
|
_removed.pop_back();
|
||||||
@ -377,6 +398,8 @@ get_next_removal() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CIntervalManager::
|
void CIntervalManager::
|
||||||
output(ostream &out) const {
|
output(ostream &out) const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
out << "CIntervalManager, " << (int)_name_index.size() << " intervals.";
|
out << "CIntervalManager, " << (int)_name_index.size() << " intervals.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,6 +410,8 @@ output(ostream &out) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CIntervalManager::
|
void CIntervalManager::
|
||||||
write(ostream &out) const {
|
write(ostream &out) const {
|
||||||
|
MutexHolder holder(_lock);
|
||||||
|
|
||||||
// We need to write this line so that it's clear what's going on
|
// We need to write this line so that it's clear what's going on
|
||||||
// when there are no intervals in the list.
|
// when there are no intervals in the list.
|
||||||
out << (int)_name_index.size() << " intervals.\n";
|
out << (int)_name_index.size() << " intervals.\n";
|
||||||
@ -454,10 +479,12 @@ finish_interval(CInterval *interval) {
|
|||||||
// Description: Removes the indicated index number from the active
|
// Description: Removes the indicated index number from the active
|
||||||
// list, either by moving it to the removed queue if it
|
// list, either by moving it to the removed queue if it
|
||||||
// is flagged external, or by simply making the slot
|
// is flagged external, or by simply making the slot
|
||||||
// available again if it is not.
|
// available again if it is not. Assumes the lock is
|
||||||
|
// already held.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CIntervalManager::
|
void CIntervalManager::
|
||||||
remove_index(int index) {
|
remove_index(int index) {
|
||||||
|
nassertv(_lock.debug_is_locked());
|
||||||
nassertv(index >= 0 && index < (int)_intervals.size());
|
nassertv(index >= 0 && index < (int)_intervals.size());
|
||||||
IntervalDef &def = _intervals[index];
|
IntervalDef &def = _intervals[index];
|
||||||
if ((def._flags & F_external) != 0) {
|
if ((def._flags & F_external) != 0) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
#include "pmap.h"
|
#include "pmap.h"
|
||||||
#include "vector_int.h"
|
#include "vector_int.h"
|
||||||
|
#include "pmutex.h"
|
||||||
|
|
||||||
class EventQueue;
|
class EventQueue;
|
||||||
|
|
||||||
@ -95,6 +96,8 @@ private:
|
|||||||
int _first_slot;
|
int _first_slot;
|
||||||
int _next_event_index;
|
int _next_event_index;
|
||||||
|
|
||||||
|
Mutex _lock;
|
||||||
|
|
||||||
static CIntervalManager *_global_ptr;
|
static CIntervalManager *_global_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user