本文整理汇总了C++中rt_mutex_take函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_mutex_take函数的具体用法?C++ rt_mutex_take怎么用?C++ rt_mutex_take使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_mutex_take函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dfs_jffs2_close
static int dfs_jffs2_close(struct dfs_fd* file)
{
int result;
cyg_file * jffs2_file;
RT_ASSERT(file->data != NULL);
jffs2_file = (cyg_file *)(file->data);
if (file->flags & DFS_O_DIRECTORY) /* operations about dir */
{
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
result = jffs2_dir_colse(jffs2_file);
rt_mutex_release(&jffs2_lock);
if (result)
return jffs2_result_to_dfs(result);
rt_free(jffs2_file);
return 0;
}
/* regular file operations */
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
result = jffs2_file_colse(jffs2_file);
rt_mutex_release(&jffs2_lock);
if (result)
return jffs2_result_to_dfs(result);
/* release memory */
rt_free(jffs2_file);
return 0;
}
示例2: thread1_entry
static void thread1_entry(void* parameter)
{
rt_err_t result;
result = rt_mutex_take(mutex, RT_WAITING_FOREVER);
result = rt_mutex_take(mutex, RT_WAITING_FOREVER);
rt_kprintf("thread1: got mutex\n");
if (result != RT_EOK)
{
return;
}
for(t1_count = 0; t1_count < 5;t1_count ++)
{
rt_kprintf("thread1:count: %d\n", t1_count);
}
if (t2->current_priority != t1->current_priority)
{
rt_kprintf("thread1: released mutex\n");
rt_mutex_release(mutex);
rt_mutex_release(mutex);
}
}
示例3: lcd1602_DispProcessing
void lcd1602_DispProcessing(uint8_t percent)
{
uint8_t i, BlockNum = 0;
uint8_t abyString[17];
rt_err_t rtResult;
//while (1)
{
BlockNum = ((uint32_t)percent * 16) / 99;
for (i = 0; i < 16; i++)
{
if (i < BlockNum)
{
abyString [i] = '#';
}
else
{
abyString [i] = ' ';
}
}
abyString[16] = 0;
rtResult = rt_mutex_take(LcdMutex, RT_WAITING_FOREVER);
if (rtResult == RT_EOK)
{
LCD_PutStr(abyString, 16, 16);
rt_mutex_release(LcdMutex);
}
}
}
示例4: rt_spi_transfer
rt_size_t rt_spi_transfer(struct rt_spi_device *device,
const void *send_buf,
void *recv_buf,
rt_size_t length)
{
rt_err_t result;
struct rt_spi_message message;
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL);
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
if (result == RT_EOK)
{
if (device->bus->owner != device)
{
/* not the same owner as current, re-configure SPI bus */
result = device->bus->ops->configure(device, &device->config);
if (result == RT_EOK)
{
/* set SPI bus owner */
device->bus->owner = device;
}
else
{
/* configure SPI bus failed */
rt_set_errno(-RT_EIO);
result = 0;
goto __exit;
}
}
/* initial message */
message.send_buf = send_buf;
message.recv_buf = recv_buf;
message.length = length;
message.cs_take = 1;
message.cs_release = 1;
message.next = RT_NULL;
/* transfer message */
result = device->bus->ops->xfer(device, &message);
if (result == 0)
{
rt_set_errno(-RT_EIO);
goto __exit;
}
}
else
{
rt_set_errno(-RT_EIO);
return 0;
}
__exit:
rt_mutex_release(&(device->bus->lock));
return result;
}
示例5: I2C_AcknowledgePolling
/*TODO: If your device need more time to initialize I2C bus or waiting memory write, you can use I2C_AcknowledgePolling avoid I2C bus lose.*/
Status I2C_AcknowledgePolling(I2C_TypeDef* I2Cx ,uint8_t Addr)
{
uint32_t timeout = 0xFFFF, ret;
uint16_t tmp;
ret = rt_mutex_take(i2c_mux, RT_WAITING_FOREVER );
if( ret == RT_EOK )
{
do{
if( timeout-- <= 0 )
{
I2C_ClearFlag(I2Cx,I2C_FLAG_AF);
I2Cx->CR1 |= CR1_STOP_Set;
rt_mutex_release(i2c_mux);
return Error;
}
I2Cx->CR1 |= CR1_START_Set;
tmp = I2Cx->SR1;//²M°£SB¦ì
I2Cx->DR = Addr;
}while((I2Cx->SR1&0x0002) != 0x0002);
I2C_ClearFlag(I2Cx,I2C_FLAG_AF);
I2Cx->CR1 |= CR1_STOP_Set;
while ((I2Cx->CR1&0x200) == 0x200);
rt_kprintf( "AcknowledgePolling OK\n");
rt_mutex_release(i2c_mux);
return Success;
}
else
return Error;
}
示例6: rt_spi_configure
rt_err_t rt_spi_configure(struct rt_spi_device* device, struct rt_spi_configuration* cfg)
{
rt_err_t result;
RT_ASSERT(device != RT_NULL);
/* set configuration */
device->config.data_width = cfg->data_width;
device->config.mode = cfg->mode & RT_SPI_MODE_MASK ;
device->config.max_hz = cfg->max_hz ;
if (device->bus != RT_NULL)
{
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
if (result == RT_EOK)
{
if (device->bus->owner == device)
{
device->bus->ops->configure(device, &device->config);
}
/* release lock */
rt_mutex_release(&(device->bus->lock));
}
}
return RT_EOK;
}
示例7: rt_i2c_transfer
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
rt_size_t ret;
if (bus->ops->master_xfer)
{
#ifdef RT_I2C_DEBUG
for (ret = 0; ret < num; ret++)
{
i2c_dbg("msgs[%d] %c, addr=0x%02x, len=%d%s\n", ret,
(msgs[ret].flags & RT_I2C_RD) ? 'R' : 'W',
msgs[ret].addr, msgs[ret].len);
}
#endif
rt_mutex_take(&bus->lock, RT_WAITING_FOREVER);
ret = bus->ops->master_xfer(bus, msgs, num);
rt_mutex_release(&bus->lock);
return ret;
}
else
{
i2c_dbg("I2C bus operation not supported\n");
return 0;
}
}
示例8: ff_req_grant
int ff_req_grant(_SYNC_t m)
{
if (rt_mutex_take(m, _FS_TIMEOUT) == RT_EOK)
return RT_TRUE;
return RT_FALSE;
}
示例9: pthread_mutex_lock
int pthread_mutex_lock(pthread_mutex_t *mutex)
{
int mtype;
rt_err_t result;
if (!mutex) return EINVAL;
if (mutex->attr == -1)
{
/* init mutex */
pthread_mutex_init(mutex, RT_NULL);
}
mtype = mutex->attr & MUTEXATTR_TYPE_MASK;
rt_enter_critical();
if (mutex->lock.owner == rt_thread_self() && mtype != PTHREAD_MUTEX_RECURSIVE)
{
rt_exit_critical();
return EDEADLK;
}
rt_exit_critical();
result = rt_mutex_take(&(mutex->lock), RT_WAITING_FOREVER);
if (result == RT_EOK) return 0;
return EINVAL;
}
示例10: sys_mutex_lock
/** Lock a mutex
* @param mutex the mutex to lock
*/
void sys_mutex_lock(sys_mutex_t *mutex)
{
RT_DEBUG_NOT_IN_INTERRUPT;
rt_mutex_take(*mutex, RT_WAITING_FOREVER);
return;
}
示例11: dfs_jffs2_write
static int dfs_jffs2_write(struct dfs_fd* file,
const void* buf,
rt_size_t len)
{
cyg_file * jffs2_file;
struct CYG_UIO_TAG uio_s;
struct CYG_IOVEC_TAG iovec;
int char_write;
int result;
RT_ASSERT(file->data != NULL);
jffs2_file = (cyg_file *)(file->data);
uio_s.uio_iov = &iovec;
uio_s.uio_iov->iov_base = (void *)buf;
uio_s.uio_iov->iov_len = len;
uio_s.uio_iovcnt = 1; //must be 1
//uio_s.uio_offset //not used...
uio_s.uio_resid = uio_s.uio_iov->iov_len; //seem no use in jffs2;
char_write = jffs2_file->f_offset;
rt_mutex_take(&jffs2_lock, RT_WAITING_FOREVER);
result = jffs2_file_write(jffs2_file, &uio_s);
rt_mutex_release(&jffs2_lock);
if (result)
return jffs2_result_to_dfs(result);
/* update position */
file->pos = jffs2_file->f_offset;
char_write = jffs2_file->f_offset - char_write;
return char_write;
}
示例12: dfs_lock
/**
* this function will lock device file system.
*
* @note please don't invoke it on ISR.
*/
void dfs_lock(void)
{
rt_err_t result;
result = rt_mutex_take(&fslock, RT_WAITING_FOREVER);
if (result != RT_EOK)
{
RT_ASSERT(0);
}
}
示例13: telnet_read
static rt_size_t telnet_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size)
{
rt_size_t result;
/* read from rx ring buffer */
rt_mutex_take(telnet->rx_ringbuffer_lock, RT_WAITING_FOREVER);
result = rt_ringbuffer_get(&(telnet->rx_ringbuffer), buffer, size);
rt_mutex_release(telnet->rx_ringbuffer_lock);
return result;
}
示例14: thread2_entry
static void thread2_entry(void* parameter)
{
rt_thread_delay(5);
rt_mutex_take(mutex, RT_WAITING_FOREVER);
rt_kprintf("thread2: got mutex\n");
for(t2_count = 0; t2_count < 5;t2_count ++)
{
rt_kprintf("thread2: count: %d\n", t2_count);
}
}
示例15: rt_thread_entry2
static void rt_thread_entry2(void* parameter)
{
rt_err_t result;
rt_tick_t tick;
/* 1. static mutex test */
rt_kprintf("thread2 try to get static mutex\n");
rt_mutex_take(&static_mutex, 10);
rt_kprintf("thread2 got static mutex\n");
rt_thread_delay(RT_TICK_PER_SECOND);
rt_kprintf("thread2 release static mutex\n");
rt_mutex_release(&static_mutex);
/* 2. dynamic mutex test */
rt_kprintf("thread2 try to get dynamic mutex\n");
rt_mutex_take(dynamic_mutex, 10);
rt_kprintf("thread2 got dynamic mutex\n");
rt_thread_delay(RT_TICK_PER_SECOND);
rt_kprintf("thread2 release dynamic mutex\n");
rt_mutex_release(dynamic_mutex);
}