信号量驱动程序
#include<linux/module.h>
#include<linux/init.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/device.h> /** udev **/
struct cdev cdev;
dev_t devno;
static struct class* test_class; /** udev **/
static struct device* test_device; /** udev **/
struct semaphore sem; /** sem **/
int test_open(struct inode *inode, struct file *filp)
{
if( !down_trylock(&sem) )
{
printk("test_open ok \n");
return 0;
}
else
{
printk("test_open error\n");
return -1;
}
return 0;
}
int test_release(struct inode *inode, struct file *filp)
{
up(&sem);
return 0;
}
static ssize_t test_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos)
{
return 0;
}
static ssize_t test_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos)
{
return 0;
}
static const struct file_operations test_fops =
{