make java maps grab locks am: 9eca02a8fa
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3134024 Change-Id: I42720232f9eb7b399c48fa7b68107fecf150a5be Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
c853c07517
3 changed files with 22 additions and 2 deletions
|
|
@ -52,6 +52,9 @@ public class BpfMap<K extends Struct, V extends Struct> implements IBpfMap<K, V>
|
|||
public static final int BPF_F_RDONLY = 1 << 3;
|
||||
public static final int BPF_F_WRONLY = 1 << 4;
|
||||
|
||||
// magic value for jni consumption, invalid from kernel point of view
|
||||
public static final int BPF_F_RDWR_EXCLUSIVE = BPF_F_RDONLY | BPF_F_WRONLY;
|
||||
|
||||
public static final int BPF_MAP_TYPE_HASH = 1;
|
||||
|
||||
private static final int BPF_F_NO_PREALLOC = 1;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class SingleWriterBpfMap<K extends Struct, V extends Struct> extends BpfM
|
|||
|
||||
public SingleWriterBpfMap(@NonNull final String path, final Class<K> key,
|
||||
final Class<V> value) throws ErrnoException, NullPointerException {
|
||||
super(path, BPF_F_RDWR, key, value);
|
||||
super(path, BPF_F_RDWR_EXCLUSIVE, key, value);
|
||||
|
||||
// Populate cache with the current map contents.
|
||||
K currentKey = super.getFirstKey();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,24 @@ static jint com_android_net_module_util_BpfMap_nativeBpfFdGet(JNIEnv *env, jclas
|
|||
jstring path, jint mode, jint keySize, jint valueSize) {
|
||||
ScopedUtfChars pathname(env, path);
|
||||
|
||||
jint fd = bpf::bpfFdGet(pathname.c_str(), static_cast<unsigned>(mode));
|
||||
jint fd = -1;
|
||||
switch (mode) {
|
||||
case 0:
|
||||
fd = bpf::mapRetrieveRW(pathname.c_str());
|
||||
break;
|
||||
case BPF_F_RDONLY:
|
||||
fd = bpf::mapRetrieveRO(pathname.c_str());
|
||||
break;
|
||||
case BPF_F_WRONLY:
|
||||
fd = bpf::mapRetrieveWO(pathname.c_str());
|
||||
break;
|
||||
case BPF_F_RDONLY|BPF_F_WRONLY:
|
||||
fd = bpf::mapRetrieveExclusiveRW(pathname.c_str());
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
jniThrowErrnoException(env, "nativeBpfFdGet", errno);
|
||||
|
|
|
|||
Loading…
Reference in a new issue