Merge pull request #287 from grissiom/device-fix

Device fix
This commit is contained in:
Bernard Xiong 2014-06-18 13:46:50 +08:00
commit bab1763003
2 changed files with 12 additions and 9 deletions

View File

@ -471,17 +471,18 @@ static long _list_device(struct rt_list_node *list)
"Unknown" "Unknown"
}; };
rt_kprintf("device type \n"); rt_kprintf("device type ref count\n");
rt_kprintf("-------- ---------- \n"); rt_kprintf("-------- -------------------- ----------\n");
for (node = list->next; node != list; node = node->next) for (node = list->next; node != list; node = node->next)
{ {
device = (struct rt_device *)(rt_list_entry(node, struct rt_object, list)); device = (struct rt_device *)(rt_list_entry(node, struct rt_object, list));
rt_kprintf("%-8.*s %-8s \n", rt_kprintf("%-8.*s %-20s %-8d\n",
RT_NAME_MAX, RT_NAME_MAX,
device->parent.name, device->parent.name,
(device->type <= RT_Device_Class_Unknown) ? (device->type <= RT_Device_Class_Unknown) ?
device_type_str[device->type] : device_type_str[device->type] :
device_type_str[RT_Device_Class_Unknown]); device_type_str[RT_Device_Class_Unknown],
device->ref_count);
} }
return 0; return 0;

View File

@ -239,11 +239,6 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
return -RT_EBUSY; return -RT_EBUSY;
} }
dev->ref_count++;
/* don't let bad things happen silently. If you are bitten by this assert,
* please set the ref_count to a bigger type. */
RT_ASSERT(dev->ref_count != 0);
/* call device open interface */ /* call device open interface */
if (dev->open != RT_NULL) if (dev->open != RT_NULL)
{ {
@ -252,8 +247,15 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
/* set open flag */ /* set open flag */
if (result == RT_EOK || result == -RT_ENOSYS) if (result == RT_EOK || result == -RT_ENOSYS)
{
dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN; dev->open_flag = oflag | RT_DEVICE_OFLAG_OPEN;
dev->ref_count++;
/* don't let bad things happen silently. If you are bitten by this assert,
* please set the ref_count to a bigger type. */
RT_ASSERT(dev->ref_count != 0);
}
return result; return result;
} }
RTM_EXPORT(rt_device_open); RTM_EXPORT(rt_device_open);