// move _Out postion (들어있는 데이터 중 일부를 버린다) int CCircularBuffer::Dump(int length) { int used, dumped; if(_Size <= 0 || length <= 0) return 0; //WaitForSingleObject(_HanNomManCBuffer, INFINITE); Lock(); used = UsedSpace(); dumped = length <= used ? length : used; _Out = (_Out + dumped) % _Size; //ReleaseMutex(_HanNomManCBuffer); Unlock(); return dumped; }
void Buffer::MakeRoomForBytes(uint64_t num_bytes) { bool has_room = (buffer_start_ != nullptr && buffer_pos_ + num_bytes < buffer_end_); if (has_room) { return; } // Need to allocate some space uint64_t curr_alloc_size = AllocatedSpace(); uint64_t curr_used_size = UsedSpace(); // Ensure the current size is a power of two PELOTON_ASSERT(curr_alloc_size % 2 == 0); // Allocate double the buffer room uint64_t next_alloc_size = curr_alloc_size; do { next_alloc_size *= 2; } while (next_alloc_size < num_bytes); LOG_DEBUG("Resizing buffer from %.2lf bytes to %.2lf KB ...", curr_alloc_size / 1024.0, next_alloc_size / 1024.0); auto &backend_manager = storage::BackendManager::GetInstance(); auto *new_buffer = reinterpret_cast<char *>( backend_manager.Allocate(BackendType::MM, next_alloc_size)); // Now copy the previous buffer into the new area PELOTON_MEMCPY(new_buffer, buffer_start_, curr_used_size); // Set pointers char *old_buffer_start = buffer_start_; buffer_start_ = new_buffer; buffer_pos_ = buffer_start_ + curr_used_size; buffer_end_ = buffer_start_ + next_alloc_size; // Release old buffer backend_manager.Release(BackendType::MM, old_buffer_start); }