Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions be/src/util/core_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <vector>

#include "common/logging.h"
#include "util/spinlock.h"

namespace doris {

Expand Down Expand Up @@ -48,8 +49,11 @@ class CoreDataAllocatorImpl : public CoreDataAllocator {
virtual ~CoreDataAllocatorImpl();
void* get_or_create(size_t id) override {
size_t block_id = id / ELEMENTS_PER_BLOCK;
if (block_id >= _blocks.size()) {
_blocks.resize(block_id + 1);
{
std::lock_guard<SpinLock> l(_lock);
if (block_id >= _blocks.size()) {
_blocks.resize(block_id + 1);
}
}
CoreDataBlock* block = _blocks[block_id];
if (block == nullptr) {
Expand All @@ -61,6 +65,7 @@ class CoreDataAllocatorImpl : public CoreDataAllocator {
}
private:
static constexpr int ELEMENTS_PER_BLOCK = BLOCK_SIZE / ELEMENT_BYTES;
SpinLock _lock; // lock to protect the modification of _blocks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreData is to bind data to cpu to eliminate the lock.
If add a lock, it's design is meaningless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used when creating the core local value (by calling get_or_create() of CoreDataAllocatorImpl).
And when creating the value, there is nothing to do with "cpu-bind".

The so called "cpu-bind" operation happens when accessing the CoreLocalValue,
not related to CoreDataAllocatorImpl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have no problem.

std::vector<CoreDataBlock*> _blocks;
};

Expand Down