mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-28 16:14:20 +08:00
add error checks of rt_mutex_take()
This commit is contained in:
@@ -58,7 +58,17 @@ static int sst25vfxx_read(struct rt_mtd_nor_device *device, rt_off_t position, r
|
||||
sst25 = SST25_MTD(device);
|
||||
RT_ASSERT(sst25 != RT_NULL);
|
||||
|
||||
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_kprintf("Take mutex time out.\n");
|
||||
return result;
|
||||
}
|
||||
else if (result == -RT_ERROR)
|
||||
{
|
||||
rt_kprintf("Take mutex error.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
fseek(sst25->file, position, SEEK_SET);
|
||||
result = fread(data, size, 1, sst25->file);
|
||||
@@ -78,7 +88,17 @@ static int sst25vfxx_write(struct rt_mtd_nor_device *device, rt_off_t position,
|
||||
sst25 = SST25_MTD(device);
|
||||
RT_ASSERT(sst25 != RT_NULL);
|
||||
|
||||
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_kprintf("Take mutex time out.\n");
|
||||
return result;
|
||||
}
|
||||
else if (result == -RT_ERROR)
|
||||
{
|
||||
rt_kprintf("Take mutex error.\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
fseek(sst25->file, position, SEEK_SET);
|
||||
result = fwrite(data, size, 1, sst25->file);
|
||||
@@ -99,7 +119,17 @@ static rt_err_t sst25vfxx_erase_block(struct rt_mtd_nor_device *device, rt_off_t
|
||||
|
||||
RT_ASSERT(sst25 != RT_NULL);
|
||||
|
||||
rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
result = rt_mutex_take(&flash_lock, RT_WAITING_FOREVER);
|
||||
if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
rt_kprintf("Take mutex time out.\n");
|
||||
return -RT_ETIMEOUT;
|
||||
}
|
||||
else if (result == -RT_ERROR)
|
||||
{
|
||||
rt_kprintf("Take mutex error.\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
memset(block_buffer, 0xFF, BLOCK_SIZE);
|
||||
fseek(sst25->file, offset, SEEK_SET);
|
||||
|
||||
Reference in New Issue
Block a user