1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

Refine comments for object cache

This commit is contained in:
winlin 2021-02-27 12:14:48 +08:00
parent 6656330d2a
commit 1e2daf9ea3

View file

@ -321,7 +321,7 @@ private:
void reuse_payload(); void reuse_payload();
void reuse_shared_msg(); void reuse_shared_msg();
public: public:
// Reset the object to reuse it. // Recycle the object to reuse it.
virtual bool reset(); virtual bool reset();
// Wrap buffer to shared_message, which is managed by us. // Wrap buffer to shared_message, which is managed by us.
char* wrap(int size); char* wrap(int size);
@ -365,11 +365,13 @@ private:
size_t capacity_; size_t capacity_;
size_t object_size_; size_t object_size_;
public: public:
// SrsRtpObjectCacheManager::SrsRtpObjectCacheManager
SrsRtpObjectCacheManager(size_t size_of_object) { SrsRtpObjectCacheManager(size_t size_of_object) {
enabled_ = false; enabled_ = false;
capacity_ = 0; capacity_ = 0;
object_size_ = size_of_object; object_size_ = size_of_object;
} }
// SrsRtpObjectCacheManager::~SrsRtpObjectCacheManager
virtual ~SrsRtpObjectCacheManager() { virtual ~SrsRtpObjectCacheManager() {
typedef typename std::vector<T*>::iterator iterator; typedef typename std::vector<T*>::iterator iterator;
for (iterator it = cache_objs_.begin(); it != cache_objs_.end(); ++it) { for (iterator it = cache_objs_.begin(); it != cache_objs_.end(); ++it) {
@ -379,6 +381,7 @@ public:
} }
public: public:
// Setup the object cache, shrink if capacity changed. // Setup the object cache, shrink if capacity changed.
// SrsRtpObjectCacheManager::setup
void setup(bool v, uint64_t memory) { void setup(bool v, uint64_t memory) {
enabled_ = v; enabled_ = v;
capacity_ = (size_t)(memory / object_size_); capacity_ = (size_t)(memory / object_size_);
@ -396,16 +399,20 @@ public:
} }
} }
// Get the status of object cache. // Get the status of object cache.
// SrsRtpObjectCacheManager::enabled
bool enabled() { bool enabled() {
return enabled_; return enabled_;
} }
// SrsRtpObjectCacheManager::size
int size() { int size() {
return (int)cache_objs_.size(); return (int)cache_objs_.size();
} }
// SrsRtpObjectCacheManager::capacity
int capacity() { int capacity() {
return (int)capacity_; return (int)capacity_;
} }
// Try to allocate from cache, create new object if no cache. // Try to allocate from cache, create new object if no cache.
// SrsRtpObjectCacheManager::allocate
T* allocate() { T* allocate() {
while (true) { while (true) {
if (!enabled_ || cache_objs_.empty()) { if (!enabled_ || cache_objs_.empty()) {
@ -426,6 +433,7 @@ public:
} }
// Recycle the object to cache. // Recycle the object to cache.
// @remark User can directly free the packet. // @remark User can directly free the packet.
// SrsRtpObjectCacheManager::recycle
void recycle(T* p) { void recycle(T* p) {
// The p may be NULL, because srs_freep(NULL) is ok. // The p may be NULL, because srs_freep(NULL) is ok.
if (!p) { if (!p) {