- Scénarios d'application Il
est très dangereux de gérer trop d'opérations dans une interruption, ce qui a un impact important sur la réponse opportune de l'interruption. Sous Linux, nous utilisons souvent INIT_DELAYED_WORK pour gérer les opérations auxquelles l'interruption doit répondre. - Fonction Fonction
File d'attente de travail (file d'attente de travail) est un mécanisme permettant de différer l'exécution des opérations dans le noyau Linux. INIT_DELAYED_WORK () est une macro - Emplacement de la fonction
\ kernel \ include \ linux \ workqueue.h - Analyse fonctionnelle
-
- Prototype de fonction
#define INIT_DELAYED_WORK(_work, _func) \
__INIT_DELAYED_WORK(_work, _func, 0)
#define __INIT_DELAYED_WORK(_work, _func, _tflags) \
do { \
INIT_WORK(&(_work)->work, (_func)); \
__setup_timer(&(_work)->timer, delayed_work_timer_fn, \
(unsigned long)(_work), \
(_tflags) | TIMER_IRQSAFE); \
} while (0)
#ifdef CONFIG_LOCKDEP
#define __INIT_WORK(_work, _func, _onstack) \
do { \
static struct lock_class_key __key; \
\
__init_work((_work), _onstack); \
(_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0); \
INIT_LIST_HEAD(&(_work)->entry); \
(_work)->func = (_func); \
} while (0)
#else
#define __INIT_WORK(_work, _func, _onstack) \
do { \
__init_work((_work), _onstack); \
(_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
INIT_LIST_HEAD(&(_work)->entry); \
(_work)->func = (_func); \
} while (0)
#endif
-
- Analyse fonctionnelle
-
démo
#define READ_VDELAY 3000 //30S
struct xxx_device{
struct delayed_work xxx_delay_work;
};
static void read_work({struct work_struct *work)
{
struct xxx_device *bq = container_of(work,
struct xxx_device, read_work.work);
schedule_delayed_work(&bq->read_work,
READ_VDELAY );
}
probe
{
struct xxx_device *bq;
...
INIT_DELAYED_WORK(&bq->xxx_delay_work, read_work);
...
}
- Lien de référence
http://blog.chinaunix.net/uid-28639221-id-5065472.html
https://blog.csdn.net/lcqlw123/article/details/46892147