本文整理汇总了C++中spin_trylock函数的典型用法代码示例。如果您正苦于以下问题:C++ spin_trylock函数的具体用法?C++ spin_trylock怎么用?C++ spin_trylock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spin_trylock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: x86_backtrace
void
x86_backtrace(struct pt_regs * const regs, unsigned int depth)
{
struct frame_head *head;
#ifdef CONFIG_X86_64
head = (struct frame_head *)regs->rbp;
#else
head = (struct frame_head *)regs->ebp;
#endif
if (!user_mode_vm(regs)) {
while (depth-- && valid_kernel_stack(head, regs))
head = dump_backtrace(head);
return;
}
#ifdef CONFIG_SMP
if (!spin_trylock(¤t->mm->page_table_lock))
return;
#endif
while (depth-- && head && pages_present(head))
head = dump_backtrace(head);
#ifdef CONFIG_SMP
spin_unlock(¤t->mm->page_table_lock);
#endif
}
示例2: serial_hsu_console_write
/*
* Print a string to the serial port trying not to disturb
* any possible real use of the port...
*
* The console_lock must be held when we get here.
*/
static void
serial_hsu_console_write(struct console *co, const char *s, unsigned int count)
{
struct uart_hsu_port *up = serial_hsu_ports[co->index];
unsigned long flags;
unsigned int ier;
int locked = 1;
local_irq_save(flags);
if (up->port.sysrq)
locked = 0;
else if (oops_in_progress) {
locked = spin_trylock(&up->port.lock);
} else
spin_lock(&up->port.lock);
/* First save the IER then disable the interrupts */
ier = serial_in(up, UART_IER);
serial_out(up, UART_IER, 0);
uart_console_write(&up->port, s, count, serial_hsu_console_putchar);
/*
* Finally, wait for transmitter to become empty
* and restore the IER
*/
wait_for_xmitr(up);
serial_out(up, UART_IER, ier);
if (locked)
spin_unlock(&up->port.lock);
local_irq_restore(flags);
}
示例3: serial_tx_interrupt
void serial_tx_interrupt(struct serial_port *port, struct cpu_user_regs *regs)
{
int i, n;
unsigned long flags;
local_irq_save(flags);
/*
* Avoid spinning for a long time: if there is a long-term lock holder
* then we know that they'll be stuffing bytes into the transmitter which
* will therefore not be empty for long.
*/
while ( !spin_trylock(&port->tx_lock) )
{
if ( port->driver->tx_ready(port) <= 0 )
goto out;
cpu_relax();
}
for ( i = 0, n = port->driver->tx_ready(port); i < n; i++ )
{
if ( port->txbufc == port->txbufp )
break;
port->driver->putc(
port, port->txbuf[mask_serial_txbuf_idx(port->txbufc++)]);
}
if ( i && port->driver->flush )
port->driver->flush(port);
spin_unlock(&port->tx_lock);
out:
local_irq_restore(flags);
}
示例4: set_a_bus_req
static ssize_t
set_a_bus_req(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct mv_otg *mvotg = dev_get_drvdata(dev);
if (count > 2)
return -1;
/* We will use this interface to change to A device */
if (mvotg->phy.state != OTG_STATE_B_IDLE
&& mvotg->phy.state != OTG_STATE_A_IDLE)
return -1;
/* The clock may disabled and we need to set irq for ID detected */
mv_otg_enable(mvotg);
mv_otg_init_irq(mvotg);
if (buf[0] == '1') {
mvotg->otg_ctrl.a_bus_req = 1;
mvotg->otg_ctrl.a_bus_drop = 0;
dev_dbg(&mvotg->pdev->dev,
"User request: a_bus_req = 1\n");
if (spin_trylock(&mvotg->wq_lock)) {
mv_otg_run_state_machine(mvotg, 0);
spin_unlock(&mvotg->wq_lock);
}
}
return count;
}
示例5: softuart_downcall
/*
* This is called when the HV needs to signal that receive data is
* available to read or that transmit buffer space has become
* available.
*/
static void softuart_downcall(struct hv_driver_cb *cb, __hv32 reason)
{
unsigned long flags;
local_irq_save(flags);
if (spin_trylock(&softuart_callback_lock)) {
struct softuart_private *softuartp =
(struct softuart_private *)cb->dev;
struct tty_struct *tty = softuartp->tty;
if (tty) {
if (reason == SOFTUART_CLIENTINT_RX) {
/*
* Some data has been received by the
* HV driver and is ready to read.
*/
softuart_do_receive_chars(tty);
} else if (reason == SOFTUART_CLIENTINT_WRITEROOM) {
/*
* If the output buffer had filled up then the
* tty has been put to sleep. The HV has
* indicated that there's buffer space
* available, so we wake the tty up.
*/
if (waitqueue_active(&tty->write_wait) &&
softuart_write_room(tty))
tty_wakeup(tty);
}
}
spin_unlock(&softuart_callback_lock);
}
local_irq_restore(flags);
}
示例6: set_a_bus_drop
static ssize_t
set_a_bus_drop(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct mv_otg *mvotg = dev_get_drvdata(dev);
if (!mvotg->phy.otg->default_a)
return -1;
if (count > 2)
return -1;
if (buf[0] == '0') {
mvotg->otg_ctrl.a_bus_drop = 0;
dev_dbg(&mvotg->pdev->dev,
"User request: a_bus_drop = 0\n");
} else if (buf[0] == '1') {
mvotg->otg_ctrl.a_bus_drop = 1;
mvotg->otg_ctrl.a_bus_req = 0;
dev_dbg(&mvotg->pdev->dev,
"User request: a_bus_drop = 1\n");
dev_dbg(&mvotg->pdev->dev,
"User request: and a_bus_req = 0\n");
}
if (spin_trylock(&mvotg->wq_lock)) {
mv_otg_run_state_machine(mvotg, 0);
spin_unlock(&mvotg->wq_lock);
}
return count;
}
示例7: spinLock_write
static ssize_t spinLock_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
// char *cmd = (char *) malloc(sizeof(char *));
char cmd[10] = { 0 };
if (copy_from_user(cmd, (void*) buf, count))
{
return -EINVAL;
}
else
{
if (strcmp("lock\n", cmd) == 0)
{
spin_lock(&lock);
mdelay(10000);
spin_unlock(&lock);
}
else if (strcmp("trylock\n", cmd) == 0)
{
if (spin_trylock(&lock))
{
printk("spin_lock is available\n");
spin_unlock(&lock);
}
else
{
printk("spin_lock is busy\n");
return -EBUSY;
}
}
return count;
}
}
示例8: mce_spin_lock
static void mce_spin_lock(spinlock_t *lk)
{
while (!spin_trylock(lk)) {
cpu_relax();
mce_panic_check();
}
}
示例9: t1_espi_get_mon_t204
/*
* This function is for T204 only.
* compare with t1_espi_get_mon(), it reads espiInTxSop[0 ~ 3] in
* one shot, since there is no per port counter on the out side.
*/
int t1_espi_get_mon_t204(adapter_t *adapter, u32 *valp, u8 wait)
{
struct peespi *espi = adapter->espi;
u8 i, nport = (u8)adapter->params.nports;
if (!wait) {
if (!spin_trylock(&espi->lock))
return -1;
} else
spin_lock(&espi->lock);
if ((espi->misc_ctrl & MON_MASK) != F_MONITORED_DIRECTION) {
espi->misc_ctrl = (espi->misc_ctrl & ~MON_MASK) |
F_MONITORED_DIRECTION;
writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
}
for (i = 0 ; i < nport; i++, valp++) {
if (i) {
writel(espi->misc_ctrl | V_MONITORED_PORT_NUM(i),
adapter->regs + A_ESPI_MISC_CONTROL);
}
*valp = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
}
writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
spin_unlock(&espi->lock);
return 0;
}
示例10: t1_espi_get_mon
u32 t1_espi_get_mon(adapter_t *adapter, u32 addr, u8 wait)
{
struct peespi *espi = adapter->espi;
u32 sel;
if (!is_T2(adapter))
return 0;
sel = V_MONITORED_PORT_NUM((addr & 0x3c) >> 2);
if (!wait) {
if (!spin_trylock(&espi->lock))
return 0;
} else
spin_lock(&espi->lock);
if ((sel != (espi->misc_ctrl & MON_MASK))) {
writel(((espi->misc_ctrl & ~MON_MASK) | sel),
adapter->regs + A_ESPI_MISC_CONTROL);
sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
writel(espi->misc_ctrl, adapter->regs + A_ESPI_MISC_CONTROL);
} else
sel = readl(adapter->regs + A_ESPI_SCH_TOKEN3);
spin_unlock(&espi->lock);
return sel;
}
示例11: autofs4_sbi
/*
* Calculate and dget next entry in top down tree traversal.
*/
static struct dentry *get_next_positive_dentry(struct dentry *prev,
struct dentry *root)
{
struct autofs_sb_info *sbi = autofs4_sbi(root->d_sb);
struct list_head *next;
struct dentry *p, *ret;
if (prev == NULL)
return dget(root);
spin_lock(&sbi->lookup_lock);
relock:
p = prev;
spin_lock(&p->d_lock);
again:
next = p->d_subdirs.next;
if (next == &p->d_subdirs) {
while (1) {
struct dentry *parent;
if (p == root) {
spin_unlock(&p->d_lock);
spin_unlock(&sbi->lookup_lock);
dput(prev);
return NULL;
}
parent = p->d_parent;
if (!spin_trylock(&parent->d_lock)) {
spin_unlock(&p->d_lock);
cpu_relax();
goto relock;
}
spin_unlock(&p->d_lock);
next = p->d_child.next;
p = parent;
if (next != &parent->d_subdirs)
break;
}
}
ret = list_entry(next, struct dentry, d_child);
spin_lock_nested(&ret->d_lock, DENTRY_D_LOCK_NESTED);
/* Negative dentry - try next */
if (!simple_positive(ret)) {
spin_unlock(&p->d_lock);
lock_set_subclass(&ret->d_lock.dep_map, 0, _RET_IP_);
p = ret;
goto again;
}
dget_dlock(ret);
spin_unlock(&ret->d_lock);
spin_unlock(&p->d_lock);
spin_unlock(&sbi->lookup_lock);
dput(prev);
return ret;
}
示例12: pstore_dump
/*
* callback from kmsg_dump. (s2,l2) has the most recently
* written bytes, older bytes are in (s1,l1). Save as much
* as we can from the end of the buffer.
*/
static void pstore_dump(struct kmsg_dumper *dumper,
enum kmsg_dump_reason reason,
const char *s1, unsigned long l1,
const char *s2, unsigned long l2)
{
unsigned long s1_start, s2_start;
unsigned long l1_cpy, l2_cpy;
unsigned long size, total = 0;
char *dst;
const char *why;
u64 id;
int hsize, ret;
unsigned int part = 1;
unsigned long flags = 0;
int is_locked = 0;
why = get_reason_str(reason);
if (in_nmi()) {
is_locked = spin_trylock(&psinfo->buf_lock);
if (!is_locked)
pr_err("pstore dump routine blocked in NMI, may corrupt error record\n");
} else
spin_lock_irqsave(&psinfo->buf_lock, flags);
oopscount++;
while (total < kmsg_bytes) {
dst = psinfo->buf;
hsize = sprintf(dst, "%s#%d Part%d\n", why, oopscount, part);
size = psinfo->bufsize - hsize;
dst += hsize;
l2_cpy = min(l2, size);
l1_cpy = min(l1, size - l2_cpy);
if (l1_cpy + l2_cpy == 0)
break;
s2_start = l2 - l2_cpy;
s1_start = l1 - l1_cpy;
memcpy(dst, s1 + s1_start, l1_cpy);
memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
ret = psinfo->write(PSTORE_TYPE_DMESG, reason, &id, part,
oopscount, hsize + l1_cpy + l2_cpy, psinfo);
if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
pstore_new_entry = 1;
l1 -= l1_cpy;
l2 -= l2_cpy;
total += l1_cpy + l2_cpy;
part++;
}
if (in_nmi()) {
if (is_locked)
spin_unlock(&psinfo->buf_lock);
} else
spin_unlock_irqrestore(&psinfo->buf_lock, flags);
}
示例13: process_hvlpevents
void process_hvlpevents(void)
{
struct HvLpEvent * event;
restart:
/* If we have recursed, just return */
if (!spin_trylock(&hvlpevent_queue.hq_lock))
return;
for (;;) {
event = get_next_hvlpevent();
if (event) {
/* Call appropriate handler here, passing
* a pointer to the LpEvent. The handler
* must make a copy of the LpEvent if it
* needs it in a bottom half. (perhaps for
* an ACK)
*
* Handlers are responsible for ACK processing
*
* The Hypervisor guarantees that LpEvents will
* only be delivered with types that we have
* registered for, so no type check is necessary
* here!
*/
if (event->xType < HvLpEvent_Type_NumTypes)
__get_cpu_var(hvlpevent_counts)[event->xType]++;
if (event->xType < HvLpEvent_Type_NumTypes &&
lpEventHandler[event->xType])
lpEventHandler[event->xType](event);
else {
u8 type = event->xType;
/*
* Don't printk in the spinlock as printk
* may require ack events form the HV to send
* any characters there.
*/
hvlpevent_clear_valid(event);
spin_unlock(&hvlpevent_queue.hq_lock);
printk(KERN_INFO
"Unexpected Lp Event type=%d\n", type);
goto restart;
}
hvlpevent_clear_valid(event);
} else if (hvlpevent_queue.hq_overflow_pending)
/*
* No more valid events. If overflow events are
* pending process them
*/
HvCallEvent_getOverflowLpEvents(hvlpevent_queue.hq_index);
else
break;
}
spin_unlock(&hvlpevent_queue.hq_lock);
}
示例14: srecorder_unregister_external_log
/**
@function: int srecorder_unregister_external_log(unsigned id)
@brief:
@param:
@return:
@note:
**/
int srecorder_unregister_external_log(unsigned id)
{
log_registration_entry_t* prev_entry = NULL;
log_registration_entry_t* curr_entry = NULL;
if (spin_trylock(&srecorder_registration_lock) == 0)
{
return -1;
}
if (spin_trylock(&srecorder_list_lock) == 0)
{
goto reg_out;
}
curr_entry = p_log_registration_list;
while (curr_entry != NULL)
{
if (curr_entry->info.log_id == id)
{
if (curr_entry == p_log_registration_list)
{
p_log_registration_list = curr_entry->next;
}
else
{
prev_entry->next = curr_entry->next;
}
spin_unlock(&srecorder_list_lock);
spin_unlock(&srecorder_registration_lock);
kfree(curr_entry);
return 0;
}
prev_entry = curr_entry;
curr_entry = curr_entry->next;
}
/* return if nothing found in loop */
spin_unlock(&srecorder_list_lock);
reg_out:
spin_unlock(&srecorder_registration_lock);
return -1;
}
示例15: smp_make_wrapper
handler_wrapper_t*
smp_make_wrapper()
{
int i;
for(i = 0; i < sizeof(wrapper_pool)/sizeof(wrapper_pool[0]); i++)
if(spin_trylock(&wrapper_pool[i].lock) == 0)
return &wrapper_pool[i];
return NULL;
}