
Instead of explicitly disabling a feature by declaring the variable and set it to false, this change supports the optional flags. I.e., you can skip certain flags if you are not using it. This optional feature supports both forms, 1. Value: A parameter for a feature. E.g., EnableRandomOffset 2. Type: A C++ type implementing a feature. E.g., ConditionVariableT On the other hand, to access the flags will be through one of the wrappers, BaseConfig/PrimaryConfig/SecondaryConfig/CacheConfig (CacheConfig is embedded in SecondaryConfig). These wrappers have the getters to access the value and the type. When adding a new feature, we need to add it to `allocator_config.def` and mark the new variable with either *_REQUIRED_* or *_OPTIONAL_* macro so that the accessor will be generated properly. In addition, also remove the need of `UseConditionVariable` to flip on/off of condition variable. Now we only need to define the type of condition variable.
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
//===-- condition_variable.h ------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SCUDO_CONDITION_VARIABLE_H_
|
|
#define SCUDO_CONDITION_VARIABLE_H_
|
|
|
|
#include "condition_variable_base.h"
|
|
|
|
#include "common.h"
|
|
#include "platform.h"
|
|
|
|
#include "condition_variable_linux.h"
|
|
|
|
namespace scudo {
|
|
|
|
// A default implementation of default condition variable. It doesn't do a real
|
|
// `wait`, instead it spins a short amount of time only.
|
|
class ConditionVariableDummy
|
|
: public ConditionVariableBase<ConditionVariableDummy> {
|
|
public:
|
|
void notifyAllImpl(UNUSED HybridMutex &M) REQUIRES(M) {}
|
|
|
|
void waitImpl(UNUSED HybridMutex &M) REQUIRES(M) {
|
|
M.unlock();
|
|
|
|
constexpr u32 SpinTimes = 64;
|
|
volatile u32 V = 0;
|
|
for (u32 I = 0; I < SpinTimes; ++I) {
|
|
u32 Tmp = V + 1;
|
|
V = Tmp;
|
|
}
|
|
|
|
M.lock();
|
|
}
|
|
};
|
|
|
|
} // namespace scudo
|
|
|
|
#endif // SCUDO_CONDITION_VARIABLE_H_
|