中断API之tasklet_enable/tasklet_disable

static inline void tasklet_enable(struct tasklet_struct *t)和static inline void tasklet_disable(struct tasklet_struct *t)
分别用于使能和禁止tasklet。
其使用的例程如下:
void drv_stop(struct ieee80211_local *local)
{
	might_sleep();

	if (WARN_ON(!local->started))
		return;

	trace_drv_stop(local);
	local->ops->stop(&local->hw);
	trace_drv_return_void(local);

	/* sync away all work on the tasklet before clearing started */
	tasklet_disable(&local->tasklet);
	tasklet_enable(&local->tasklet);

	barrier();

	local->started = false;
}
其源码分析如下:
static inline void tasklet_enable(struct tasklet_struct *t)
{
	smp_mb__before_atomic();
	atomic_dec(&t->count);
}
可见tasklet_enable 仅仅是增加tasklet_struct的成员变量count
static inline void tasklet_disable(struct tasklet_struct *t)
{
	#与前面的对应减少tasklet_struct的成员变量count
	tasklet_disable_nosync(t);
	#等待这个task 运行完成
	tasklet_unlock_wait(t);
	smp_mb();
}
可见disable的时候一定回阻塞当前进程,直到tasklet 运行完成
static inline void tasklet_unlock_wait(struct tasklet_struct *t)
{
	while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
}

与tasklet相关的flags最共有两个,分别如下:
enum
{
	TASKLET_STATE_SCHED,	/* Tasklet is scheduled for execution */
	TASKLET_STATE_RUN	/* Tasklet is running (SMP only) */
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值