ccls/src/message_queue.cc

34 lines
1003 B
C++
Raw Normal View History

2017-03-19 22:06:22 +00:00
#include "message_queue.h"
#include <cassert>
struct MessageQueue::BufferMetadata {
// Total number of used bytes exluding the sizeof this metadata object.
void set_total_messages_byte_count(size_t used_bytes) {
total_message_bytes_ = used_bytes;
}
// The total number of bytes in use.
size_t total_bytes_used_including_metadata() {
return total_message_bytes_ + sizeof(BufferMetadata);
}
// The total number of bytes currently used for messages. This does not
// include the sizeof the buffer metadata.
2017-03-19 22:08:36 +00:00
size_t total_message_bytes() { return total_message_bytes_; }
2017-03-19 22:06:22 +00:00
2017-03-19 22:08:36 +00:00
private:
2017-03-19 22:06:22 +00:00
size_t total_message_bytes_ = 0;
};
2017-03-19 22:08:36 +00:00
MessageQueue::MessageQueue(std::unique_ptr<Buffer> buffer, bool buffer_has_data)
: buffer_(std::move(buffer)) {
2017-03-19 22:06:22 +00:00
if (!buffer_has_data)
2017-03-19 22:08:36 +00:00
new (buffer_->data) BufferMetadata();
2017-03-19 22:06:22 +00:00
}
2017-03-19 22:08:36 +00:00
void MessageQueue::Enqueue(const Message& message) {}
2017-03-19 22:06:22 +00:00
MessageQueue::BufferMetadata* MessageQueue::Metadata() {
return reinterpret_cast<BufferMetadata*>(buffer_->data);
}