Merge pull request #3523 from DavidLin1577/patch-3

[components/drivers] update pipe.c
This commit is contained in:
Bernard Xiong 2020-04-14 10:36:46 +08:00 committed by GitHub
commit aaecf9414b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -323,18 +323,29 @@ static const struct dfs_file_ops pipe_fops =
rt_err_t rt_pipe_open (rt_device_t device, rt_uint16_t oflag)
{
rt_pipe_t *pipe = (rt_pipe_t *)device;
rt_err_t ret = RT_EOK;
if (device == RT_NULL) return -RT_EINVAL;
if (device == RT_NULL)
{
ret = -RT_EINVAL;
goto __exit;
}
rt_mutex_take(&(pipe->lock), RT_WAITING_FOREVER);
if (pipe->fifo == RT_NULL)
{
pipe->fifo = rt_ringbuffer_create(pipe->bufsz);
if (pipe->fifo == RT_NULL)
{
ret = -RT_ENOMEM;
}
}
rt_mutex_release(&(pipe->lock));
return RT_EOK;
__exit:
return ret;
}
rt_err_t rt_pipe_close (rt_device_t device)