本文整理汇总了C++中DECLARE_WAITQUEUE函数的典型用法代码示例。如果您正苦于以下问题:C++ DECLARE_WAITQUEUE函数的具体用法?C++ DECLARE_WAITQUEUE怎么用?C++ DECLARE_WAITQUEUE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DECLARE_WAITQUEUE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mtd_ipanic_block_erase
static void mtd_ipanic_block_erase(void)
{
struct mtd_ipanic_data *ctx = &mtd_drv_ctx;
struct erase_info erase;
DECLARE_WAITQUEUE(wait, current);
wait_queue_head_t wait_q;
int rc, i;
init_waitqueue_head(&wait_q);
erase.mtd = ctx->mtd;
erase.callback = mtd_ipanic_block_erase_callback;
erase.len = ctx->mtd->erasesize;
erase.priv = (u_long)&wait_q;
for (i = 0; i < ctx->mtd->size; i += ctx->mtd->erasesize) {
erase.addr = i;
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&wait_q, &wait);
rc = ctx->mtd->_block_isbad(ctx->mtd, erase.addr);
if (rc < 0) {
xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
"aee-ipanic: Bad block check "
"failed (%d)\n", rc);
goto out;
}
if (rc) {
xlog_printk(ANDROID_LOG_WARN, IPANIC_LOG_TAG,
"aee-ipanic: Skipping erase of bad "
"block @%llx\n", erase.addr);
set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait);
continue;
}
rc = ctx->mtd->_erase(ctx->mtd, &erase);
if (rc) {
set_current_state(TASK_RUNNING);
remove_wait_queue(&wait_q, &wait);
xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
"aee-ipanic: Erase of 0x%llx, 0x%llx failed\n",
(unsigned long long) erase.addr,
(unsigned long long) erase.len);
if (rc == -EIO) {
if (ctx->mtd->_block_markbad(ctx->mtd,
erase.addr)) {
xlog_printk(ANDROID_LOG_ERROR, IPANIC_LOG_TAG,
"aee-ipanic: Err marking blk bad\n");
goto out;
}
xlog_printk(ANDROID_LOG_INFO, IPANIC_LOG_TAG,
"aee-ipanic: Marked a bad block"
" @%llx\n", erase.addr);
continue;
}
goto out;
}
schedule();
remove_wait_queue(&wait_q, &wait);
}
xlog_printk(ANDROID_LOG_DEBUG, IPANIC_LOG_TAG, "aee-ipanic: %s partition erased\n",
AEE_IPANIC_PLABEL);
out:
return;
}
示例2: n_hdlc_tty_write
/**
* n_hdlc_tty_write - write a single frame of data to device
* @tty - pointer to associated tty device instance data
* @file - pointer to file object data
* @data - pointer to transmit data (one frame)
* @count - size of transmit frame in bytes
*
* Returns the number of bytes written (or error code).
*/
static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
const unsigned char *data, size_t count)
{
struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
int error = 0;
DECLARE_WAITQUEUE(wait, current);
struct n_hdlc_buf *tbuf;
if (debuglevel >= DEBUG_LEVEL_INFO)
printk("%s(%d)n_hdlc_tty_write() called count=%zd\n",
__FILE__,__LINE__,count);
/* Verify pointers */
if (!n_hdlc)
return -EIO;
if (n_hdlc->magic != HDLC_MAGIC)
return -EIO;
/* verify frame size */
if (count > maxframe ) {
if (debuglevel & DEBUG_LEVEL_INFO)
printk (KERN_WARNING
"n_hdlc_tty_write: truncating user packet "
"from %lu to %d\n", (unsigned long) count,
maxframe );
count = maxframe;
}
add_wait_queue(&tty->write_wait, &wait);
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list);
if (tbuf)
break;
if (tty_io_nonblock(tty, file)) {
error = -EAGAIN;
break;
}
schedule();
n_hdlc = tty2n_hdlc (tty);
if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
tty != n_hdlc->tty) {
printk("n_hdlc_tty_write: %p invalid after wait!\n", n_hdlc);
error = -EIO;
break;
}
if (signal_pending(current)) {
error = -EINTR;
break;
}
}
__set_current_state(TASK_RUNNING);
remove_wait_queue(&tty->write_wait, &wait);
if (!error) {
/* Retrieve the user's buffer */
memcpy(tbuf->buf, data, count);
/* Send the data */
tbuf->count = error = count;
n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
n_hdlc_send_frames(n_hdlc,tty);
}
return error;
} /* end of n_hdlc_tty_write() */
示例3: n_tty_read
static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
unsigned char __user *buf, size_t nr)
{
unsigned char __user *b = buf;
DECLARE_WAITQUEUE(wait, current);
int c;
int minimum, time;
ssize_t retval = 0;
ssize_t size;
long timeout;
unsigned long flags;
int packet;
do_it_again:
if (WARN_ON(!tty->read_buf))
return -EAGAIN;
c = job_control(tty, file);
if (c < 0)
return c;
minimum = time = 0;
timeout = MAX_SCHEDULE_TIMEOUT;
if (!tty->icanon) {
time = (HZ / 10) * TIME_CHAR(tty);
minimum = MIN_CHAR(tty);
if (minimum) {
if (time)
tty->minimum_to_wake = 1;
else if (!waitqueue_active(&tty->read_wait) ||
(tty->minimum_to_wake > minimum))
tty->minimum_to_wake = minimum;
} else {
timeout = 0;
if (time) {
timeout = time;
time = 0;
}
tty->minimum_to_wake = minimum = 1;
}
}
if (file->f_flags & O_NONBLOCK) {
if (!mutex_trylock(&tty->atomic_read_lock))
return -EAGAIN;
} else {
if (mutex_lock_interruptible(&tty->atomic_read_lock))
return -ERESTARTSYS;
}
packet = tty->packet;
add_wait_queue(&tty->read_wait, &wait);
while (nr) {
if (packet && tty->link->ctrl_status) {
unsigned char cs;
if (b != buf)
break;
spin_lock_irqsave(&tty->link->ctrl_lock, flags);
cs = tty->link->ctrl_status;
tty->link->ctrl_status = 0;
spin_unlock_irqrestore(&tty->link->ctrl_lock, flags);
if (tty_put_user(tty, cs, b++)) {
retval = -EFAULT;
b--;
break;
}
nr--;
break;
}
set_current_state(TASK_INTERRUPTIBLE);
if (((minimum - (b - buf)) < tty->minimum_to_wake) &&
((minimum - (b - buf)) >= 1))
tty->minimum_to_wake = (minimum - (b - buf));
if (!input_available_p(tty, 0)) {
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
retval = -EIO;
break;
}
if (tty_hung_up_p(file))
break;
if (!timeout)
break;
if (file->f_flags & O_NONBLOCK) {
retval = -EAGAIN;
break;
}
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
n_tty_set_room(tty);
timeout = schedule_timeout(timeout);
BUG_ON(!tty->read_buf);
continue;
}
__set_current_state(TASK_RUNNING);
//.........这里部分代码省略.........
示例4: mtd_ioctl
static int mtd_ioctl(struct inode *inode, struct file *file,
u_int cmd, u_long arg)
{
struct mtd_info *mtd = (struct mtd_info *)file->private_data;
int ret = 0;
u_long size;
DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
if (cmd & IOC_IN) {
ret = verify_area(VERIFY_READ, (char *)arg, size);
if (ret) return ret;
}
if (cmd & IOC_OUT) {
ret = verify_area(VERIFY_WRITE, (char *)arg, size);
if (ret) return ret;
}
switch (cmd) {
case MEMGETREGIONCOUNT:
if (copy_to_user((int *) arg, &(mtd->numeraseregions), sizeof(int)))
return -EFAULT;
break;
case MEMGETREGIONINFO:
{
struct region_info_user ur;
if (copy_from_user( &ur,
(struct region_info_user *)arg,
sizeof(struct region_info_user))) {
return -EFAULT;
}
if (ur.regionindex >= mtd->numeraseregions)
return -EINVAL;
if (copy_to_user((struct mtd_erase_region_info *) arg,
&(mtd->eraseregions[ur.regionindex]),
sizeof(struct mtd_erase_region_info)))
return -EFAULT;
break;
}
case MEMGETINFO:
if (copy_to_user((struct mtd_info *)arg, mtd,
sizeof(struct mtd_info_user)))
return -EFAULT;
break;
case MEMERASE:
{
struct erase_info *erase=kmalloc(sizeof(struct erase_info),GFP_KERNEL);
if (!erase)
ret = -ENOMEM;
else {
wait_queue_head_t waitq;
DECLARE_WAITQUEUE(wait, current);
init_waitqueue_head(&waitq);
memset (erase,0,sizeof(struct erase_info));
if (copy_from_user(&erase->addr, (u_long *)arg,
2 * sizeof(u_long))) {
kfree(erase);
return -EFAULT;
}
erase->mtd = mtd;
erase->callback = mtd_erase_callback;
erase->priv = (unsigned long)&waitq;
/*
FIXME: Allow INTERRUPTIBLE. Which means
not having the wait_queue head on the stack.
If the wq_head is on the stack, and we
leave because we got interrupted, then the
wq_head is no longer there when the
callback routine tries to wake us up.
*/
ret = mtd->erase(mtd, erase);
if (!ret) {
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(&waitq, &wait);
if (erase->state != MTD_ERASE_DONE &&
erase->state != MTD_ERASE_FAILED)
schedule();
remove_wait_queue(&waitq, &wait);
set_current_state(TASK_RUNNING);
ret = (erase->state == MTD_ERASE_FAILED)?-EIO:0;
}
kfree(erase);
}
break;
}
case MEMWRITEOOB:
{
struct mtd_oob_buf buf;
//.........这里部分代码省略.........
开发者ID:jameshilliard,项目名称:actiontec_opensource_mi424wr-rev-acd-56-0-10-14-4,代码行数:101,代码来源:mtdchar-compat.c
示例5: cx18_stop_v4l2_encode_stream
int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
{
struct cx18 *cx = s->cx;
unsigned long then;
if (!cx18_stream_enabled(s))
return -EINVAL;
/* This function assumes that you are allowed to stop the capture
and that we are actually capturing */
CX18_DEBUG_INFO("Stop Capture\n");
if (atomic_read(&cx->tot_capturing) == 0)
return 0;
set_bit(CX18_F_S_STOPPING, &s->s_flags);
if (s->type == CX18_ENC_STREAM_TYPE_MPG)
cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, !gop_end);
else
cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
then = jiffies;
if (s->type == CX18_ENC_STREAM_TYPE_MPG && gop_end) {
#if 0
/* only run these if we're shutting down the last cap */
DECLARE_WAITQUEUE(wait, current);
unsigned long duration;
then = jiffies;
add_wait_queue(&cx->cap_w, &wait);
set_current_state(TASK_INTERRUPTIBLE);
/* TODO: wait 2s for EOS interrupt */
while (!test_bit(CX18_F_I_EOS, &cx->i_flags) &&
time_before(jiffies, then + msecs_to_jiffies(2000)))
schedule_timeout(msecs_to_jiffies(10));
duration = jiffies_to_msecs(jiffies - then);
if (!test_bit(CX18_F_I_EOS, &cx->i_flags)) {
CX18_DEBUG_WARN("%s: EOS interrupt not received! stopping anyway.\n", s->name);
CX18_DEBUG_WARN("%s: waited %lu ms.\n", s->name, duration);
} else {
CX18_DEBUG_INFO("%s: EOS took %lu ms to occur.\n", s->name, duration);
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&cx->cap_w, &wait);
#else
CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
#endif
}
if (s->type != CX18_ENC_STREAM_TYPE_TS)
atomic_dec(&cx->ana_capturing);
atomic_dec(&cx->tot_capturing);
/* Clear capture and no-read bits */
clear_bit(CX18_F_S_STREAMING, &s->s_flags);
/* Tell the CX23418 it can't use our buffers anymore */
cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
s->handle = CX18_INVALID_TASK_HANDLE;
clear_bit(CX18_F_S_STOPPING, &s->s_flags);
if (atomic_read(&cx->tot_capturing) > 0)
return 0;
cx18_write_reg(cx, 5, CX18_DSP0_INTERRUPT_MASK);
wake_up(&s->waitq);
return 0;
}
示例6: MlmeHalt
/*
========================================================================
Routine Description:
Close raxx interface.
Arguments:
*net_dev the raxx interface pointer
Return Value:
0 Open OK
otherwise Open Fail
Note:
1. if open fail, kernel will not call the close function.
2. Free memory for
(1) Mlme Memory Handler: MlmeHalt()
(2) TX & RX: RTMPFreeTxRxRingMemory()
(3) BA Reordering: ba_reordering_resource_release()
========================================================================
*/
int rt28xx_close(struct net_device *dev)
{
struct net_device *net_dev = (struct net_device *)dev;
struct rt_rtmp_adapter *pAd = NULL;
BOOLEAN Cancelled;
u32 i = 0;
#ifdef RTMP_MAC_USB
DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup);
DECLARE_WAITQUEUE(wait, current);
#endif /* RTMP_MAC_USB // */
GET_PAD_FROM_NET_DEV(pAd, net_dev);
DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
Cancelled = FALSE;
/* Sanity check for pAd */
if (pAd == NULL)
return 0; /* close ok */
{
#ifdef RTMP_MAC_PCI
RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE);
#endif /* RTMP_MAC_PCI // */
/* If dirver doesn't wake up firmware here, */
/* NICLoadFirmware will hang forever when interface is up again. */
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) {
AsicForceWakeup(pAd, TRUE);
}
#ifdef RTMP_MAC_USB
RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
#endif /* RTMP_MAC_USB // */
MlmeRadioOff(pAd);
#ifdef RTMP_MAC_PCI
pAd->bPCIclkOff = FALSE;
#endif /* RTMP_MAC_PCI // */
}
RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
for (i = 0; i < NUM_OF_TX_RING; i++) {
while (pAd->DeQueueRunning[i] == TRUE) {
DBGPRINT(RT_DEBUG_TRACE,
("Waiting for TxQueue[%d] done..........\n",
i));
RTMPusecDelay(1000);
}
}
#ifdef RTMP_MAC_USB
/* ensure there are no more active urbs. */
add_wait_queue(&unlink_wakeup, &wait);
pAd->wait = &unlink_wakeup;
/* maybe wait for deletions to finish. */
i = 0;
/*while((i < 25) && atomic_read(&pAd->PendingRx) > 0) */
while (i < 25) {
unsigned long IrqFlags;
RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
if (pAd->PendingRx == 0) {
RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
break;
}
RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
msleep(UNLINK_TIMEOUT_MS); /*Time in millisecond */
i++;
}
pAd->wait = NULL;
remove_wait_queue(&unlink_wakeup, &wait);
#endif /* RTMP_MAC_USB // */
/* Stop Mlme state machine */
MlmeHalt(pAd);
//.........这里部分代码省略.........
示例7: hsi_proto_read
int hsi_proto_read(int ch, u32 *buffer, int count)
{
DECLARE_WAITQUEUE(wait, current);
u32 *data;
unsigned int data_len = 0;
struct protocol_queue *entry;
int ret, recv_data = 0;
/*if (count > MAX_HSI_IPC_BUFFER)
count = MAX_HSI_IPC_BUFFER;
data = kmalloc(count, GFP_ATOMIC);*/
ret = if_hsi_read(ch, buffer, count);
if (ret < 0) {
pr_err("Can not submit read. READ Error\n");
goto out2;
}
spin_lock_bh(&hsi_protocol_data[ch].lock);
add_wait_queue(&hsi_protocol_data[ch].rx_wait, &wait);
spin_unlock_bh(&hsi_protocol_data[ch].lock);
for (;;) {
data = NULL;
data_len = 0;
set_current_state(TASK_INTERRUPTIBLE);
spin_lock_bh(&hsi_protocol_data[ch].lock);
if (!list_empty(&hsi_protocol_data[ch].rx_queue)) {
entry = list_entry(hsi_protocol_data[ch].rx_queue.next,
struct protocol_queue, list);
data = entry->data;
data_len = entry->count;
list_del(&entry->list);
kfree(entry);
}
spin_unlock_bh(&hsi_protocol_data[ch].lock);
pr_debug("%s, data = 0x%p, data_len = %d\n",
__func__, data, data_len);
if (data_len) {
pr_debug("%s, RX finished, ch-> %d, length = %d\n",
__func__, ch, count);
spin_lock_bh(&hsi_protocol_data[ch].lock);
hsi_protocol_data[ch].poll_event &=
~(POLLIN | POLLRDNORM);
spin_unlock_bh(&hsi_protocol_data[ch].lock);
if_hsi_poll(ch);
#if 0
memcpy(buffer, data, count);
#endif
recv_data += data_len;
#if 0
buffer += data_len;
if ((recv_data == count) || (recv_data >= MAX_HSI_IPC_BUFFER))
#endif
break;
} else if (signal_pending(current)) {
pr_debug("%s, ERESTARTSYS\n", __func__);
recv_data = -EAGAIN;
if_hsi_cancel_read(ch);
/* goto out; */
break;
}
/*printk(KERN_DEBUG "%s, going to sleep...\n", __func__); */
schedule();
/*printk(KERN_DEBUG "%s, woke up\n", __func__); */
}
示例8: MlmeHalt
/*
========================================================================
Routine Description:
Close raxx interface.
Arguments:
*net_dev the raxx interface pointer
Return Value:
0 Open OK
otherwise Open Fail
Note:
1. if open fail, kernel will not call the close function.
2. Free memory for
(1) Mlme Memory Handler: MlmeHalt()
(2) TX & RX: RTMPFreeTxRxRingMemory()
(3) BA Reordering: ba_reordering_resource_release()
========================================================================
*/
int rt28xx_close(IN PNET_DEV dev)
{
struct net_device * net_dev = (struct net_device *)dev;
RTMP_ADAPTER *pAd = RTMP_OS_NETDEV_GET_PRIV(net_dev);
BOOLEAN Cancelled;
UINT32 i = 0;
#ifdef RTMP_MAC_USB
DECLARE_WAIT_QUEUE_HEAD(unlink_wakeup);
DECLARE_WAITQUEUE(wait, current);
//RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
#endif // RTMP_MAC_USB //
DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n"));
Cancelled = FALSE;
// Sanity check for pAd
if (pAd == NULL)
return 0; // close ok
#ifdef WDS_SUPPORT
WdsDown(pAd);
#endif // WDS_SUPPORT //
#ifdef CONFIG_STA_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
// If dirver doesn't wake up firmware here,
// NICLoadFirmware will hang forever when interface is up again.
if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
{
AsicForceWakeup(pAd, TRUE);
}
#ifdef RTMP_MAC_USB
RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
#endif // RTMP_MAC_USB //
MlmeRadioOff(pAd);
}
#endif // CONFIG_STA_SUPPORT //
RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
for (i = 0 ; i < NUM_OF_TX_RING; i++)
{
while (pAd->DeQueueRunning[i] == TRUE)
{
DBGPRINT(RT_DEBUG_TRACE, ("Waiting for TxQueue[%d] done..........\n", i));
RTMPusecDelay(1000);
}
}
#ifdef RTMP_MAC_USB
// ensure there are no more active urbs.
add_wait_queue (&unlink_wakeup, &wait);
pAd->wait = &unlink_wakeup;
// maybe wait for deletions to finish.
i = 0;
//while((i < 25) && atomic_read(&pAd->PendingRx) > 0)
while(i < 25)
{
unsigned long IrqFlags;
RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags);
if (pAd->PendingRx == 0)
{
RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
break;
}
RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags);
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
msleep(UNLINK_TIMEOUT_MS); //Time in millisecond
#else
//.........这里部分代码省略.........
示例9: kafscmd
/*
* AFS Cache Manager kernel thread
*/
static int kafscmd(void *arg)
{
DECLARE_WAITQUEUE(myself, current);
struct rxrpc_call *call;
_SRXAFSCM_xxxx_t func;
int die;
printk("kAFS: Started kafscmd %d\n", current->pid);
daemonize("kafscmd");
complete(&kafscmd_alive);
/* loop around looking for things to attend to */
do {
if (list_empty(&kafscmd_attention_list)) {
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&kafscmd_sleepq, &myself);
for (;;) {
set_current_state(TASK_INTERRUPTIBLE);
if (!list_empty(&kafscmd_attention_list) ||
signal_pending(current) ||
kafscmd_die)
break;
schedule();
}
remove_wait_queue(&kafscmd_sleepq, &myself);
set_current_state(TASK_RUNNING);
}
die = kafscmd_die;
/* dequeue the next call requiring attention */
call = NULL;
spin_lock(&kafscmd_attention_lock);
if (!list_empty(&kafscmd_attention_list)) {
call = list_entry(kafscmd_attention_list.next,
struct rxrpc_call,
app_attn_link);
list_del_init(&call->app_attn_link);
die = 0;
}
spin_unlock(&kafscmd_attention_lock);
if (call) {
/* act upon it */
_debug("@@@ Begin Attend Call %p", call);
func = call->app_user;
if (func)
func(call);
rxrpc_put_call(call);
_debug("@@@ End Attend Call %p", call);
}
} while(!die);
示例10: gs_block_til_ready
int gs_block_til_ready(void *port_, struct file * filp)
{
struct gs_port *gp = port_;
struct tty_port *port = &gp->port;
DECLARE_WAITQUEUE(wait, current);
int retval;
int do_clocal = 0;
int CD;
struct tty_struct *tty;
unsigned long flags;
func_enter ();
if (!port) return 0;
tty = port->tty;
gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n");
/*
* If the device is in the middle of being closed, then block
* until it's done, and then try again.
*/
if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
interruptible_sleep_on(&port->close_wait);
if (port->flags & ASYNC_HUP_NOTIFY)
return -EAGAIN;
else
return -ERESTARTSYS;
}
gs_dprintk (GS_DEBUG_BTR, "after hung up\n");
/*
* If non-blocking mode is set, or the port is not enabled,
* then make the check up front and then exit.
*/
if ((filp->f_flags & O_NONBLOCK) ||
(tty->flags & (1 << TTY_IO_ERROR))) {
port->flags |= ASYNC_NORMAL_ACTIVE;
return 0;
}
gs_dprintk (GS_DEBUG_BTR, "after nonblock\n");
if (C_CLOCAL(tty))
do_clocal = 1;
/*
* Block waiting for the carrier detect and the line to become
* free (i.e., not in use by the callout). While we are in
* this loop, port->count is dropped by one, so that
* rs_close() knows when to free things. We restore it upon
* exit, either normal or abnormal.
*/
retval = 0;
add_wait_queue(&port->open_wait, &wait);
gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n");
spin_lock_irqsave(&port->lock, flags);
if (!tty_hung_up_p(filp)) {
port->count--;
}
port->blocked_open++;
spin_unlock_irqrestore(&port->lock, flags);
while (1) {
CD = tty_port_carrier_raised(port);
gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD);
set_current_state (TASK_INTERRUPTIBLE);
if (tty_hung_up_p(filp) ||
!(port->flags & ASYNC_INITIALIZED)) {
if (port->flags & ASYNC_HUP_NOTIFY)
retval = -EAGAIN;
else
retval = -ERESTARTSYS;
break;
}
if (!(port->flags & ASYNC_CLOSING) &&
(do_clocal || CD))
break;
gs_dprintk (GS_DEBUG_BTR, "signal_pending is now: %d (%lx)\n",
(int)signal_pending (current), *(long*)(¤t->blocked));
if (signal_pending(current)) {
retval = -ERESTARTSYS;
break;
}
schedule();
}
gs_dprintk (GS_DEBUG_BTR, "Got out of the loop. (%d)\n",
port->blocked_open);
set_current_state (TASK_RUNNING);
remove_wait_queue(&port->open_wait, &wait);
spin_lock_irqsave(&port->lock, flags);
if (!tty_hung_up_p(filp)) {
port->count++;
}
port->blocked_open--;
if (retval == 0)
port->flags |= ASYNC_NORMAL_ACTIVE;
//.........这里部分代码省略.........
示例11: afs_vnode_fetch_status
/*
* fetch file status from the volume
* - don't issue a fetch if:
* - the changed bit is not set and there's a valid callback
* - there are any outstanding ops that will fetch the status
* - TODO implement local caching
*/
int afs_vnode_fetch_status(struct afs_vnode *vnode,
struct afs_vnode *auth_vnode, struct key *key)
{
struct afs_server *server;
unsigned long acl_order;
int ret;
DECLARE_WAITQUEUE(myself, current);
_enter("%s,{%x:%u.%u}",
vnode->volume->vlocation->vldb.name,
vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
vnode->cb_promised) {
_leave(" [unchanged]");
return 0;
}
if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
_leave(" [deleted]");
return -ENOENT;
}
acl_order = 0;
if (auth_vnode)
acl_order = auth_vnode->acl_order;
spin_lock(&vnode->lock);
if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags) &&
vnode->cb_promised) {
spin_unlock(&vnode->lock);
_leave(" [unchanged]");
return 0;
}
ASSERTCMP(vnode->update_cnt, >=, 0);
if (vnode->update_cnt > 0) {
/* someone else started a fetch */
_debug("wait on fetch %d", vnode->update_cnt);
set_current_state(TASK_UNINTERRUPTIBLE);
ASSERT(myself.func != NULL);
add_wait_queue(&vnode->update_waitq, &myself);
/* wait for the status to be updated */
for (;;) {
if (!test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
break;
if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
break;
/* check to see if it got updated and invalidated all
* before we saw it */
if (vnode->update_cnt == 0) {
remove_wait_queue(&vnode->update_waitq,
&myself);
set_current_state(TASK_RUNNING);
goto get_anyway;
}
spin_unlock(&vnode->lock);
schedule();
set_current_state(TASK_UNINTERRUPTIBLE);
spin_lock(&vnode->lock);
}
remove_wait_queue(&vnode->update_waitq, &myself);
spin_unlock(&vnode->lock);
set_current_state(TASK_RUNNING);
return test_bit(AFS_VNODE_DELETED, &vnode->flags) ?
-ENOENT : 0;
}
get_anyway:
/* okay... we're going to have to initiate the op */
vnode->update_cnt++;
spin_unlock(&vnode->lock);
/* merge AFS status fetches and clear outstanding callback on this
* vnode */
do {
/* pick a server to query */
server = afs_volume_pick_fileserver(vnode);
if (IS_ERR(server))
goto no_server;
//.........这里部分代码省略.........
示例12: n_hdlc_tty_write
/* n_hdlc_tty_write()
*
* write a single frame of data to device
*
* Arguments: tty pointer to associated tty device instance data
* file pointer to file object data
* data pointer to transmit data (one frame)
* count size of transmit frame in bytes
*
* Return Value: number of bytes written (or error code)
*/
static rw_ret_t n_hdlc_tty_write (struct tty_struct *tty, struct file *file,
const __u8 * data, rw_count_t count)
{
struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
int error = 0;
DECLARE_WAITQUEUE(wait, current);
N_HDLC_BUF *tbuf;
if (debuglevel >= DEBUG_LEVEL_INFO)
printk("%s(%d)n_hdlc_tty_write() called count=%d\n",
__FILE__,__LINE__,count);
/* Verify pointers */
if (!n_hdlc)
return -EIO;
if (n_hdlc->magic != HDLC_MAGIC)
return -EIO;
/* verify frame size */
if (count > maxframe ) {
if (debuglevel & DEBUG_LEVEL_INFO)
printk (KERN_WARNING
"n_hdlc_tty_write: truncating user packet "
"from %lu to %d\n", (unsigned long) count,
maxframe );
count = maxframe;
}
add_wait_queue(&n_hdlc->write_wait, &wait);
set_current_state(TASK_INTERRUPTIBLE);
/* Allocate transmit buffer */
/* sleep until transmit buffer available */
while (!(tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list))) {
schedule();
n_hdlc = tty2n_hdlc (tty);
if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC ||
tty != n_hdlc->tty) {
printk("n_hdlc_tty_write: %p invalid after wait!\n", n_hdlc);
error = -EIO;
break;
}
if (signal_pending(current)) {
error = -EINTR;
break;
}
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&n_hdlc->write_wait, &wait);
if (!error) {
/* Retrieve the user's buffer */
COPY_FROM_USER (error, tbuf->buf, data, count);
if (error) {
/* return tx buffer to free list */
n_hdlc_buf_put(&n_hdlc->tx_free_buf_list,tbuf);
} else {
/* Send the data */
tbuf->count = error = count;
n_hdlc_buf_put(&n_hdlc->tx_buf_list,tbuf);
n_hdlc_send_frames(n_hdlc,tty);
}
}
return error;
} /* end of n_hdlc_tty_write() */
示例13: ad1889_update_ptr
static void ad1889_update_ptr(ad1889_dev_t *dev, int wake)
{
ad1889_state_t *state;
struct dmabuf *dmabuf;
unsigned long hwptr;
int diff;
/* check ADC first */
state = &dev->adc_state;
dmabuf = &state->dmabuf;
if (dmabuf->enable & ADC_RUNNING) {
hwptr = ad1889_get_dma_addr(state);
diff = (dmabuf->dmasize + hwptr - dmabuf->hwptr) % dmabuf->dmasize;
dmabuf->hwptr = hwptr;
dmabuf->total_bytes += diff;
dmabuf->count += diff;
if (dmabuf->count > dmabuf->dmasize)
dmabuf->count = dmabuf->dmasize;
if (dmabuf->mapped) {
if (wake & dmabuf->count >= dmabuf->fragsize)
wake_up(&dmabuf->wait);
} else {
if (wake & dmabuf->count > 0)
wake_up(&dmabuf->wait);
}
}
/* check DAC */
state = &dev->wav_state;
dmabuf = &state->dmabuf;
if (dmabuf->enable & DAC_RUNNING) {
XXX
}
#endif
/************************* /dev/dsp interfaces ************************* */
static ssize_t ad1889_read(struct file *file, char __user *buffer, size_t count,
loff_t *ppos)
{
return 0;
}
static ssize_t ad1889_write(struct file *file, const char __user *buffer, size_t count,
loff_t *ppos)
{
ad1889_dev_t *dev = (ad1889_dev_t *)file->private_data;
ad1889_state_t *state = &dev->state[AD_WAV_STATE];
volatile struct dmabuf *dmabuf = &state->dmabuf;
ssize_t ret = 0;
DECLARE_WAITQUEUE(wait, current);
mutex_lock(&state->mutex);
#if 0
if (dmabuf->mapped) {
ret = -ENXIO;
goto err1;
}
#endif
if (!access_ok(VERIFY_READ, buffer, count)) {
ret = -EFAULT;
goto err1;
}
add_wait_queue(&state->dmabuf.wait, &wait);
/* start filling dma buffer.... */
while (count > 0) {
long rem;
long cnt = count;
unsigned long flags;
for (;;) {
long used_bytes;
long timeout; /* max time for DMA in jiffies */
/* buffer is full if wr catches up to rd */
spin_lock_irqsave(&state->card->lock, flags);
used_bytes = dmabuf->wr_ptr - dmabuf->rd_ptr;
timeout = (dmabuf->dma_len * HZ) / dmabuf->rate;
spin_unlock_irqrestore(&state->card->lock, flags);
/* adjust for buffer wrap around */
used_bytes = (used_bytes + DMA_SIZE) & (DMA_SIZE - 1);
/* If at least one page unused */
if (used_bytes < (DMA_SIZE - 0x1000))
break;
/* dma buffer full */
if (file->f_flags & O_NONBLOCK) {
ret = -EAGAIN;
goto err2;
}
set_current_state(TASK_INTERRUPTIBLE);
//.........这里部分代码省略.........
示例14: netlink_unicast
int netlink_unicast(struct sock *ssk, struct sk_buff *skb, u32 pid, int nonblock)
{
struct sock *sk;
int len = skb->len;
int protocol = ssk->protocol;
long timeo;
DECLARE_WAITQUEUE(wait, current);
timeo = sock_sndtimeo(ssk, nonblock);
retry:
sk = netlink_lookup(protocol, pid);
if (sk == NULL)
goto no_dst;
/* Don't bother queuing skb if kernel socket has no input function */
if (sk->protinfo.af_netlink->pid == 0 &&
!sk->protinfo.af_netlink->data_ready)
goto no_dst;
#ifdef NL_EMULATE_DEV
if (sk->protinfo.af_netlink->handler) {
skb_orphan(skb);
len = sk->protinfo.af_netlink->handler(protocol, skb);
sock_put(sk);
return len;
}
#endif
if (atomic_read(&sk->rmem_alloc) > sk->rcvbuf ||
test_bit(0, &sk->protinfo.af_netlink->state)) {
if (!timeo) {
if (ssk->protinfo.af_netlink->pid == 0)
netlink_overrun(sk);
sock_put(sk);
kfree_skb(skb);
return -EAGAIN;
}
__set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&sk->protinfo.af_netlink->wait, &wait);
if ((atomic_read(&sk->rmem_alloc) > sk->rcvbuf ||
test_bit(0, &sk->protinfo.af_netlink->state)) &&
!sk->dead)
timeo = schedule_timeout(timeo);
__set_current_state(TASK_RUNNING);
remove_wait_queue(&sk->protinfo.af_netlink->wait, &wait);
sock_put(sk);
if (signal_pending(current)) {
kfree_skb(skb);
return sock_intr_errno(timeo);
}
goto retry;
}
skb_orphan(skb);
skb_set_owner_r(skb, sk);
skb_queue_tail(&sk->receive_queue, skb);
sk->data_ready(sk, len);
sock_put(sk);
return len;
no_dst:
kfree_skb(skb);
return -ECONNREFUSED;
}
示例15: usb_rtusb_close_device
static int usb_rtusb_close_device(
IN PRTMP_ADAPTER pAd)
{
int i = 0;
int ret;
DECLARE_WAIT_QUEUE_HEAD (unlink_wakeup);
DECLARE_WAITQUEUE (wait, current);
DBGPRINT(RT_DEBUG_TRACE, "-->usb_rtusb_close_device \n");
// ensure there are no more active urbs.
add_wait_queue (&unlink_wakeup, &wait);
pAd->wait = &unlink_wakeup;
// maybe wait for deletions to finish.
while ((i < 25) && atomic_read(&pAd->PendingRx) > 0)
{
#if LINUX_VERSION_CODE >KERNEL_VERSION(2,6,9)
msleep(UNLINK_TIMEOUT_MS);
#endif
i++;
}
pAd->wait = NULL;
remove_wait_queue (&unlink_wakeup, &wait);
if (pAd->MLMEThr_pid >= 0)
{
mlme_kill = 1;
RTUSBMlmeUp(pAd);
wmb(); // need to check
ret = KILL_THREAD_PID (pAd->MLMEThr_pid, SIGTERM, 1);
if (ret)
{
printk (KERN_WARNING "%s: unable to Mlme thread \n", pAd->net_dev->name);
}
wait_for_completion (&pAd->MlmeThreadNotify);
// reset mlme thread
pAd->MLMEThr_pid = THREAD_PID_INIT_VALUE;
}
if (pAd->RTUSBCmdThr_pid>= 0)
{
RTUSBCmd_kill = 1;
RTUSBCMDUp(pAd);
wmb(); // need to check
ret = KILL_THREAD_PID (pAd->RTUSBCmdThr_pid, SIGTERM, 1);
if (ret)
{
printk (KERN_WARNING "%s: unable to RTUSBCmd thread \n", pAd->net_dev->name);
}
wait_for_completion (&pAd->CmdThreadNotify);
// reset cmd thread
pAd->RTUSBCmdThr_pid= THREAD_PID_INIT_VALUE;
}
RTUSBHalt(pAd, TRUE);
RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS);
tasklet_kill(&pAd->rx_bh);
DBGPRINT(RT_DEBUG_TRACE,"<--usb_rtusb_close_device \n");
return 0;
}