Pin buffer around potential async operations (#1193)
This commit is contained in:
Родитель
ca1b1739d9
Коммит
3879067799
|
@ -35,7 +35,9 @@ public:
|
|||
Buffer readBuffer(int address, int size, bool repeat = false)
|
||||
{
|
||||
Buffer buf = mkBuffer(NULL, size);
|
||||
registerGCObj(buf);
|
||||
int status = this->i2c.read(address << 1, buf->data, size, repeat);
|
||||
unregisterGCObj(buf);
|
||||
if (status != ErrorCode::DEVICE_OK) {
|
||||
buf = 0;
|
||||
}
|
||||
|
|
|
@ -190,7 +190,9 @@ Buffer LinuxSerialDevice::readBuffer() {
|
|||
pthread_mutex_lock(&lock);
|
||||
int sz = bufferedSize();
|
||||
auto r = mkBuffer(NULL, sz);
|
||||
registerGCObj(r);
|
||||
int sz2 = readBuf(r->data, sz);
|
||||
unegisterGCObj(r);
|
||||
if (sz != sz2)
|
||||
target_panic(999);
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
|
|
@ -51,17 +51,16 @@ class CodalSerialDeviceProxy {
|
|||
// n maybe 0 but we still call read to force
|
||||
// to initialize rx
|
||||
auto buf = mkBuffer(NULL, n);
|
||||
auto res = buf;
|
||||
registerGCObj(buf);
|
||||
auto read = ser.read(buf->data, buf->length, SerialMode::ASYNC);
|
||||
if (read == DEVICE_SERIAL_IN_USE || read == 0) { // someone else is reading
|
||||
return mkBuffer(NULL, 0);
|
||||
res = mkBuffer(NULL, 0);
|
||||
} else if (buf->length != read) {
|
||||
res = mkBuffer(buf->data, read);
|
||||
}
|
||||
if (buf->length != read) {
|
||||
registerGCObj(buf);
|
||||
auto buf2 = mkBuffer(buf->data, read);
|
||||
unregisterGCObj(buf);
|
||||
buf = buf2;
|
||||
}
|
||||
return buf;
|
||||
unregisterGCObj(buf);
|
||||
return res;
|
||||
}
|
||||
|
||||
void writeBuffer(Buffer buffer) {
|
||||
|
|
|
@ -164,8 +164,10 @@ Buffer readAsBuffer(String filename) {
|
|||
if (sz > 0xffff)
|
||||
return NULL;
|
||||
auto res = mkBuffer(NULL, sz);
|
||||
registerGCObj(res);
|
||||
f->seek(0);
|
||||
f->read(res->data, res->length);
|
||||
unregisterGCObj(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче