Release GIL when calling C++ params functions (#21257)

* Release GIL when calling C++ params functions

* small cleanup
old-commit-hash: 2f759893ca
commatwo_master
Willem Melching 4 years ago committed by GitHub
parent 34643d7afc
commit 0fb755e425
  1. 14
      common/params_pxd.pxd
  2. 31
      common/params_pyx.pyx

@ -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:
self.p = new c_Params(persistent_params)
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,16 +92,19 @@ 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)
self.p.putBool(k, val)
with nogil:
self.p.putBool(k, val)
def delete(self, 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):

Loading…
Cancel
Save