History

[SCSI] add execute_in_process_context() API

We have several points in the SCSI stack (primarily for our device functions) where we need to guarantee process context, but (given the place where the last reference was released) we cannot guarantee this. This API gets around the issue by executing the function directly if the caller has process context, but scheduling a workqueue to execute in process context if the caller doesn't have it.

James Bottomley committed 20 years ago

Commit 1fa44ec1 parent ba3af0a2 files · +35 −0Browse files

Showing the changes to kernel/workqueue.c (1 of 2 files). Show all

Unified · Split

kernel/workqueue.c+29−0
@@ -27,6 +27,7 @@ · 26 unmodified lines
27#include <linux/cpu.h>27#include <linux/cpu.h>
28#include <linux/notifier.h>28#include <linux/notifier.h>
29#include <linux/kthread.h>29#include <linux/kthread.h>
30#include <linux/hardirq.h>
30 31
31/*32/*
32 * The per-CPU workqueue (if single thread, we always use the first33 * The per-CPU workqueue (if single thread, we always use the first
@@ -476,6 +477,34 @@ void cancel_rearming_delayed_work(struct work_struct *work) · 443 unmodified lines
476}477}
477EXPORT_SYMBOL(cancel_rearming_delayed_work);478EXPORT_SYMBOL(cancel_rearming_delayed_work);
478 479
480/**
481 * execute_in_process_context - reliably execute the routine with user context
482 * @fn: the function to execute
483 * @data: data to pass to the function
484 * @ew: guaranteed storage for the execute work structure (must
485 * be available when the work executes)
486 *
487 * Executes the function immediately if process context is available,
488 * otherwise schedules the function for delayed execution.
489 *
490 * Returns: 0 - function was executed
491 * 1 - function was scheduled for execution
492 */
493int execute_in_process_context(void (*fn)(void *data), void *data,
494 struct execute_work *ew)
495{
496 if (!in_interrupt()) {
497 fn(data);
498 return 0;
499 }
500
501 INIT_WORK(&ew->work, fn, data);
502 schedule_work(&ew->work);
503
504 return 1;
505}
506EXPORT_SYMBOL_GPL(execute_in_process_context);
507
479int keventd_up(void)508int keventd_up(void)
480{509{
481 return keventd_wq != NULL;510 return keventd_wq != NULL;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t