Files
scylladb/service/memory_limiter.hh
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

33 lines
612 B
C++

/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (C) 2021-present ScyllaDB
*
*/
#pragma once
#include "seastarx.hh"
#include <seastar/core/semaphore.hh>
namespace service {
class memory_limiter final {
size_t _mem_total;
semaphore _sem;
public:
memory_limiter(size_t available_memory) noexcept
: _mem_total(available_memory / 10)
, _sem(_mem_total) {}
future<> stop() {
return _sem.wait(_mem_total);
}
size_t total_memory() const noexcept { return _mem_total; }
semaphore& get_semaphore() noexcept { return _sem; }
};
} // namespace service