本文整理汇总了C++中schedule函数的典型用法代码示例。如果您正苦于以下问题:C++ schedule函数的具体用法?C++ schedule怎么用?C++ schedule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了schedule函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: setScope
bool MultiTower::init()
{
if (!Sprite::init()) //如果忘记了这句话则会在runApplication报错
{
return false;
}
instance = GameManager::getInstance();
setScope(300);
setAttack(1);
setRate(5);//2.5秒钟开火一次
setTowerType(4);
setIsSelected(false);
setGrade(0);//开始没有等级
setPower(40);//塔消耗电力
setMove(false);//开始不处于移动状态
setIsPowerEnough(true);//开始状态电力足够
setIsPowerConsumption(true);//该塔耗电
towerSprite = Sprite::create("towerItem/Item5.png");
towerSprite->setScale(1);
addChild(towerSprite, 5);
gradeSprite = Sprite::create("level1.png");
gradeSprite->setAnchorPoint(Point(0, 0));
gradeSprite->setPosition(this->getPosition().x + 10, -towerSprite->getBoundingBox().size.height / 2);
gradeSprite->setOpacity(0);//开始让其不可见
addChild(gradeSprite, 6);
noPowerSprite = Sprite::create("noPower.png");
noPowerSprite->setAnchorPoint(Point(0.5, 0));
noPowerSprite->setScale(1);
noPowerSprite->setPosition(towerSprite->getBoundingBox().size.width / 2 - 50, towerSprite->getBoundingBox().size.height - 30);
noPowerSprite->setVisible(false);
addChild(noPowerSprite, 7);
//沉默图片
noAttackSprite = Sprite::create("noSpeak.png");
noAttackSprite->setScale(0.7);
noAttackSprite->setAnchorPoint(Point(0.5, 0));
noAttackSprite->setPosition(towerSprite->getBoundingBox().size.width / 2 - 58, towerSprite->getBoundingBox().size.height - 60);
addChild(noAttackSprite, 8);
noAttackSprite->setVisible(false);
//血量条背景图片
towerHpSprite = Sprite::create("manaBarBg.png");
towerHpSprite->setPosition(noPowerSprite->getPosition()-Point(10,20));
towerHpSprite->setScale(0.6);
addChild(towerHpSprite, 10);
//炮塔血量
hp = 4;
//炮塔血量进度条
towerHp = ProgressTimer::create(Sprite::create("soldierProduceTimeBar.png")); //参数是一个图片sprite
towerHp->setScaleX(2);
towerHp->setScaleY(5.2);
towerHp->setType(ProgressTimer::Type::BAR);
towerHp->setMidpoint(Point(0, 0.5f));
towerHp->setBarChangeRate(Point(1, 0));
towerHp->setPercentage(100);
towerHp->setPosition(Point(towerHpSprite->getContentSize().width / 2, towerHpSprite->getContentSize().height / 3 * 2 - 10));
towerHpSprite->addChild(towerHp, 5);
//初始化不可见
towerHp->setVisible(false);
towerHpSprite->setVisible(false);
schedule(schedule_selector(MultiTower::checkNearestEnemy, this), 0.2);
schedule(schedule_selector(MultiTower::shoot,this), rate);
addTouch();//添加触摸事件
return true;
}
开发者ID:houzisbw,项目名称:Cocos2dx_TowerDefense_Version2,代码行数:74,代码来源:MultiTower.cpp
示例2: schedule_exists
void schedule_exists (Ob ob) { schedule(ExistsTask(ob)); }
开发者ID:imclab,项目名称:pomagma,代码行数:1,代码来源:theory.hpp
示例3: schedule_nless
void schedule_nless (Ob lhs, Ob rhs) { schedule(NegativeOrderTask(lhs, rhs)); }
开发者ID:imclab,项目名称:pomagma,代码行数:1,代码来源:theory.hpp
示例4: amvdec_loadmc
static s32 amvdec_loadmc(const u32 *p)
{
ulong timeout;
s32 ret = 0;
#ifdef AMVDEC_USE_STATIC_MEMORY
if (mc_addr == NULL) {
#else
{
#endif
mc_addr = kmalloc(MC_SIZE, GFP_KERNEL);
}
if (!mc_addr)
return -ENOMEM;
memcpy(mc_addr, p, MC_SIZE);
mc_addr_map = dma_map_single(amports_get_dma_device(),
mc_addr, MC_SIZE, DMA_TO_DEVICE);
WRITE_VREG(MPSR, 0);
WRITE_VREG(CPSR, 0);
/* Read CBUS register for timing */
timeout = READ_VREG(MPSR);
timeout = READ_VREG(MPSR);
timeout = jiffies + HZ;
WRITE_VREG(IMEM_DMA_ADR, mc_addr_map);
WRITE_VREG(IMEM_DMA_COUNT, 0x1000);
WRITE_VREG(IMEM_DMA_CTRL, (0x8000 | (7 << 16)));
while (READ_VREG(IMEM_DMA_CTRL) & 0x8000) {
if (time_before(jiffies, timeout))
schedule();
else {
pr_err("vdec load mc error\n");
ret = -EBUSY;
break;
}
}
dma_unmap_single(amports_get_dma_device(),
mc_addr_map, MC_SIZE, DMA_TO_DEVICE);
#ifndef AMVDEC_USE_STATIC_MEMORY
kfree(mc_addr);
mc_addr = NULL;
#endif
return ret;
}
s32 amvdec_loadmc_ex(enum vformat_e type, const char *name, char *def)
{
return am_loadmc_ex(type, name, def, &amvdec_loadmc);
}
static s32 amvdec2_loadmc(const u32 *p)
{
if (has_vdec2()) {
ulong timeout;
s32 ret = 0;
#ifdef AMVDEC_USE_STATIC_MEMORY
if (mc_addr == NULL) {
#else
{
#endif
mc_addr = kmalloc(MC_SIZE, GFP_KERNEL);
}
if (!mc_addr)
return -ENOMEM;
memcpy(mc_addr, p, MC_SIZE);
mc_addr_map = dma_map_single(amports_get_dma_device(),
mc_addr, MC_SIZE, DMA_TO_DEVICE);
WRITE_VREG(VDEC2_MPSR, 0);
WRITE_VREG(VDEC2_CPSR, 0);
/* Read CBUS register for timing */
timeout = READ_VREG(VDEC2_MPSR);
timeout = READ_VREG(VDEC2_MPSR);
timeout = jiffies + HZ;
WRITE_VREG(VDEC2_IMEM_DMA_ADR, mc_addr_map);
WRITE_VREG(VDEC2_IMEM_DMA_COUNT, 0x1000);
WRITE_VREG(VDEC2_IMEM_DMA_CTRL, (0x8000 | (7 << 16)));
while (READ_VREG(VDEC2_IMEM_DMA_CTRL) & 0x8000) {
if (time_before(jiffies, timeout))
schedule();
else {
pr_err("vdec2 load mc error\n");
//.........这里部分代码省略.........
开发者ID:gcsuri,项目名称:linux-wetek-3.14.y,代码行数:101,代码来源:amvdec.c
示例5: __mutex_lock_common
/*
* Lock a mutex (possibly interruptible), slowpath:
*/
static inline int
__mutex_lock_common(struct mutex *lock, long state)
{
struct task_struct *task = current;
struct mutex_waiter waiter;
unsigned int old_val;
unsigned long flags;
spin_lock_mutex(&lock->wait_lock, flags);
/* add waiting tasks to the end of the waitqueue (FIFO): */
list_add_tail(&waiter.list, &lock->wait_list);
waiter.task = task;
old_val = atomic_xchg(&lock->count, -1);
if (old_val == 1)
goto done;
for (;;) {
/*
* Lets try to take the lock again - this is needed even if
* we get here for the first time (shortly after failing to
* acquire the lock), to make sure that we get a wakeup once
* it's unlocked. Later on, if we sleep, this is the
* operation that gives us the lock. We xchg it to -1, so
* that when we release the lock, we properly wake up the
* other waiters:
*/
old_val = atomic_xchg(&lock->count, -1);
if (old_val == 1)
break;
/*
* got a signal? (This code gets eliminated in the
* TASK_UNINTERRUPTIBLE case.)
*/
#if 0
if (unlikely((state == TASK_INTERRUPTIBLE &&
signal_pending(task)) ||
(state == TASK_KILLABLE &&
fatal_signal_pending(task)))) {
mutex_remove_waiter(lock, &waiter,
task_thread_info(task));
spin_unlock_mutex(&lock->wait_lock, flags);
return -EINTR;
}
#endif
set_task_state(task, state);
/* didnt get the lock, go to sleep: */
spin_unlock_mutex(&lock->wait_lock, flags);
schedule();
spin_lock_mutex(&lock->wait_lock, flags);
}
done:
/* got the lock - rejoice! */
mutex_remove_waiter(lock, &waiter, task_thread_info(task));
/* set it to 0 if there are no waiters left: */
if (likely(list_empty(&lock->wait_list)))
atomic_set(&lock->count, 0);
spin_unlock_mutex(&lock->wait_lock, flags);
return 0;
}
开发者ID:HobbesOSR,项目名称:kitten,代码行数:72,代码来源:mutex.c
示例6: fscache_wait_bit_interruptible
/*
* wait_on_bit() sleep function for interruptible waiting
*/
int fscache_wait_bit_interruptible(void *flags)
{
schedule();
return signal_pending(current);
}
开发者ID:rrowicki,项目名称:Chrono_Kernel-1,代码行数:8,代码来源:main.c
示例7: ocfbench_init
int
ocfbench_init(void)
{
int i;
unsigned long mbps;
unsigned long flags;
printk("Crypto Speed tests\n");
requests = kmalloc(sizeof(request_t) * request_q_len, GFP_KERNEL);
if (!requests) {
printk("malloc failed\n");
return -EINVAL;
}
for (i = 0; i < request_q_len; i++) {
/* +64 for return data */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
INIT_WORK(&requests[i].work, ocf_request_wq);
#else
INIT_WORK(&requests[i].work, ocf_request, &requests[i]);
#endif
requests[i].buffer = kmalloc(request_size + 128, GFP_DMA);
if (!requests[i].buffer) {
printk("malloc failed\n");
return -EINVAL;
}
memset(requests[i].buffer, '0' + i, request_size + 128);
}
/*
* OCF benchmark
*/
printk("OCF: testing ...\n");
if (ocf_init() == -1)
return -EINVAL;
spin_lock_init(&ocfbench_counter_lock);
total = outstanding = 0;
jstart = jiffies;
for (i = 0; i < request_q_len; i++) {
spin_lock_irqsave(&ocfbench_counter_lock, flags);
outstanding++;
spin_unlock_irqrestore(&ocfbench_counter_lock, flags);
ocf_request(&requests[i]);
}
while (outstanding > 0)
schedule();
jstop = jiffies;
mbps = 0;
if (jstop > jstart) {
mbps = (unsigned long) total * (unsigned long) request_size * 8;
mbps /= ((jstop - jstart) * 1000) / HZ;
}
printk("OCF: %d requests of %d bytes in %d jiffies (%d.%03d Mbps)\n",
total, request_size, (int)(jstop - jstart),
((int)mbps) / 1000, ((int)mbps) % 1000);
ocf_done();
#ifdef BENCH_IXP_ACCESS_LIB
/*
* IXP benchmark
*/
printk("IXP: testing ...\n");
ixp_init();
total = outstanding = 0;
jstart = jiffies;
for (i = 0; i < request_q_len; i++) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
INIT_WORK(&requests[i].work, ixp_request_wq);
#else
INIT_WORK(&requests[i].work, ixp_request, &requests[i]);
#endif
spin_lock_irqsave(&ocfbench_counter_lock, flags);
outstanding++;
spin_unlock_irqrestore(&ocfbench_counter_lock, flags);
ixp_request(&requests[i]);
}
while (outstanding > 0)
schedule();
jstop = jiffies;
mbps = 0;
if (jstop > jstart) {
mbps = (unsigned long) total * (unsigned long) request_size * 8;
mbps /= ((jstop - jstart) * 1000) / HZ;
}
printk("IXP: %d requests of %d bytes in %d jiffies (%d.%03d Mbps)\n",
total, request_size, jstop - jstart,
((int)mbps) / 1000, ((int)mbps) % 1000);
ixp_done();
#endif /* BENCH_IXP_ACCESS_LIB */
for (i = 0; i < request_q_len; i++)
kfree(requests[i].buffer);
kfree(requests);
return -EINVAL; /* always fail to load so it can be re-run quickly ;-) */
}
开发者ID:020gzh,项目名称:openwrt-mirror,代码行数:99,代码来源:ocf-bench.c
示例8: pp_write
static ssize_t pp_write (struct file * file, const char * buf, size_t count,
loff_t * ppos)
{
unsigned int minor = MINOR (file->f_dentry->d_inode->i_rdev);
struct pp_struct *pp = file->private_data;
char * kbuffer;
ssize_t bytes_written = 0;
ssize_t wrote;
int mode;
struct parport *pport;
if (!(pp->flags & PP_CLAIMED)) {
/* Don't have the port claimed */
printk (KERN_DEBUG CHRDEV "%x: claim the port first\n",
minor);
return -EINVAL;
}
kbuffer = kmalloc(min_t(size_t, count, PP_BUFFER_SIZE), GFP_KERNEL);
if (!kbuffer) {
return -ENOMEM;
}
pport = pp->pdev->port;
mode = pport->ieee1284.mode & ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
parport_set_timeout (pp->pdev,
(file->f_flags & O_NONBLOCK) ?
PARPORT_INACTIVITY_O_NONBLOCK :
pp->default_inactivity);
while (bytes_written < count) {
ssize_t n = min_t(unsigned long, count - bytes_written, PP_BUFFER_SIZE);
if (copy_from_user (kbuffer, buf + bytes_written, n)) {
bytes_written = -EFAULT;
break;
}
if ((pp->flags & PP_FASTWRITE) && (mode == IEEE1284_MODE_EPP)) {
/* do a fast EPP write */
if (pport->ieee1284.mode & IEEE1284_ADDR) {
wrote = pport->ops->epp_write_addr (pport,
kbuffer, n, PARPORT_EPP_FAST);
} else {
wrote = pport->ops->epp_write_data (pport,
kbuffer, n, PARPORT_EPP_FAST);
}
} else {
wrote = parport_write (pp->pdev->port, kbuffer, n);
}
if (wrote <= 0) {
if (!bytes_written) {
bytes_written = wrote;
}
break;
}
bytes_written += wrote;
if (file->f_flags & O_NONBLOCK) {
if (!bytes_written)
bytes_written = -EAGAIN;
break;
}
if (signal_pending (current)) {
if (!bytes_written) {
bytes_written = -EINTR;
}
break;
}
if (current->need_resched) {
schedule ();
}
}
parport_set_timeout (pp->pdev, pp->default_inactivity);
kfree (kbuffer);
pp_enable_irq (pp);
return bytes_written;
}
开发者ID:GunioRobot,项目名称:MI424WR_GEN2_Rev_E-F,代码行数:84,代码来源:ppdev.c
示例9: ac_write
static ssize_t ac_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
unsigned int NumCard; /* Board number 1 -> 8 */
unsigned int IndexCard; /* Index board number 0 -> 7 */
unsigned char TicCard; /* Board TIC to send */
unsigned long flags; /* Current priority */
struct st_ram_io st_loc;
struct mailbox tmpmailbox;
#ifdef DEBUG
int c;
#endif
DECLARE_WAITQUEUE(wait, current);
if (count != sizeof(struct st_ram_io) + sizeof(struct mailbox)) {
static int warncount = 5;
if (warncount) {
printk(KERN_INFO "Hmmm. write() of Applicom card, length %zd != expected %zd\n",
count, sizeof(struct st_ram_io) + sizeof(struct mailbox));
warncount--;
}
return -EINVAL;
}
if(copy_from_user(&st_loc, buf, sizeof(struct st_ram_io)))
return -EFAULT;
if(copy_from_user(&tmpmailbox, &buf[sizeof(struct st_ram_io)],
sizeof(struct mailbox)))
return -EFAULT;
NumCard = st_loc.num_card; /* board number to send */
TicCard = st_loc.tic_des_from_pc; /* tic number to send */
IndexCard = NumCard - 1;
if((NumCard < 1) || (NumCard > MAX_BOARD) || !apbs[IndexCard].RamIO)
return -EINVAL;
#ifdef DEBUG
printk("Write to applicom card #%d. struct st_ram_io follows:",
IndexCard+1);
for (c = 0; c < sizeof(struct st_ram_io);) {
printk("\n%5.5X: %2.2X", c, ((unsigned char *) &st_loc)[c]);
for (c++; c % 8 && c < sizeof(struct st_ram_io); c++) {
printk(" %2.2X", ((unsigned char *) &st_loc)[c]);
}
}
printk("\nstruct mailbox follows:");
for (c = 0; c < sizeof(struct mailbox);) {
printk("\n%5.5X: %2.2X", c, ((unsigned char *) &tmpmailbox)[c]);
for (c++; c % 8 && c < sizeof(struct mailbox); c++) {
printk(" %2.2X", ((unsigned char *) &tmpmailbox)[c]);
}
}
printk("\n");
#endif
spin_lock_irqsave(&apbs[IndexCard].mutex, flags);
/* Test octet ready correct */
if(readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY) > 2) {
Dummy = readb(apbs[IndexCard].RamIO + VERS);
spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags);
printk(KERN_WARNING "APPLICOM driver write error board %d, DataFromPcReady = %d\n",
IndexCard,(int)readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY));
DeviceErrorCount++;
return -EIO;
}
/* Place ourselves on the wait queue */
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&apbs[IndexCard].FlagSleepSend, &wait);
/* Check whether the card is ready for us */
while (readb(apbs[IndexCard].RamIO + DATA_FROM_PC_READY) != 0) {
Dummy = readb(apbs[IndexCard].RamIO + VERS);
/* It's busy. Sleep. */
spin_unlock_irqrestore(&apbs[IndexCard].mutex, flags);
schedule();
if (signal_pending(current)) {
remove_wait_queue(&apbs[IndexCard].FlagSleepSend,
&wait);
return -EINTR;
}
spin_lock_irqsave(&apbs[IndexCard].mutex, flags);
set_current_state(TASK_INTERRUPTIBLE);
}
/* We may not have actually slept */
set_current_state(TASK_RUNNING);
remove_wait_queue(&apbs[IndexCard].FlagSleepSend, &wait);
writeb(1, apbs[IndexCard].RamIO + DATA_FROM_PC_READY);
//.........这里部分代码省略.........
开发者ID:tch-opensrc,项目名称:TC72XX_LxG1.0.10mp5_OpenSrc,代码行数:101,代码来源:applicom.c
示例10: ltpc_probe
//.........这里部分代码省略.........
inb_p(io+1);
inb_p(io+3);
msleep(20);
inb_p(io+0);
inb_p(io+2);
inb_p(io+7); /* clear reset */
inb_p(io+4);
inb_p(io+5);
inb_p(io+5); /* enable dma */
inb_p(io+6); /* tri-state interrupt line */
ssleep(1);
/* now, figure out which dma channel we're using, unless it's
already been specified */
/* well, 0 is a legal DMA channel, but the LTPC card doesn't
use it... */
dma = ltpc_probe_dma(io, dma);
if (!dma) { /* no dma channel */
printk(KERN_ERR "No DMA channel found on ltpc card.\n");
err = -ENODEV;
goto out3;
}
/* print out friendly message */
if(irq)
printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, IR%d, DMA%d.\n",io,irq,dma);
else
printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, DMA%d. Using polled mode.\n",io,dma);
dev->netdev_ops = <pc_netdev;
dev->base_addr = io;
dev->irq = irq;
dev->dma = dma;
/* the card will want to send a result at this point */
/* (I think... leaving out this part makes the kernel crash,
so I put it back in...) */
f=claim_dma_lock();
disable_dma(dma);
clear_dma_ff(dma);
set_dma_mode(dma,DMA_MODE_READ);
set_dma_addr(dma,virt_to_bus(ltdmabuf));
set_dma_count(dma,0x100);
enable_dma(dma);
release_dma_lock(f);
(void) inb_p(io+3);
(void) inb_p(io+2);
timeout = jiffies+100*HZ/100;
while(time_before(jiffies, timeout)) {
if( 0xf9 == inb_p(io+6))
break;
schedule();
}
if(debug & DEBUG_VERBOSE) {
printk("setting up timer and irq\n");
}
/* grab it and don't let go :-) */
if (irq && request_irq( irq, ltpc_interrupt, 0, "ltpc", dev) >= 0)
{
(void) inb_p(io+7); /* enable interrupts from board */
(void) inb_p(io+7); /* and reset irq line */
} else {
if( irq )
printk(KERN_ERR "ltpc: IRQ already in use, using polled mode.\n");
dev->irq = 0;
/* polled mode -- 20 times per second */
/* this is really, really slow... should it poll more often? */
init_timer(<pc_timer);
ltpc_timer.function=ltpc_poll;
ltpc_timer.data = (unsigned long) dev;
ltpc_timer.expires = jiffies + HZ/20;
add_timer(<pc_timer);
}
err = register_netdev(dev);
if (err)
goto out4;
return NULL;
out4:
del_timer_sync(<pc_timer);
if (dev->irq)
free_irq(dev->irq, dev);
out3:
free_pages((unsigned long)ltdmabuf, get_order(1000));
out2:
release_region(io, 8);
out1:
free_netdev(dev);
out:
return ERR_PTR(err);
}
开发者ID:kozmikkick,项目名称:eternityprj-kernel-endeavoru-128,代码行数:101,代码来源:ltpc.c
示例11: pp_read
static ssize_t pp_read (struct file * file, char * buf, size_t count,
loff_t * ppos)
{
unsigned int minor = MINOR (file->f_dentry->d_inode->i_rdev);
struct pp_struct *pp = file->private_data;
char * kbuffer;
ssize_t bytes_read = 0;
struct parport *pport;
int mode;
if (!(pp->flags & PP_CLAIMED)) {
/* Don't have the port claimed */
printk (KERN_DEBUG CHRDEV "%x: claim the port first\n",
minor);
return -EINVAL;
}
/* Trivial case. */
if (count == 0)
return 0;
kbuffer = kmalloc(min_t(size_t, count, PP_BUFFER_SIZE), GFP_KERNEL);
if (!kbuffer) {
return -ENOMEM;
}
pport = pp->pdev->port;
mode = pport->ieee1284.mode & ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
parport_set_timeout (pp->pdev,
(file->f_flags & O_NONBLOCK) ?
PARPORT_INACTIVITY_O_NONBLOCK :
pp->default_inactivity);
while (bytes_read == 0) {
ssize_t need = min_t(unsigned long, count, PP_BUFFER_SIZE);
if (mode == IEEE1284_MODE_EPP) {
/* various specials for EPP mode */
int flags = 0;
size_t (*fn)(struct parport *, void *, size_t, int);
if (pp->flags & PP_W91284PIC) {
flags |= PARPORT_W91284PIC;
}
if (pp->flags & PP_FASTREAD) {
flags |= PARPORT_EPP_FAST;
}
if (pport->ieee1284.mode & IEEE1284_ADDR) {
fn = pport->ops->epp_read_addr;
} else {
fn = pport->ops->epp_read_data;
}
bytes_read = (*fn)(pport, kbuffer, need, flags);
} else {
bytes_read = parport_read (pport, kbuffer, need);
}
if (bytes_read != 0)
break;
if (file->f_flags & O_NONBLOCK) {
bytes_read = -EAGAIN;
break;
}
if (signal_pending (current)) {
bytes_read = -ERESTARTSYS;
break;
}
if (current->need_resched)
schedule ();
}
parport_set_timeout (pp->pdev, pp->default_inactivity);
if (bytes_read > 0 && copy_to_user (buf, kbuffer, bytes_read))
bytes_read = -EFAULT;
kfree (kbuffer);
pp_enable_irq (pp);
return bytes_read;
}
开发者ID:GunioRobot,项目名称:MI424WR_GEN2_Rev_E-F,代码行数:83,代码来源:ppdev.c
示例12: xbuf_wait
int xbuf_wait(void *word)
{
schedule();
return 0;
}
开发者ID:cpady,项目名称:ndas4linux,代码行数:5,代码来源:xixfs_xbuf.c
示例13: sys_msgrcv
asmlinkage long sys_msgrcv (int msqid, struct msgbuf *msgp, size_t msgsz,
long msgtyp, int msgflg)
{
struct msg_queue *msq;
struct msg_receiver msr_d;
struct list_head* tmp;
struct msg_msg* msg, *found_msg;
int err;
int mode;
if (msqid < 0 || (long) msgsz < 0)
return -EINVAL;
mode = convert_mode(&msgtyp,msgflg);
msq = msg_lock(msqid);
if(msq==NULL)
return -EINVAL;
retry:
err = -EIDRM;
if (msg_checkid(msq,msqid))
goto out_unlock;
err=-EACCES;
if (ipcperms (&msq->q_perm, S_IRUGO))
goto out_unlock;
tmp = msq->q_messages.next;
found_msg=NULL;
while (tmp != &msq->q_messages) {
msg = list_entry(tmp,struct msg_msg,m_list);
if(testmsg(msg,msgtyp,mode) &&
!security_msg_queue_msgrcv(msq, msg, current, msgtyp, mode)) {
found_msg = msg;
if(mode == SEARCH_LESSEQUAL && msg->m_type != 1) {
found_msg=msg;
msgtyp=msg->m_type-1;
} else {
found_msg=msg;
break;
}
}
tmp = tmp->next;
}
if(found_msg) {
msg=found_msg;
if ((msgsz < msg->m_ts) && !(msgflg & MSG_NOERROR)) {
err=-E2BIG;
goto out_unlock;
}
list_del(&msg->m_list);
msq->q_qnum--;
msq->q_rtime = get_seconds();
msq->q_lrpid = current->tgid;
msq->q_cbytes -= msg->m_ts;
atomic_sub(msg->m_ts,&msg_bytes);
atomic_dec(&msg_hdrs);
ss_wakeup(&msq->q_senders,0);
msg_unlock(msq);
out_success:
msgsz = (msgsz > msg->m_ts) ? msg->m_ts : msgsz;
if (put_user (msg->m_type, &msgp->mtype) ||
store_msg(msgp->mtext, msg, msgsz)) {
msgsz = -EFAULT;
}
free_msg(msg);
return msgsz;
} else
{
/* no message waiting. Prepare for pipelined
* receive.
*/
if (msgflg & IPC_NOWAIT) {
err=-ENOMSG;
goto out_unlock;
}
list_add_tail(&msr_d.r_list,&msq->q_receivers);
msr_d.r_tsk = current;
msr_d.r_msgtype = msgtyp;
msr_d.r_mode = mode;
if(msgflg & MSG_NOERROR)
msr_d.r_maxsize = INT_MAX;
else
msr_d.r_maxsize = msgsz;
msr_d.r_msg = ERR_PTR(-EAGAIN);
current->state = TASK_INTERRUPTIBLE;
msg_unlock(msq);
schedule();
/*
* The below optimisation is buggy. A sleeping thread that is
* woken up checks if it got a message and if so, copies it to
* userspace and just returns without taking any locks.
* But this return to user space can be faster than the message
* send, and if the receiver immediately exits the
* wake_up_process performed by the sender will oops.
*/
#if 0
msg = (struct msg_msg*) msr_d.r_msg;
if(!IS_ERR(msg))
//.........这里部分代码省略.........
开发者ID:xricson,项目名称:knoppix,代码行数:101,代码来源:msg.c
示例14: sys_msgsnd
asmlinkage long sys_msgsnd (int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg)
{
struct msg_queue *msq;
struct msg_msg *msg;
long mtype;
int err;
if (msgsz > msg_ctlmax || (long) msgsz < 0 || msqid < 0)
return -EINVAL;
if (get_user(mtype, &msgp->mtype))
return -EFAULT;
if (mtype < 1)
return -EINVAL;
msg = load_msg(msgp->mtext, msgsz);
if(IS_ERR(msg))
return PTR_ERR(msg);
msg->m_type = mtype;
msg->m_ts = msgsz;
msq = msg_lock(msqid);
err=-EINVAL;
if(msq==NULL)
goto out_free;
retry:
err= -EIDRM;
if (msg_checkid(msq,msqid))
goto out_unlock_free;
err=-EACCES;
if (ipcperms(&msq->q_perm, S_IWUGO))
goto out_unlock_free;
err = security_msg_queue_msgsnd(msq, msg, msgflg);
if (err)
goto out_unlock_free;
if(msgsz + msq->q_cbytes > msq->q_qbytes ||
1 + msq->q_qnum > msq->q_qbytes) {
struct msg_sender s;
if(msgflg&IPC_NOWAIT) {
err=-EAGAIN;
goto out_unlock_free;
}
ss_add(msq, &s);
msg_unlock(msq);
schedule();
current->state= TASK_RUNNING;
msq = msg_lock(msqid);
err = -EIDRM;
if(msq==NULL)
goto out_free;
ss_del(&s);
if (signal_pending(current)) {
err=-EINTR;
goto out_unlock_free;
}
goto retry;
}
msq->q_lspid = current->tgid;
msq->q_stime = get_seconds();
if(!pipelined_send(msq,msg)) {
/* noone is waiting for this message, enqueue it */
list_add_tail(&msg->m_list,&msq->q_messages);
msq->q_cbytes += msgsz;
msq->q_qnum++;
atomic_add(msgsz,&msg_bytes);
atomic_inc(&msg_hdrs);
}
err = 0;
msg = NULL;
out_unlock_free:
msg_unlock(msq);
out_free:
if(msg!=NULL)
free_msg(msg);
return err;
}
开发者ID:xricson,项目名称:knoppix,代码行数:86,代码来源:msg.c
示例15: __do_exit
// __do_exit - cause a thread exit (use do_exit, do_exit_thread instead)
// 1. call exit_mmap & put_pgdir & mm_destroy to free the almost all memory space of process
// 2. set process' state as PROC_ZOMBIE, then call wakeup_proc(parent) to ask parent reclaim itself.
// 3. call scheduler to switch to other process
static int __do_exit(void)
{
if (current == idleproc) {
panic("idleproc exit.\n");
}
if (current == initproc) {
panic("initproc exit.\n");
}
struct mm_struct *mm = current->mm;
if (mm != NULL) {
mp_set_mm_pagetable(NULL);
if (mm_count_dec(mm) == 0) {
exit_mmap(mm);
put_pgdir(mm);
bool intr_flag;
local_intr_save(intr_flag);
{
list_del(&(mm->proc_mm_link));
}
local_intr_restore(intr_flag);
mm_destroy(mm);
}
current->mm = NULL;
}
put_sighand(current);
put_signal(current);
put_fs(current);
put_sem_queue(current);
current->state = PROC_ZOMBIE;
bool intr_flag;
struct proc_struct *proc, *parent;
local_intr_save(intr_flag);
{
proc = parent = current->parent;
do {
if (proc->wait_state == WT_CHILD) {
wakeup_proc(proc);
}
proc = next_thread(proc);
} while (proc != parent);
if ((parent = next_thread(current)) == current) {
parent = initproc;
}
de_thread(current);
while (current->cptr != NULL) {
proc = current->cptr;
current->cptr = proc->optr;
proc->yptr = NULL;
if ((proc->optr = parent->cptr) != NULL) {
parent->cptr->yptr = proc;
}
proc->parent = parent;
parent->cptr = proc;
if (proc->state == PROC_ZOMBIE) {
if (parent->wait_state == WT_CHILD) {
wakeup_proc(parent);
}
}
}
}
wakeup_queue(&(current->event_box.wait_queue), WT_INTERRUPTED, 1);
local_intr_restore(intr_flag);
schedule();
panic("__do_exit will not return!! %d %d.\n", current->pid,
current->exit_code);
}
开发者ID:liangchao1992,项目名称:ucore,代码行数:77,代码来源:proc.c
示例16: ac_read
static ssize_t ac_read (struct file *filp, char __user *buf, size_t count, loff_t *ptr)
{
unsigned long flags;
unsigned int i;
unsigned char tmp;
int ret = 0;
DECLARE_WAITQUEUE(wait, current);
#ifdef DEBUG
int loopcount=0;
#endif
/* No need to ratelimit this. Only root can trigger it anyway */
if (count != sizeof(struct st_ram_io) + sizeof(struct mailbox)) {
printk( KERN_WARNING "Hmmm. read() of Applicom card, length %zd != expected %zd\n",
count,sizeof(struct st_ram_io) + sizeof(struct mailbox));
return -EINVAL;
}
while(1) {
/* Stick ourself on the wait queue */
set_current_state(TASK_INTERRUPTIBLE);
add_wait_queue(&FlagSleepRec, &wait);
/* Scan each board, looking for one which has a packet for us */
for (i=0; i < MAX_BOARD; i++) {
if (!apbs[i].RamIO)
continue;
spin_lock_irqsave(&apbs[i].mutex, flags);
tmp = readb(apbs[i].RamIO + DATA_TO_PC_READY);
if (tmp == 2) {
struct st_ram_io st_loc;
struct mailbox mailbox;
/* Got a packet for us */
ret = do_ac_read(i, buf, &st_loc, &mailbox);
spin_unlock_irqrestore(&apbs[i].mutex, flags);
set_current_state(TASK_RUNNING);
remove_wait_queue(&FlagSleepRec, &wait);
if (copy_to_user(buf, &st_loc, sizeof(st_loc)))
return -EFAULT;
if (copy_to_user(buf + sizeof(st_loc), &mailbox, sizeof(mailbox)))
return -EFAULT;
return tmp;
}
if (tmp > 2) {
/* Got an error */
Dummy = readb(apbs[i].RamIO + VERS);
spin_unlock_irqrestore(&apbs[i].mutex, flags);
set_current_state(TASK_RUNNING);
remove_wait_queue(&FlagSleepRec, &wait);
printk(KERN_WARNING "APPLICOM driver read error board %d, DataToPcReady = %d\n",
i,(int)readb(apbs[i].RamIO + DATA_TO_PC_READY));
DeviceErrorCount++;
return -EIO;
}
/* Nothing for us. Try the next board */
Dummy = readb(apbs[i].RamIO + VERS);
spin_unlock_irqrestore(&apbs[i].mutex, flags);
} /* per board */
/* OK - No boards had data for us. Sleep now */
schedule();
remove_wait_queue(&FlagSleepRec, &wait);
if (signal_pending(current))
return -EINTR;
#ifdef DEBUG
if (loopcount++ > 2) {
printk(KERN_DEBUG "Looping in ac_read. loopcount %d\n", loopcount);
}
#endif
}
}
开发者ID:tch-opensrc,项目名称:TC72XX_LxG1.0.10mp5_OpenSrc,代码行数:82,代码来源:applicom.c
示例17: fscache_wait_bit
/*
* wait_on_bit() sleep function for uninterruptible waiting
*/
int fscache_wait_bit(void *flags)
{
schedule();
return 0;
}
开发者ID:rrowicki,项目名称:Chrono_Kernel-1,代码行数:8,代码来源:main.c
示例18: while
void
IOManagerEPoll::idle()
{
epoll_event events[64];
while (true) {
unsigned long long nextTimeout;
if (stopping(nextTimeout))
return;
int rc = -1;
errno = EINTR;
while (rc < 0 && errno == EINTR) {
int timeout = -1;
if (nextTimeout != ~0ull)
timeout = (int)(nextTimeout / 1000) + 1;
rc = epoll_wait(m_epfd, events, 64, timeout);
if (rc < 0 && errno == EINTR)
nextTimeout = nextTimer();
}
MORDOR_LOG_LEVEL(g_log, rc < 0 ? Log::ERROR : Log::VERBOSE) << this
<< " epoll_wait(" << m_epfd << "): " << rc << " (" << errno << ")";
if (rc < 0)
MORDOR_THROW_EXCEPTION_FROM_LAST_ERROR_API("epoll_wait");
std::vector<boost::function<void ()> > expired = processTimers();
schedule(expired.begin(), expired.end());
for(int i = 0; i < rc; ++i) {
epoll_event &event = events[i];
if (event.data.fd == m_tickleFds[0]) {
unsigned char dummy;
int rc2 = read(m_tickleFds[0], &dummy, 1);
MORDOR_VERIFY(rc2 == 1);
MORDOR_LOG_VERBOSE(g_log) << this << " received tickle";
continue;
}
bool err = event.events & (EPOLLERR | EPOLLHUP);
boost::mutex::scoped_lock lock(m_mutex);
std::map<int, AsyncEvent>::iterator it =
m_pendingEvents.find(event.data.fd);
if (it == m_pendingEvents.end())
continue;
AsyncEvent &e = it->second;
MORDOR_LOG_TRACE(g_log) << " epoll_event {"
<< (epoll_events_t)event.events << ", " << event.data.fd
<< "}, registered for " << (epoll_events_t)e.event.events;
if ((event.events & EPOLLERR) && (e.event.events & EPOLLERR)) {
if (e.m_dgError)
e.m_schedulerError->schedule(e.m_dgError);
else
e.m_schedulerError->schedule(e.m_fiberError);
// Block other events from firing
e.m_dgError = NULL;
e.m_fiberError.reset();
e.m_dgIn = NULL;
e.m_fiberIn.reset();
e.m_dgOut = NULL;
e.m_fiberOut.reset();
event.events = 0;
e.event.events = 0;
}
if ((event.events & EPOLLHUP) && (e.event.events & EPOLLHUP)) {
if (e.m_dgClose)
e.m_schedulerError->schedule(e.m_dgClose);
else
e.m_schedulerError->schedule(e.m_fiberClose);
// Block write event from firing
e.m_dgOut = NULL;
e.m_fiberOut.reset();
e.m_dgClose = NULL;
e.m_fiberClose.reset();
event.events &= EPOLLOUT;
e.event.events &= EPOLLOUT;
err = false;
}
if (((event.events & EPOLLIN) ||
err) && (e.event.events & EPOLLIN)) {
if (e.m_dgIn)
e.m_schedulerIn->schedule(e.m_dgIn);
else
e.m_schedulerIn->schedule(e.m_fiberIn);
e.m_dgIn = NULL;
e.m_fiberIn.reset();
event.events |= EPOLLIN;
}
if (((event.events & EPOLLOUT) ||
err) && (e.event.events & EPOLLOUT)) {
if (e.m_dgOut)
e.m_schedulerOut->schedule(e.m_dgOut);
else
e.m_schedulerOut->schedule(e.m_fiberOut);
e.m_dgOut = NULL;
e.m_fiberOut.reset();
event.events |= EPOLLOUT;
}
e.event.events &= ~event.events;
int op = e.event.events == 0 ? EPOLL_CTL_DEL : EPOLL_CTL_MOD;
int rc2 = epoll_ctl(m_epfd, op, event.data.fd,
&e.event);
MORDOR_LOG_LEVEL(g_log, rc2 ? Log::ERROR : Log::VERBOSE) << this
//.........这里部分代码省略.........
开发者ID:adfin,项目名称:mordor,代码行数:101,代码来源:iomanager_epoll.cpp
示例19: main
int main(
int argc,
char *argv[])
{
char *id = "main";
struct hostent *hp;
int go, c, errflg = 0;
int lockfds;
int t = 1;
pid_t pid;
char host[100];
char *homedir = PBS_SERVER_HOME;
unsigned int port;
char *dbfile = "sched_out";
struct sigaction act;
sigset_t oldsigs;
caddr_t curr_brk = 0;
caddr_t next_brk;
extern char *optarg;
extern int optind, opterr;
extern int rpp_fd;
fd_set fdset;
int schedinit(int argc, char **argv);
int schedule(int com, int connector);
glob_argv = argv;
alarm_time = 180;
/* The following is code to reduce security risks */
/* move this to a place where nss_ldap doesn't hold a socket yet */
c = sysconf(_SC_OPEN_MAX);
while (--c > 2)
(void)close(c); /* close any file desc left open by parent */
port = get_svrport(PBS_SCHEDULER_SERVICE_NAME, "tcp",
PBS_SCHEDULER_SERVICE_PORT);
pbs_rm_port = get_svrport(PBS_MANAGER_SERVICE_NAME, "tcp",
PBS_MANAGER_SERVICE_PORT);
strcpy(pbs_current_user, "Scheduler");
msg_daemonname = strdup("pbs_sched");
opterr = 0;
while ((c = getopt(argc, argv, "L:S:R:d:p:c:a:-:")) != EOF)
{
switch (c)
{
case '-':
if ((optarg == NULL) || (optarg[0] == '\0'))
{
errflg = 1;
}
if (!strcmp(optarg, "version"))
{
fprintf(stderr, "version: %s\n", PACKAGE_VERSION);
exit(0);
}
else
{
errflg = 1;
}
break;
case 'L':
logfile = optarg;
break;
case 'S':
port = atoi(optarg);
if (port == 0)
{
fprintf(stderr,
"%s: illegal port\n", optarg);
errflg = 1;
}
break;
case 'R':
if ((pbs_rm_port = atoi(optarg)) == 0)
{
(void)fprintf(stderr, "%s: bad -R %s\n",
argv[0], optarg);
return 1;
//.........这里部分代码省略.........
开发者ID:Johnlihj,项目名称:torque,代码行数:101,代码来源:pbs_sched.c
示例20: splat_condvar_test1
static int
splat_condvar_test1(struct file *file, void *arg)
{
int i, count = 0, rc = 0;
condvar_thr_t ct[SPLAT_CONDVAR_TEST_COUNT];
condvar_priv_t cv;
cv.cv_magic = SPLAT_CONDVAR_TEST_MAGIC;
cv.cv_file = file;
mutex_init(&cv.cv_mtx, SPLAT_CONDVAR_TEST_NAME, MUTEX_DEFAULT, NULL);
cv_init(&cv.cv_condvar, NULL, CV_DEFAULT, NULL);
/* Create some threads, the exact number isn't important just as
* long as we know how many we managed to create and should expect. */
for (i = 0; i < SPLAT_CONDVAR_TEST_COUNT; i++) {
ct[i].ct_cvp = &cv;
ct[i].ct_name = SPLAT_CONDVAR_TEST1_NAME;
ct[i].ct_rc = 0;
ct[i].ct_thread = spl_kthread_create(splat_condvar_test12_thread,
&ct[i], "%s/%d", SPLAT_CONDVAR_TEST_NAME, i);
if (!IS_ERR(ct[i].ct_thread)) {
wake_up_process(ct[i].ct_thread);
count++;
}
}
/* Wait until all threads are waiting on the condition variable */
while (atomic_read(&cv.cv_condvar.cv_waiters) != count)
schedule();
/* Wake a single thread at a time, wait until it exits */
for (i = 1; i <= count; i++) {
cv_signal(&cv.cv_condvar);
while (atomic_read(&cv.cv_condvar.cv_waiters) > (count - i))
schedule();
/* Correct behavior 1 thread woken */
if (atomic_read(&cv.cv_condvar.cv_waiters) == (count - i))
continue;
splat_vprint(file, SPLAT_CONDVAR_TEST1_NAME, "Attempted to "
"wake %d thread but work %d threads woke\n",
1, count - atomic_read(&cv.cv_condvar.cv_waiters));
rc = -EINVAL;
break;
}
if (!rc)
splat_vprint(file, SPLAT_CONDVAR_TEST1_NAME, "Correctly woke &quo
|
请发表评论