Release GIL when calling C++ params functions (#21257)
* Release GIL when calling C++ params functions * small cleanuppull/21275/head
parent
e28b5552e7
commit
2f759893ca
|
@ -17,12 +17,12 @@ cdef extern from "selfdrive/common/params.h":
|
||||||
ALL
|
ALL
|
||||||
|
|
||||||
cdef cppclass Params:
|
cdef cppclass Params:
|
||||||
Params(bool)
|
Params(bool) nogil
|
||||||
Params(string)
|
Params(string) nogil
|
||||||
string get(string, bool) nogil
|
string get(string, bool) nogil
|
||||||
bool getBool(string)
|
bool getBool(string) nogil
|
||||||
int remove(string)
|
int remove(string) nogil
|
||||||
int put(string, string)
|
int put(string, string) nogil
|
||||||
int putBool(string, bool)
|
int putBool(string, bool) nogil
|
||||||
bool checkKey(string)
|
bool checkKey(string) nogil
|
||||||
void clearAll(ParamKeyType)
|
void clearAll(ParamKeyType)
|
||||||
|
|
|
@ -31,10 +31,14 @@ cdef class Params:
|
||||||
cdef c_Params* p
|
cdef c_Params* p
|
||||||
|
|
||||||
def __cinit__(self, d=None, bool persistent_params=False):
|
def __cinit__(self, d=None, bool persistent_params=False):
|
||||||
|
cdef string path
|
||||||
if d is None:
|
if d is None:
|
||||||
self.p = new c_Params(persistent_params)
|
with nogil:
|
||||||
|
self.p = new c_Params(persistent_params)
|
||||||
else:
|
else:
|
||||||
self.p = new c_Params(<string>d.encode())
|
path = <string>d.encode()
|
||||||
|
with nogil:
|
||||||
|
self.p = new c_Params(path)
|
||||||
|
|
||||||
def __dealloc__(self):
|
def __dealloc__(self):
|
||||||
del self.p
|
del self.p
|
||||||
|
@ -53,13 +57,12 @@ cdef class Params:
|
||||||
|
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def get(self, key, block=False, encoding=None):
|
def get(self, key, bool block=False, encoding=None):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
cdef bool b = block
|
|
||||||
|
|
||||||
cdef string val
|
cdef string val
|
||||||
with nogil:
|
with nogil:
|
||||||
val = self.p.get(k, b)
|
val = self.p.get(k, block)
|
||||||
|
|
||||||
if val == b"":
|
if val == b"":
|
||||||
if block:
|
if block:
|
||||||
|
@ -76,7 +79,10 @@ cdef class Params:
|
||||||
|
|
||||||
def get_bool(self, key):
|
def get_bool(self, key):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
return self.p.getBool(k)
|
cdef bool r
|
||||||
|
with nogil:
|
||||||
|
r = self.p.getBool(k)
|
||||||
|
return r
|
||||||
|
|
||||||
def put(self, key, dat):
|
def put(self, key, dat):
|
||||||
"""
|
"""
|
||||||
|
@ -86,16 +92,19 @@ cdef class Params:
|
||||||
in general try to avoid writing params as much as possible.
|
in general try to avoid writing params as much as possible.
|
||||||
"""
|
"""
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
dat = ensure_bytes(dat)
|
cdef string dat_bytes = ensure_bytes(dat)
|
||||||
self.p.put(k, dat)
|
with nogil:
|
||||||
|
self.p.put(k, dat_bytes)
|
||||||
|
|
||||||
def put_bool(self, key, val):
|
def put_bool(self, key, bool val):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
self.p.putBool(k, val)
|
with nogil:
|
||||||
|
self.p.putBool(k, val)
|
||||||
|
|
||||||
def delete(self, key):
|
def delete(self, key):
|
||||||
cdef string k = self.check_key(key)
|
cdef string k = self.check_key(key)
|
||||||
self.p.remove(k)
|
with nogil:
|
||||||
|
self.p.remove(k)
|
||||||
|
|
||||||
|
|
||||||
def put_nonblocking(key, val, d=None):
|
def put_nonblocking(key, val, d=None):
|
||||||
|
|
Loading…
Reference in New Issue