MCPcopy Create free account
hub / github.com/apache/brpc / Return

Method Return

src/brpc/simple_data_pool.cpp:106–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void SimpleDataPool::Return(void* data) {
107 if (data == NULL) {
108 return;
109 }
110 if (!_factory->ResetData(data)) {
111 return _factory->DestroyData(data);
112 }
113 std::unique_lock<butil::Mutex> mu(_mutex);
114 if (_capacity == _size) {
115 const unsigned new_cap = (_capacity <= 1 ? 128 : (_capacity * 3 / 2));
116 void** new_pool = (void**)malloc(new_cap * sizeof(void*));
117 if (NULL == new_pool) {
118 mu.unlock();
119 return _factory->DestroyData(data);
120 }
121 if (_pool) {
122 memcpy(new_pool, _pool, _capacity * sizeof(void*));
123 free(_pool);
124 }
125 _capacity = new_cap;
126 _pool = new_pool;
127 }
128 _pool[_size++] = data;
129}
130
131SimpleDataPool::Stat SimpleDataPool::stat() const {
132 Stat s = { _size, _ncreated.load(butil::memory_order_relaxed) };

Callers 1

ResetNonPodsMethod · 0.45

Calls 3

ResetDataMethod · 0.80
DestroyDataMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected