trước khi thực hiện bất kỳ đọc tiếp theo. wmb đảm bảo đặt hàng trong các hoạt động ghi, và hướng dẫn mb đảm bảo cả hai. Mỗi phòng trong số các chức năng này là một siêu của hàng rào. read_barrier_depends là một hình thức, đặc biệt yếu của hàng rào đọc. | The scullsingle device maintains an atomic_t variable called scull_s_available that variable is initialized to a value of one indicating that the device is indeed available. The open call decrements and tests scull_s_available and refuses access if somebody else already has the device open static atomic_t scull_s_available ATOMIC_INIT 1 static int scull_s_open struct inode inode struct file filp . struct scull_dev dev scull_s_device device information if atomic_dec_and_test scull_s_available atomic_inc scull_s_available return -EBUSY already open then everything else is copied from the bare scull device if filp- f_flags O_ACCMOdE O_WRONLY scull_trim dev filp- private_data dev return 0 success The release call on the other hand marks the device as no longer busy static int scull_s_release struct inode inode struct file filp atomic_inc scull_s_available release the device return 0 Normally we recommend that you put the open flag scull_s_available within the device structure Scull_Dev here because conceptually it belongs to the device. The scull driver however uses standalone variables to hold the flag so it can use the same device structure and methods as the bare scull device and minimize code duplication. Restricting Access to a Single User at a Time The next step beyond a single-open device is to let a single user open a device in multiple processes but allow only one user to have the device open at a time. This solution makes it easy to test the device since the user can read and write from several processes at once but assumes that the user takes some responsibility for maintaining the integrity of the data during multiple accesses. This is accomplished by adding checks in the open method such checks are performed after the normal permission checking and can only make access more restrictive than that specified by the owner and group permission bits. This is the same access policy as that used for ttys but it doesn t resort to an external privileged program. .