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