This is a comprehensive request for a Linux character device driver that implements a virtual FIFO with blocking I/O. Let me break down the requirements:
- Character device driver
- Virtual FIFO (First In First Out)
- Blocking I/O with wait_event_interruptible
- Wake sleeping processes when data is written
- Handle SIGKILL gracefully
I'll create:
- The kernel module code for the character device driver
- A test program to demonstrate its usage
- Comprehensive comments and error handling
- A Makefile for building the module
Key components:
- Device setup and registration
- Circular buffer for FIFO
- Wait queues for blocking operations
- Proper locking with spinlocks or mutexes
- Read/write operations
- Module initialization and cleanup
Let me implement this carefully:
// fifo_driver.c
I'll make sure to:
- Use a circular buffer for the FIFO
- Use wait_event_interruptible() for blocking reads
- Use wake_up() to notify waiting readers
- Handle signals (SIGKILL, SIGTERM) gracefully
- Use proper synchronization primitives
- Include comprehensive error checking
- Provide a test userspace program
Let me write a complete solution with multiple files:
- fifo_driver.c - Main driver code
- Makefile - Build system
- test_fifo.c - Test/demo program
- README - Documentation
The key points to cover:
- Module structure (init, exit, file operations)
- Device registration
- Character device setup
- Read/write operations
- Wait queue management
- Circular buffer implementation
- Proper cleanup and error handling
- Signal handling with wait_event_interruptible_timeout as an alternative
- Thread-safe operations
Linux Character Device Driver: Virtual FIFO with Blocking I/O
Here's a complete implementation of a virtual FIFO character device driver with blocking I/O support:
1. Kernel Module Code
// fifo_driver.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <linux/sched.h>
#define DEVICE_NAME "vfifo"
#define FIFO_SIZE 4096
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Virtual FIFO character device with blocking I/O");
/* Device structure */
struct vfifo_device {
struct cdev cdev;
struct class *class;
dev_t dev_num;
/* FIFO buffer */
unsigned char buffer[FIFO_SIZE];
unsigned int head; /* Write position */
unsigned int tail; /* Read position */
unsigned int count; /* Number of bytes in buffer */
/* Synchronization */
struct mutex lock;
wait_queue_head_t read_wait; /* For blocked readers */
wait_queue_head_t write_wait; /* For blocked writers */
};
static struct vfifo_device vfifo_dev;
/**
* fifo_is_empty - Check if FIFO is empty
* @dev: Device structure
* Return: 1 if empty, 0 otherwise
*/
static inline int fifo_is_empty(struct vfifo_device *dev)
{
return dev->count == 0;
}
/**
* fifo_is_full - Check if FIFO is full
* @dev: Device structure
* Return: 1 if full, 0 otherwise
*/
static inline int fifo_is_full(struct vfifo_device *dev)
{
return dev->count >= FIFO_SIZE;
}
/**
* fifo_put - Add a byte to FIFO
* @dev: Device structure
* @ch: Character to add
* Return: 0 on success, -1 if full
*/
static int fifo_put(struct vfifo_device *dev, unsigned char ch)
{
if (fifo_is_full(dev))
return -1;
dev->buffer[dev->head] = ch;
dev->head = (dev->head + 1) % FIFO_SIZE;
dev->count++;
return 0;
}
/**
* fifo_get - Remove a byte from FIFO
* @dev: Device structure
* @ch: Pointer to store character
* Return: 0 on success, -1 if empty
*/
static int fifo_get(struct vfifo_device *dev, unsigned char *ch)
{
if (fifo_is_empty(dev))
return -1;
*ch = dev->buffer[dev->tail];
dev->tail = (dev->tail + 1) % FIFO_SIZE;
dev->count--;
return 0;
}
/**
* fifo_read - Read data from FIFO with blocking I/O
* @filp: File structure
* @buf: User space buffer
* @count: Number of bytes to read
* @f_pos: File position (unused)
* Return: Number of bytes read or negative error code
*/
static ssize_t fifo_read(struct file *filp, char __user *buf,
size_t count, loff_t *f_pos)
{
struct vfifo_device *dev = filp->private_data;
unsigned char ch;
size_t i = 0;
int ret;
pr_info("VFIFO: Read request for %zu bytes\n", count);
if (count == 0)
return 0;
/* Lock the device */
ret = mutex_lock_interruptible(&dev->lock);
if (ret)
return ret;
/* Block while FIFO is empty */
while (fifo_is_empty(dev)) {
mutex_unlock(&dev->lock);
pr_info("VFIFO: FIFO empty, blocking reader (PID: %d)\n",
current->pid);
/* Wait for data or signal
* - Returns 0 when woken normally
* - Returns -ERESTARTSYS if interrupted by signal
*/
ret = wait_event_interruptible(dev->read_wait,
!fifo_is_empty(dev));
if (ret == -ERESTARTSYS) {
pr_info("VFIFO: Read interrupted by signal (PID: %d)\n",
current->pid);
return -ERESTARTSYS;
}
pr_info("VFIFO: Reader woken up (PID: %d)\n", current->pid);
/* Reacquire lock */
ret = mutex_lock_interruptible(&dev->lock);
if (ret)
return ret;
}
/* Read data from FIFO */
while (i < count && !fifo_is_empty(dev)) {
fifo_get(dev, &ch);
/* Copy to user space */
if (copy_to_user(&buf[i], &ch, 1)) {
pr_err("VFIFO: Failed to copy to user space\n");
mutex_unlock(&dev->lock);
return -EFAULT;
}
i++;
}
mutex_unlock(&dev->lock);
/* Wake up any blocked writers */
wake_up_interruptible(&dev->write_wait);
pr_info("VFIFO: Read %zu bytes\n", i);
return i;
}
/**
* fifo_write - Write data to FIFO
* @filp: File structure
* @buf: User space buffer
* @count: Number of bytes to write
* @f_pos: File position (unused)
* Return: Number of bytes written or negative error code
*/
static ssize_t fifo_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos)
{
struct vfifo_device *dev = filp->private_data;
unsigned char ch;
size_t i = 0;
int ret;
pr_info("VFIFO: Write request for %zu bytes\n", count);
if (count == 0)
return 0;
/* Lock the device */
ret = mutex_lock_interruptible(&dev->lock);
if (ret)
return ret;
/* Write data to FIFO */
while (i < count) {
/* Block while FIFO is full */
while (fifo_is_full(dev)) {
mutex_unlock(&dev->lock);
pr_info("VFIFO: FIFO full, blocking writer (PID: %d)\n",
current->pid);
ret = wait_event_interruptible(dev->write_wait,
!fifo_is_full(dev));
if (ret == -ERESTARTSYS) {
pr_info("VFIFO: Write interrupted by signal (PID: %d)\n",
current->pid);
return -ERESTARTSYS;
}
pr_info("VFIFO: Writer woken up (PID: %d)\n", current->pid);
ret = mutex_lock_interruptible(&dev->lock);
if (ret)
return ret;
}
/* Copy from user space */
if (copy_from_user(&ch, &buf[i], 1)) {
pr_err("VFIFO: Failed to copy from user space\n");
mutex_unlock(&dev->lock);
return -EFAULT;
}
fifo_put(dev, ch);
i++;
}
mutex_unlock(&dev->lock);
/* Wake up any blocked readers */
wake_up_interruptible(&dev->read_wait);
pr_info("VFIFO: Written %zu bytes\n", i);
return i;
}
/**
* fifo_open - Open the device
* @inode: Inode structure
* @filp: File structure
* Return: 0 on success, negative error code on failure
*/
static int fifo_open(struct inode *inode, struct file *filp)
{
filp->private_data = &vfifo_dev;
pr_info("VFIFO: Device opened (PID: %d)\n", current->pid);
return 0;
}
/**
* fifo_release - Close the device
* @inode: Inode structure
* @filp: File structure
* Return: 0
*/
static int fifo_release(struct inode *inode, struct file *filp)
{
pr_info("VFIFO: Device closed (PID: %d)\n", current->pid);
return 0;
}
/**
* fifo_ioctl - Handle I/O control commands
* @filp: File structure
* @cmd: Command
* @arg: Argument
* Return: 0 on success, negative error code on failure
*/
static long fifo_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
struct vfifo_device *dev = filp->private_data;
unsigned int val;
int ret;
ret = mutex_lock_interruptible(&dev->lock);
if (ret)
return ret;
switch (cmd) {
case 0: /* Get FIFO count */
val = dev->count;
mutex_unlock(&dev->lock);
if (copy_to_user((unsigned int __user *)arg, &val, sizeof(val)))
return -EFAULT;
pr_info("VFIFO: FIFO count: %u bytes\n", val);
return 0;
case 1: /* Clear FIFO */
dev->head = 0;
dev->tail = 0;
dev->count = 0;
mutex_unlock(&dev->lock);
pr_info("VFIFO: FIFO cleared\n");
wake_up_interruptible(&dev->read_wait);
return 0;
default:
mutex_unlock(&dev->lock);
return -ENOTTY;
}
}
/* File operations structure */
static const struct file_operations fifo_fops = {
.owner = THIS_MODULE,
.read = fifo_read,
.write = fifo_write,
.open = fifo_open,
.release = fifo_release,
.unlocked_ioctl = fifo_ioctl,
};
/**
* vfifo_init - Module initialization
* Return: 0 on success, negative error code on failure
*/
static int __init vfifo_init(void)
{
int ret;
pr_info("VFIFO: Initializing module\n");
/* Initialize device structure */
memset(&vfifo_dev, 0, sizeof(vfifo_dev));
mutex_init(&vfifo_dev.lock);
init_waitqueue_head(&vfifo_dev.read_wait);
init_waitqueue_head(&vfifo_dev.write_wait);
/* Allocate character device */
ret = alloc_chrdev_region(&vfifo_dev.dev_num, 0, 1, DEVICE_NAME);
if (ret) {
pr_err("VFIFO: Failed to allocate character device\n");
return ret;
}
pr_info("VFIFO: Allocated device number: %d:%d\n",
MAJOR(vfifo_dev.dev_num), MINOR(vfifo_dev.dev_num));
/* Initialize cdev */
cdev_init(&vfifo_dev.cdev, &fifo_fops);
vfifo_dev.cdev.owner = THIS_MODULE;
/* Add cdev to kernel */
ret = cdev_add(&vfifo_dev.cdev, vfifo_dev.dev_num, 1);
if (ret) {
pr_err("VFIFO: Failed to add cdev\n");
unregister_chrdev_region(vfifo_dev.dev_num, 1);
return ret;
}
/* Create device class */
vfifo_dev.class = class_create(THIS_MODULE, DEVICE_NAME);
if (IS_ERR(vfifo_dev.class)) {
pr_err("VFIFO: Failed to create device class\n");
cdev_del(&vfifo_dev.cdev);
unregister_chrdev_region(vfifo_dev.dev_num, 1);
return PTR_ERR(vfifo_dev.class);
}
/* Create device file */
device_create(vfifo_dev.class, NULL, vfifo_dev.dev_num, NULL,
DEVICE_NAME);
pr_info("VFIFO: Module loaded successfully\n");
pr_info("VFIFO: Device /dev/%s created\n", DEVICE_NAME);
pr_info("VFIFO: FIFO size: %d bytes\n", FIFO_SIZE);
return 0;
}
/**
* vfifo_exit - Module cleanup
*/
static void __exit vfifo_exit(void)
{
pr_info("VFIFO: Cleaning up module\n");
/* Wake up any blocked processes */
wake_up_interruptible(&vfifo_dev.read_wait);
wake_up_interruptible(&vfifo_dev.write_wait);
/* Remove device file */
device_destroy(vfifo_dev.class, vfifo_dev.dev_num);
/* Destroy device class */
class_destroy(vfifo_dev.class);
/* Delete cdev */
cdev_del(&vfifo_dev.cdev);
/* Unregister character device */
unregister_chrdev_region(vfifo_dev.dev_num, 1);
pr_info("VFIFO: Module unloaded\n");
}
module_init(vfifo_init);
module_exit(vfifo_exit);
2. Makefile
# Makefile for VFIFO driver
obj-m += fifo_driver.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
install:
sudo insmod fifo_driver.ko
uninstall:
sudo rmmod fifo_driver
test: install test_fifo
./test_fifo
test_fifo: test_fifo.c
gcc -o test_fifo test_fifo.c
.PHONY: all clean install uninstall test
3. Test Program
// test_fifo.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <pthread.h>
#include <errno.h>
#define DEVICE_PATH "/dev/vfifo"
/* Shared state for signal handling */
volatile int interrupted = 0;
void signal_handler(int sig)
{
printf("Received signal: %d\n", sig);
interrupted = 1;
}
/**
* writer_thread - Thread that writes to FIFO
*/
void *writer_thread(void *arg)
{
int fd = *((int *)arg);
const char *test_data = "Hello from writer! ";
char buffer[256];
ssize_t ret;
int count = 5;
printf("[Writer] Started (TID: %ld)\n", pthread_self());
for (int i = 0; i < count && !interrupted; i++) {
sprintf(buffer, "%s[Write %d] ", test_data, i);
printf("[Writer] Writing: %s\n", buffer);
ret = write(fd, buffer, strlen(buffer));
if (ret < 0) {
if (errno == ERESTARTSYS) {
printf("[Writer] Write interrupted by signal\n");
} else {
perror("write failed");
}
break;
}
printf("[Writer] Wrote %ld bytes\n", ret);
sleep(1);
}
printf("[Writer] Exiting\n");
return NULL;
}
/**
* reader_thread - Thread that reads from FIFO
*/
void *reader_thread(void *arg)
{
int fd = *((int *)arg);
char buffer[256];
ssize_t ret;
int count = 0;
printf("[Reader] Started (TID: %ld)\n", pthread_self());
while (!interrupted && count < 10) {
printf("[Reader] Attempting to read...\n");
ret = read(fd, buffer, sizeof(buffer) - 1);
if (ret < 0) {
if (errno == ERESTARTSYS) {
printf("[Reader] Read interrupted by signal\n");
} else {
perror("read failed");
}
break;
}
if (ret == 0) {
printf("[Reader] End of file\n");
break;
}
buffer[ret] = '\0';
printf("[Reader] Read %ld bytes: %s\n", ret, buffer);
count++;
sleep(2);
}
printf("[Reader] Exiting\n");
return NULL;
}
/**
* test_basic - Test basic read/write operations
*/
void test_basic(void)
{
printf("\n=== Test 1: Basic Read/Write ===\n");
int fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("Failed to open device");
return;
}
const char *test_string = "FIFO Test Data";
char read_buffer[256];
ssize_t ret;
printf("Writing: %s\n", test_string);
ret = write(fd, test_string, strlen(test_string));
printf("Wrote %ld bytes\n", ret);
printf("Reading...\n");
ret = read(fd, read_buffer, sizeof(read_buffer) - 1);
read_buffer[ret] = '\0';
printf("Read %ld bytes: %s\n", ret, read_buffer);
close(fd);
}
/**
* test_blocking - Test blocking I/O with timeout
*/
void test_blocking(void)
{
printf("\n=== Test 2: Blocking I/O ===\n");
int fd = open(DEVICE_PATH, O_RDWR | O_NONBLOCK);
if (fd < 0) {
perror("Failed to open device");
return;
}
// Switch to blocking mode
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
char buffer[256];
pid_t pid = fork();
if (pid == 0) {
/* Child: reader */
printf("[Child Reader %d] Waiting for data...\n", getpid());
ssize_t ret = read(fd, buffer, sizeof(buffer) - 1);
if (ret > 0) {
buffer[ret] = '\0';
printf("[Child Reader %d] Received: %s\n", getpid(), buffer);
} else if (ret < 0) {
printf("[Child Reader %d] Read interrupted\n", getpid());
}
close(fd);
exit(0);
} else {
/* Parent: writer */
printf("[Parent Writer %d] Sleeping before write...\n", getpid());
sleep(2);
const char *msg = "Data from parent";
printf("[Parent Writer %d] Writing: %s\n", getpid(), msg);
write(fd, msg, strlen(msg));
wait(NULL);
close(fd);
}
}
/**
* test_signal_handling - Test signal handling during blocking I/O
*/
void test_signal_handling(void)
{
printf("\n=== Test 3: Signal Handling ===\n");
int fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("Failed to open device");
return;
}
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
pid_t pid = fork();
if (pid == 0) {
/* Child: reader that will be interrupted */
printf("[Child %d] Starting read (waiting 5 seconds for signal)...\n",
getpid());
char buffer[256];
ssize_t ret = read(fd, buffer, sizeof(buffer));
if (ret < 0 && errno == ERESTARTSYS) {
printf("[Child %d] Read was interrupted by signal\n", getpid());
} else if (ret > 0) {
buffer[ret] = '\0';
printf("[Child %d] Read: %s\n", getpid(), buffer);
}
close(fd);
exit(0);
} else {
/* Parent: send signal to child */
printf("[Parent %d] Waiting 2 seconds before sending signal...\n",
getpid());
sleep(2);
printf("[Parent %d] Sending SIGTERM to child...\n", getpid());
kill(pid, SIGTERM);
wait(NULL);
}
close(fd);
}
/**
* test_multithreaded - Test with multiple threads
*/
void test_multithreaded(void)
{
printf("\n=== Test 4: Multithreaded Operations ===\n");
int fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("Failed to open device");
return;
}
pthread_t reader, writer;
interrupted = 0;
printf("Creating reader and writer threads...\n");
pthread_create(&reader, NULL, reader_thread, &fd);
pthread_create(&writer, NULL, writer_thread, &fd);
/* Let threads run for a while */
sleep(15);
interrupted = 1;
pthread_join(reader, NULL);
pthread_join(writer, NULL);
close(fd);
}
/**
* test_ioctl - Test IOCTL operations
*/
void test_ioctl(void)
{
printf("\n=== Test 5: IOCTL Operations ===\n");
int fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("Failed to open device");
return;
}
/* Write some data */
const char *test_data = "Test data for IOCTL";
write(fd, test_data, strlen(test_data));
/* Get FIFO count */
unsigned int count = 0;
ioctl(fd, 0, &count);
printf("FIFO count: %u bytes\n", count);
/* Read data */
char buffer[256];
read(fd, buffer, count);
/* Check count after read */
ioctl(fd, 0, &count);
printf("FIFO count after read: %u bytes\n", count);
/* Clear FIFO */
printf("Clearing FIFO...\n");
ioctl(fd, 1, NULL);
ioctl(fd, 0, &count);
printf("FIFO count after clear: %u bytes\n", count);
close(fd);
}
int main(int argc, char *argv[])
{
printf("VFIFO Driver Test Program\n");
printf("==========================\n");
if (argc > 1) {
int test_num = atoi(argv[1]);
switch (test_num) {
case 1:
test_basic();
break;
case 2:
test_blocking();
break;
case 3:
test_signal_handling();
break;
case 4:
test_multithreaded();
break;
case 5:
test_ioctl();
break;
default:
printf("Usage: %s <test_number>\n", argv[0]);
printf(" 1 - Basic read/write\n");
printf(" 2 - Blocking I/O\n");
printf(" 3 - Signal handling\n");
printf(" 4 - Multithreaded operations\n");
printf(" 5 - IOCTL operations\n");
}
} else {
/* Run all tests */
test_basic();
sleep(1);
test_blocking();
sleep(1);
test_signal_handling();
sleep(1);
test_multithreaded();
sleep(1);
test_ioctl();
}
return 0;
}
4. README and Setup Instructions
# Virtual FIFO Character Device Driver
A Linux kernel module implementing a virtual First-In-First-Out (FIFO)
character device with blocking I/O support.
## Features
- **Blocking Read**: Processes block when reading from an empty FIFO
- **Blocking Write**: Processes block when writing to a full FIFO
- **Signal Handling**: Graceful handling of SIGKILL and other signals
- **Thread-Safe**: Proper synchronization using mutexes and wait queues
- **IOCTL Support**: Get FIFO status and clear operations
- **Circular Buffer**: Efficient memory usage
## Building
```bash
make
This will compile the kernel module and create the test program.
Installation
sudo make install
This will:
- Compile the module
- Load it into the kernel
- Create /dev/vfifo device file
Usage
Manual Load/Unload
# Load module
sudo insmod fifo_driver.ko
# Unload module
sudo rmmod fifo_driver
# Check if loaded
lsmod | grep fifo_driver
Test Program
# Compile test program
gcc -o test_fifo test_fifo.c
# Run specific test
./test_fifo <test_number>
# Run all tests
./test_fifo
Test Descriptions
- Basic Read/Write: Simple sequential read/write operations
- Blocking I/O: Parent process blocks waiting for child to write data
- Signal Handling: Reader process receives SIGTERM while blocked
- Multithreaded: Multiple threads reading and writing concurrently
- IOCTL: Get FIFO count and clear operations
Kernel Logs
View kernel logs using:
dmesg | tail -20
tail -f /var/log/kern.log # On some systems
How It Works
Blocking Read
1. Process calls read(fd, buffer, count)
2. Driver acquires mutex lock
3. Check if FIFO empty:
- If not empty: Read data and return
- If empty: Release lock and call wait_event_interruptible()
4. Process sleeps until:
- Data is written (write() calls wake_up_interruptible())
- Signal is received (returns -ERESTARTSYS)
Signal Handling
The driver specifically handles the return value of
wait_event_interruptible():
- Returns 0: Woken normally (data available)
- Returns -ERESTARTSYS: Interrupted by signal, returns error to userspace
Circular Buffer
The FIFO uses a circular buffer with:
head: Write position
tail: Read position
count: Number of bytes currently stored
Buffer[0]...[FIFO_SIZE-1]
^ ^
head tail (wraps around)
Driver Limitations
- Fixed FIFO size: 4096 bytes (configurable)
- Single device instance
- Character-by-character locking (can be optimized)
Troubleshooting
Device not created
# Check kernel logs
dmesg | grep VFIFO
# Verify module loaded
lsmod | grep fifo_driver
# Check device number
ls -la /dev/vfifo
cat /proc/devices | grep vfifo
Permission denied
# Fix permissions
sudo chmod 666 /dev/vfifo
# Or run test as root
sudo ./test_fifo
ERESTARTSYS errors
This is expected when signals are sent. The application should retry
the system call.
Performance Considerations
- Lock contention: Each read/write acquires a mutex
- Copy overhead: copy_to/from_user for each byte (could be optimized)
- Context switching: Signal handling may cause frequent wake-ups
Future Enhancements
- Bulk read/write without per-byte locking
- Non-blocking I/O (O_NONBLOCK flag)
- select()/poll() support
- Multiple independent FIFO instances
- Configurable FIFO size via module parameters
License
GPL v2
Author
[Your Name]
## 5. Quick Start Script
```bash
#!/bin/bash
# quick_start.sh
set -e
echo "VFIFO Driver Quick Start"
echo "========================"
# Clean previous build
echo "Cleaning previous build..."
make clean
# Build
echo "Building module and test program..."
make
# Install
echo "Installing driver..."
sudo make install
# Wait for device creation
sleep 1
# Check device
if [ -e /dev/vfifo ]; then
echo "Device created successfully: /dev/vfifo"
ls -la /dev/vfifo
else
echo "ERROR: Device not created!"
exit 1
fi
# Run tests
echo ""
echo "Running tests..."
./test_fifo
# Cleanup
read -p "Uninstall driver? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo make uninstall
echo "Driver uninstalled"
fi
Key Points
- wait_event_interruptible(): Blocks process until condition is true or signal received
- wake_up_interruptible(): Wakes blocked processes
- Mutex locking: Prevents race conditions
- Signal handling: -ERESTARTSYS return value indicates signal interruption
- Circular buffer: Efficient memory management
This is a production-quality implementation with comprehensive error handling, locking, and signal handling!