[svn-commits] fjoe: freebsd/trunk r8309 - in /freebsd/trunk: freebsd/dahdi/ include/dahdi/ ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 9 13:36:24 CST 2010


Author: fjoe
Date: Tue Mar  9 13:36:21 2010
New Revision: 8309

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8309
Log:
- Workqueue API
- down_interruptible should return int
- Tasklet API:
	- implement tasklet_disable() properly
	- add tasklet_enable()
- Add cpu_to_le16()

Modified:
    freebsd/trunk/freebsd/dahdi/bsd-compat.c
    freebsd/trunk/include/dahdi/compat/bsd.h
    freebsd/trunk/include/dahdi/kernel.h

Modified: freebsd/trunk/freebsd/dahdi/bsd-compat.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/freebsd/dahdi/bsd-compat.c?view=diff&rev=8309&r1=8308&r2=8309
==============================================================================
--- freebsd/trunk/freebsd/dahdi/bsd-compat.c (original)
+++ freebsd/trunk/freebsd/dahdi/bsd-compat.c Tue Mar  9 13:36:21 2010
@@ -36,10 +36,16 @@
 
 #include <dahdi/compat/bsd.h>
 
+/*
+ * Tasklet API
+ */
 static void
 tasklet_run(void *context, int pending)
 {
 	struct tasklet_struct *t = (struct tasklet_struct *) context;
+
+	if (atomic_read(&t->disable_count))
+		return;
 	t->func(t->data);
 }
 
@@ -49,6 +55,7 @@
 	TASK_INIT(&t->task, 0, tasklet_run, t);
 	t->func = func;
 	t->data = data;
+	t->disable_count = 0;
 }
 
 void
@@ -60,7 +67,13 @@
 void
 tasklet_disable(struct tasklet_struct *t)
 {
-	// nothing to do
+	atomic_inc(&t->disable_count);
+}
+
+void
+tasklet_enable(struct tasklet_struct *t)
+{
+	atomic_dec(&t->disable_count);
 }
 
 void
@@ -69,6 +82,9 @@
 	taskqueue_drain(taskqueue_fast, &t->task);
 }
 
+/*
+ * Timer API
+ */
 static void
 run_timer(void *arg)
 {
@@ -134,6 +150,9 @@
 	del_timer_sync(t);
 }
 
+/*
+ * Completion API
+ */
 void
 init_completion(struct completion *c)
 {
@@ -169,6 +188,9 @@
 	cv_signal(&c->cv);
 }
 
+/*
+ * Semaphore API
+ */
 void
 _sema_init(struct semaphore *s, int value)
 {
@@ -181,10 +203,11 @@
 	sema_destroy(&s->sema);
 }
 
-void
+int
 down_interruptible(struct semaphore *s)
 {
 	sema_wait(&s->sema);
+	return 0;
 }
 
 void
@@ -193,6 +216,69 @@
 	sema_post(&s->sema);
 }
 
+/*
+ * Workqueue API
+ */
+void
+work_run(void *context, int pending)
+{
+	struct work_struct *work = (struct work_struct *) context;
+	work->func(work);
+}
+
+void
+schedule_work(struct work_struct *work)
+{
+	taskqueue_enqueue_fast(taskqueue_fast, &work->task);
+}
+
+void
+cancel_work_sync(struct work_struct *work)
+{
+	taskqueue_drain(taskqueue_fast, &work->task);
+}
+
+struct workqueue_struct *
+create_singlethread_workqueue(const char *name)
+{
+	int res;
+	struct workqueue_struct *wq;
+
+	wq = malloc(sizeof(*wq), M_DAHDI, M_NOWAIT);
+	if (wq == NULL)
+		return NULL;
+
+	wq->tq = taskqueue_create_fast(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->tq);
+	if (wq->tq == NULL) {
+		free(wq, M_DAHDI);
+		return NULL;
+	}
+
+	res = taskqueue_start_threads(&wq->tq, 1, PI_NET, "%s taskq", name);
+	if (res) {
+		destroy_workqueue(wq);
+		return NULL;
+	}
+
+	return wq;
+}
+
+void
+destroy_workqueue(struct workqueue_struct *wq)
+{
+	taskqueue_free(wq->tq);
+	free(wq, M_DAHDI);
+}
+
+void
+queue_work(struct workqueue_struct *wq, struct work_struct *work)
+{
+	taskqueue_enqueue(wq->tq, &work->task);
+}
+
+/*
+ * Logging API
+ */
 void
 rlprintf(int pps, const char *fmt, ...)
 {
@@ -221,6 +307,36 @@
 		va_end(ap);
 	}
 }
+
+int
+printk_ratelimit(void)
+{
+	static struct timeval last_printk;
+	static int count;
+
+	return ppsratecheck(&last_printk, &count, 10);
+}
+
+/*
+ * Kernel module API
+ */
+int
+request_module(const char *fmt, ...)
+{
+	va_list ap;
+	char modname[128];
+	int fileid;
+
+	va_start(ap, fmt);
+	vsnprintf(modname, sizeof(modname), fmt, ap);
+	va_end(ap);
+
+	return kern_kldload(curthread, modname, &fileid);
+}
+
+/*
+ * Misc API
+ */
 
 /*
  * Concatenate src on the end of dst.  At most strlen(dst)+n+1 bytes
@@ -244,26 +360,3 @@
 	}
 	return (dst);
 }
-
-int
-printk_ratelimit(void)
-{
-	static struct timeval last_printk;
-	static int count;
-
-	return ppsratecheck(&last_printk, &count, 10);
-}
-
-int
-request_module(const char *fmt, ...)
-{
-	va_list ap;
-	char modname[128];
-	int fileid;
-
-	va_start(ap, fmt);
-	vsnprintf(modname, sizeof(modname), fmt, ap);
-	va_end(ap);
-
-	return kern_kldload(curthread, modname, &fileid);
-}

Modified: freebsd/trunk/include/dahdi/compat/bsd.h
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/include/dahdi/compat/bsd.h?view=diff&rev=8309&r1=8308&r2=8309
==============================================================================
--- freebsd/trunk/include/dahdi/compat/bsd.h (original)
+++ freebsd/trunk/include/dahdi/compat/bsd.h Tue Mar  9 13:36:21 2010
@@ -12,26 +12,41 @@
 #include <sys/taskqueue.h>
 #include <machine/atomic.h>
 
-struct module;
-
-#define EXPORT_SYMBOL(s)
-
 #define LINUX_VERSION_CODE	-1
 #define KERNEL_VERSION(x, y, z)	0
 
+/*
+ * Byte order API
+ */
 #define cpu_to_le32(x)	htole32(x)
 #define le32_to_cpu(x)	le32toh(x)
-
+#define cpu_to_le16(x)	htole16(x)
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+#define __constant_htons(x)	((uint16_t) (((uint16_t) (x)) << 8 | ((uint16_t) (x)) >> 8))
+#else
+#define __constant_htons(x)	(x)
+#endif
+
+/*
+ * Copy from/to user API
+ */
 #define copy_from_user(to, from, n)	(bcopy((from), (to), (n)), 0)
 #define copy_to_user(to, from, n)	(bcopy((from), (to), (n)), 0)
 
 #define get_user(v, p)	copy_from_user(&(v), (void *) (p), sizeof(v))
 #define put_user(v, p)	copy_to_user((void *) (p), &(v), sizeof(v))
 
+/*
+ * Waitqueue API
+ */
 typedef void *wait_queue_head_t;
 #define init_waitqueue_head(q)
 #define wake_up_interruptible(q)	wakeup(q)
 
+/*
+ * Bit API
+ */
 #define test_bit(v, p)	((*(p)) & (1 << ((v) & 0x1f)))
 #define set_bit(v, p)	atomic_set_long((p), (1 << ((v) & 0x1f)))
 #define clear_bit(v, p)	atomic_clear_long((p), (1 << ((v) & 0x1f)))
@@ -66,7 +81,10 @@
 	return oldbit;
 }
 
-typedef u_int atomic_t;
+/*
+ * Atomic API
+ */
+typedef int atomic_t;
 #define atomic_set(p, v)	(*(p) = (v))
 #define atomic_read(p)		(*(p))
 #define atomic_inc(p)		atomic_add_int(p, 1)
@@ -77,21 +95,20 @@
 
 #define ATOMIC_INIT(v)		(v)
 
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-#define __constant_htons(x)	((uint16_t) (((uint16_t) (x)) << 8 | ((uint16_t) (x)) >> 8))
-#else
-#define __constant_htons(x)	(x)
-#endif
-
+/*
+ * Spinlock API
+ */
 typedef struct mtx spinlock_t;
 
 #define DEFINE_SPINLOCK(name)				\
 	struct mtx name;				\
 	MTX_SYSINIT(name, &name, #name, MTX_SPIN)
-#define spin_lock_init(lock)	mtx_init(lock, "dahdi lock", NULL, MTX_SPIN)
+#define spin_lock_init(lock)	mtx_init(lock, "DAHDI spinlock", NULL, MTX_SPIN)
 #define spin_lock_destroy(lock)	mtx_destroy(lock)
 #define spin_lock(lock)		mtx_lock_spin(lock)
 #define spin_unlock(lock)	mtx_unlock_spin(lock)
+#define spin_lock_bh(lock)	spin_lock(lock)
+#define spin_unlock_bh(lock)	spin_unlock(lock)
 #define spin_lock_irqsave(lock, flags)			\
 	do {						\
 		mtx_lock_spin(lock);			\
@@ -100,9 +117,15 @@
 #define spin_unlock_irqrestore(lock, flags)		\
 	mtx_unlock_spin(lock)
 
+/*
+ * Rwlock API
+ */
+typedef struct sx rwlock_t;
+
 #define DEFINE_RWLOCK(name)				\
 	struct sx name;					\
 	SX_SYSINIT(name, &name, #name)
+#define rwlock_init(rwlock)	sx_init(rwlock, "DAHDI rwlock")
 #define read_lock(rwlock)	sx_slock(rwlock)
 #define read_unlock(rwlock)	sx_sunlock(rwlock)
 
@@ -116,18 +139,26 @@
 #define write_unlock_irqrestore(rwlock, flags)		\
 	sx_xunlock(rwlock)
 
+/*
+ * Tasklet API
+ */
 struct tasklet_struct {
 	struct task task;
 
 	void (*func)(unsigned long);
 	unsigned long data;
+	atomic_t disable_count;
 };
 
 void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data);
 void tasklet_hi_schedule(struct tasklet_struct *t);
 void tasklet_disable(struct tasklet_struct *t);
+void tasklet_enable(struct tasklet_struct *t);
 void tasklet_kill(struct tasklet_struct *t);
 
+/*
+ * Timer API
+ */
 struct timer_list {
 	struct mtx mtx;
 	struct callout callout;
@@ -143,6 +174,9 @@
 void del_timer(struct timer_list *t);
 void del_timer_sync(struct timer_list *t);
 
+/*
+ * Completion API
+ */
 struct completion {
 	struct cv cv;
 	struct mtx lock;
@@ -154,15 +188,50 @@
 int wait_for_completion_timeout(struct completion *c, unsigned long timeout);
 void complete(struct completion *c);
 
+/*
+ * Semaphore API
+ */
 struct semaphore {
 	struct sema sema;
 };
 
 void _sema_init(struct semaphore *s, int value);
 void _sema_destroy(struct semaphore *s);
-void down_interruptible(struct semaphore *s);
+int down_interruptible(struct semaphore *s);
 void up(struct semaphore *s);
 
+/*
+ * Workqueue API
+ */
+struct work_struct;
+
+typedef void (*work_func_t)(struct work_struct *work);
+
+struct work_struct {
+	struct task task;
+	work_func_t func;
+};
+
+#define INIT_WORK(ws, wf)					\
+	do {							\
+		TASK_INIT(&(ws)->task, 0, work_run, (ws));	\
+		(ws)->func = (wf);				\
+	} while (0)
+void work_run(void *context, int pending);
+void schedule_work(struct work_struct *work);
+void cancel_work_sync(struct work_struct *work);
+
+struct workqueue_struct {
+	struct taskqueue *tq;
+};
+
+struct workqueue_struct *create_singlethread_workqueue(const char *name);
+void destroy_workqueue(struct workqueue_struct *wq);
+void queue_work(struct workqueue_struct *wq, struct work_struct *work);
+
+/*
+ * Logging and assertions API
+ */
 void rlprintf(int pps, const char *fmt, ...)
 	__printflike(2, 3);
 
@@ -170,8 +239,7 @@
 device_rlprintf(int pps, device_t dev, const char *fmt, ...)
 	__printflike(3, 4);
 
-char *
-strncat(char * __restrict dst, const char * __restrict src, size_t n);
+#define might_sleep()
 
 #define WARN_ON(cond)					\
 	do {						\
@@ -205,6 +273,9 @@
 
 int printk_ratelimit(void);
 
+/*
+ * Malloc API
+ */
 #define GFP_KERNEL	0
 #define GFP_ATOMIC	0
 
@@ -215,24 +286,47 @@
 #define kzalloc(a, b)		kcalloc(1, (a), (b))
 #define kfree(p)		free(p, M_DAHDI)
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-#define memmove(dst, src, size)	bcopy((src), (dst), (size))
-
-#define might_sleep()
-
-#define ENODATA EINVAL
-
+/*
+ * Kernel module API
+ */
 #define __init
 #define __exit
 #define __devinit
 #define __devexit
 #define __devinitdata
-#define __user
-
-#define likely(x)       __builtin_expect(!!(x), 1)
-#define unlikely(x)     __builtin_expect(!!(x), 0)
-
+
+struct module;
+
+#define try_module_get(m)	(1)
+#define module_put(m)		((void) (m))
+#define THIS_MODULE		((struct module *) __FILE__)
+int request_module(const char *fmt, ...);
+
+#define EXPORT_SYMBOL(s)
+
+/*
+ * PCI device API
+ */
+#define PCI_ANY_ID (~0)
+
+struct pci_device_id {
+	uint32_t vendor, device;	/* Vendor and device ID or PCI_ANY_ID*/
+	uint32_t subvendor, subdevice;	/* Subsystem ID's or PCI_ANY_ID */
+	uint32_t class, class_mask;	/* (class,subclass,prog-if) triplet */
+	unsigned long driver_data;	/* Data private to the driver */
+};
+
+struct pci_dev {
+	device_t dev;
+};
+
+#define dahdi_pci_get_bus(pci_dev)	pci_get_bus((pci_dev)->dev)
+#define dahdi_pci_get_slot(pci_dev)	pci_get_slot((pci_dev)->dev)
+#define dahdi_pci_get_irq(pci_dev)	pci_get_irq((pci_dev)->dev)
+
+/*
+ * Time API
+ */
 #if 1
 /* emulate jiffies */
 static inline unsigned long _jiffies(void)
@@ -261,28 +355,23 @@
 #define time_after_eq(a, b)	((a) >= (b))
 #define time_before(a, b)	((a) < (b))
 
-#define try_module_get(m)	(1)
-#define module_put(m)		((void) (m))
-#define THIS_MODULE		((struct module *) __FILE__)
-int request_module(const char *fmt, ...);
+/*
+ * Misc API
+ */
+char *
+strncat(char * __restrict dst, const char * __restrict src, size_t n);
+
+#define memmove(dst, src, size)	bcopy((src), (dst), (size))
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#define ENODATA EINVAL
+
+#define __user
+
+#define likely(x)       __builtin_expect(!!(x), 1)
+#define unlikely(x)     __builtin_expect(!!(x), 0)
 
 #define DAHDI_IRQ_HANDLER(a)	static int a(void *dev_id)
 
-#define PCI_ANY_ID (~0)
-
-struct pci_device_id {
-	uint32_t vendor, device;	/* Vendor and device ID or PCI_ANY_ID*/
-	uint32_t subvendor, subdevice;	/* Subsystem ID's or PCI_ANY_ID */
-	uint32_t class, class_mask;	/* (class,subclass,prog-if) triplet */
-	unsigned long driver_data;	/* Data private to the driver */
-};
-
-struct pci_dev {
-	device_t dev;
-};
-
-#define dahdi_pci_get_bus(pci_dev)	pci_get_bus((pci_dev)->dev)
-#define dahdi_pci_get_slot(pci_dev)	pci_get_slot((pci_dev)->dev)
-#define dahdi_pci_get_irq(pci_dev)	pci_get_irq((pci_dev)->dev)
-
 #endif /* _DAHDI_COMPAT_BSD_H_ */

Modified: freebsd/trunk/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/include/dahdi/kernel.h?view=diff&rev=8309&r1=8308&r2=8309
==============================================================================
--- freebsd/trunk/include/dahdi/kernel.h (original)
+++ freebsd/trunk/include/dahdi/kernel.h Tue Mar  9 13:36:21 2010
@@ -43,6 +43,7 @@
 #include <sys/selinfo.h>
 #include <sys/taskqueue.h>
 #include <sys/uio.h>
+#include <sys/libkern.h>
 
 #include <dahdi/compat/types.h>
 #include <dahdi/compat/list.h>




More information about the svn-commits mailing list