简体   繁体   中英

Wait for completion possible in user-space?

There is a couple of functions I really like, when synchronizing threads in a Linux driver, which is : wait_for_completion() and its counterpart complete_and_exit()

Is it feasible to implement this api with 2 threads, sharing a memory map, respectively a writer in kernel and a reader in user-space ?

If not, what would be the effort to provide wait_for_completion() to the C language user-space thread ?

Regards, CyrIng (Fr)

A user-space process can use ioctl() calls on a device file created via mknod . Your device driver can use the arguments from the ioctl system call to come up with arguments to a wait_for_completion() call. For example, a user process could use ioctl() to pass a structure containing a code of some kind to identify what it wants, a pointer to a user-space buffer, and a size field containing the size of the buffer. The kernel thread processing the ioctl() could then block on wait_for_complete() , then fill in the user-space buffer with data.

See this web page for an example of ioctl() processing:

Introducing ioctl()

Input/Output Control (ioctl, in short) is a common operation, or system call, available in most driver categories. It is a one-bill-fits-all kind of system call. If there is no other system call that meets a particular requirement, then ioctl() is the one to use.

Practical examples include volume control for an audio device, display configuration for a video device, reading device registers, and so on — basically, anything to do with device input/output, or device-specific operations, yet versatile enough for any kind of operation (for example, for debugging a driver by querying driver data structures).

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM