mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
parent
95d1ac2f8b
commit
085795db83
@ -16,6 +16,7 @@
|
|||||||
#include "notifyCategoryProxy.h"
|
#include "notifyCategoryProxy.h"
|
||||||
|
|
||||||
#include "uniqueIdAllocator.h"
|
#include "uniqueIdAllocator.h"
|
||||||
|
#include "lightMutexHolder.h"
|
||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
@ -84,6 +85,8 @@ UniqueIdAllocator::
|
|||||||
*/
|
*/
|
||||||
uint32_t UniqueIdAllocator::
|
uint32_t UniqueIdAllocator::
|
||||||
allocate() {
|
allocate() {
|
||||||
|
LightMutexHolder holder(_lock);
|
||||||
|
|
||||||
if (_next_free == IndexEnd) {
|
if (_next_free == IndexEnd) {
|
||||||
// ...all ids allocated.
|
// ...all ids allocated.
|
||||||
uniqueIdAllocator_warning("allocate Error: no more free ids.");
|
uniqueIdAllocator_warning("allocate Error: no more free ids.");
|
||||||
@ -115,6 +118,8 @@ allocate() {
|
|||||||
*/
|
*/
|
||||||
void UniqueIdAllocator::
|
void UniqueIdAllocator::
|
||||||
initial_reserve_id(uint32_t id) {
|
initial_reserve_id(uint32_t id) {
|
||||||
|
LightMutexHolder holder(_lock);
|
||||||
|
|
||||||
nassertv(id >= _min && id <= _max); // Attempt to reserve out-of-range id.
|
nassertv(id >= _min && id <= _max); // Attempt to reserve out-of-range id.
|
||||||
uint32_t index = id - _min; // Convert to _table index.
|
uint32_t index = id - _min; // Convert to _table index.
|
||||||
|
|
||||||
@ -175,6 +180,8 @@ initial_reserve_id(uint32_t id) {
|
|||||||
*/
|
*/
|
||||||
bool UniqueIdAllocator::
|
bool UniqueIdAllocator::
|
||||||
is_allocated(uint32_t id) {
|
is_allocated(uint32_t id) {
|
||||||
|
LightMutexHolder holder(_lock);
|
||||||
|
|
||||||
if (id < _min || id > _max) {
|
if (id < _min || id > _max) {
|
||||||
// This id is out of range, not allocated.
|
// This id is out of range, not allocated.
|
||||||
return false;
|
return false;
|
||||||
@ -190,6 +197,8 @@ is_allocated(uint32_t id) {
|
|||||||
*/
|
*/
|
||||||
void UniqueIdAllocator::
|
void UniqueIdAllocator::
|
||||||
free(uint32_t id) {
|
free(uint32_t id) {
|
||||||
|
LightMutexHolder holder(_lock);
|
||||||
|
|
||||||
uniqueIdAllocator_debug("free("<<id<<")");
|
uniqueIdAllocator_debug("free("<<id<<")");
|
||||||
|
|
||||||
nassertv(id >= _min && id <= _max); // Attempt to free out-of-range id.
|
nassertv(id >= _min && id <= _max); // Attempt to free out-of-range id.
|
||||||
@ -234,6 +243,8 @@ output(std::ostream &out) const {
|
|||||||
*/
|
*/
|
||||||
void UniqueIdAllocator::
|
void UniqueIdAllocator::
|
||||||
write(std::ostream &out) const {
|
write(std::ostream &out) const {
|
||||||
|
LightMutexHolder holder(_lock);
|
||||||
|
|
||||||
out << "_min: " << _min << "; _max: " << _max
|
out << "_min: " << _min << "; _max: " << _max
|
||||||
<< ";\n_next_free: " << int32_t(_next_free)
|
<< ";\n_next_free: " << int32_t(_next_free)
|
||||||
<< "; _last_free: " << int32_t(_last_free)
|
<< "; _last_free: " << int32_t(_last_free)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "pandabase.h"
|
#include "pandabase.h"
|
||||||
#include "numeric_types.h"
|
#include "numeric_types.h"
|
||||||
|
#include "lightMutex.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage a set of ID values from min to max inclusive. The ID numbers that
|
* Manage a set of ID values from min to max inclusive. The ID numbers that
|
||||||
@ -86,6 +87,10 @@ protected:
|
|||||||
|
|
||||||
// The number of free elements in _table.
|
// The number of free elements in _table.
|
||||||
uint32_t _free;
|
uint32_t _free;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// A light mutex lock to make usage safe in multi-threaded scenarios.
|
||||||
|
LightMutex _lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //]
|
#endif //]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user