调整保存USB图像时,不在IO锁当中执行,以便在save_usb_image中可以通过休眠来让其它线程有机会获取IO锁。

This commit is contained in:
gb 2023-12-04 16:29:55 +08:00
parent 9b10e91dba
commit ca041a1005
3 changed files with 76 additions and 76 deletions

View File

@ -714,22 +714,21 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
ret = status_;
else
{
std::lock_guard<std::mutex> lock(io_lock_);
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
if (!buf.get())
return SCANNER_ERR_INSUFFICIENT_MEMORY;
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
else // if (ret == SCANNER_ERR_OK)
{
std::lock_guard<std::mutex> lock(io_lock_);
// write reading command
ret = write_register(setting3399::SR_IM_TX, 1);
buf->set_image_statu(statu);
if (ret == SCANNER_ERR_OK)
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
r = total;
if (ret == SCANNER_ERR_OK)
{
unsigned int size = r;
@ -776,7 +775,7 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
{
VLOG_MINI_2(LOG_LEVEL_FATAL, "read_one_image_from_usb 'total' is %d, 'left' total len is:%d!!!\n", total, r);
}
}
if (ret == SCANNER_ERR_OK)
{
ret = save_usb_data(buf);
@ -790,7 +789,6 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
VLOG_MINI_1(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
}
}
}
if (is_scanner_err_ok)
{
pop_first_image();

View File

@ -576,19 +576,19 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
ret = status_;
else
{
std::lock_guard<std::mutex> lock(io_lock_);
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
if (!buf.get())
return SCANNER_ERR_INSUFFICIENT_MEMORY;
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
else // if (ret == SCANNER_ERR_OK)
{
// write reading command
buf->set_image_statu(statu);
ret = write_register(setting3399::SR_IM_TX, 1);
if (ret == SCANNER_ERR_OK)
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = write_register(setting3399::SR_IM_TX, 1);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
r = total;
if (ret == SCANNER_ERR_OK)
{
void* buff = buf->data(off, (unsigned int*)&r);
@ -607,6 +607,11 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
buff = buf->data(off, (unsigned int*)&r);
}
}
else
{
VLOG_MINI_1(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret));
}
}
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret));
if (ret == SCANNER_ERR_OK)
{
@ -630,10 +635,6 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
}
}
else
{
VLOG_MINI_1(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret));
}
}
if(popimg)
pop_first_image();

View File

@ -460,13 +460,14 @@ int hg_scanner_306::get_img_data_7010()
int ret = SCANNER_ERR_OK;
USBCB usb{ setting3288dsp::GET_IMAGE, 0, 0 };
{
setting3288dsp::HG_JpegCompressInfo info;
StopWatch sw;
{
std::lock_guard<std::mutex> lock(io_lock_);
ret = writeusb(usb);
io_->set_timeout(800);
setting3288dsp::HG_JpegCompressInfo info;
StopWatch sw;
sw.reset();
int len = sizeof(info);
ret = io_->read_bulk(&info, &len);
@ -493,7 +494,7 @@ int hg_scanner_306::get_img_data_7010()
index_ += frame_length_;
last_frame_total_ = info.index_frame;
}
}
if (info.last_frame)
{