OpenSS7
SS7 for the
Common Man

© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved.
Last modified:

Home Overview Status News Documentation Resources About
   
 Overview
 Status
 News
 Documentation
 Resources
 About

   
Home Index Prev Next More Download Info FAQ Mail   Home -> Resources -> Browse Source -> strss7/drivers/timer.h


File /code/strss7/drivers/timer.h



#ifndef __TIMER_H__
#define __TIMER_H__

#define SS7_DECLARE_TIMER(__n,__o,__t,__c) \
STATIC int __o ## _ ## __t ## _timeout(struct __o *); \
STATIC void __o ## _ ## __t ## _expiry(caddr_t data) \
{ \
	ss7_do_timeout(data, # __t, __n, &((struct __o *)data)->timers.__t, \
			(int(*)(struct head *))&__o ## _ ## __t ## _timeout, \
			&__o ## _ ## __t ## _expiry); \
} \
STATIC void __o ## _stop_timer_ ## __t (struct __o * __o) \
{ \
	ss7_stop_timer((struct head *)__o, # __t, __n, &__o->timers.__t); \
} \
STATIC void __o ## _start_timer_ ## __t (struct __o * __o) \
{ \
	ss7_start_timer((struct head *)__o, # __t, __n, &__o->timers.__t, &__o ## _ ## __t ## _expiry, __o->__c.__t); \
} \

STATIC INLINE void ss7_do_timeout(caddr_t data, const char *timer, const char *mod, ulong * timeo,
				  int (*to_fnc) (struct head *), void (*exp_func) (caddr_t))
{
	struct head *h = (struct head *) data;
	if (xchg(timeo, 0)) {
		if (lis_spin_trylock(&h->lock)) {
			printd(("%s: %p: %s timeout at %lu\n", mod, h, timer, jiffies));
			switch (to_fnc(h)) {
			default:
			case QR_DONE:
				lis_spin_unlock(&h->lock);
				if (h->put)
					h->put(h);
				else
					printd(("%s: %p: object has no put procedure\n", mod, h));
				return;
			case -ENOMEM:
			case -ENOBUFS:
			case -EBUSY:
			case -EAGAIN:
				break;
			}
			lis_spin_unlock(&h->lock);
		} else
			printd(("%s: %p: %s timeout collision at %lu\n", mod, h, timer, jiffies));
		/* back off timer two ticks */
		*timeo = timeout(exp_func, data, 2);
	}
}
STATIC INLINE void ss7_stop_timer(struct head *h, const char *timer, const char *mod, ulong * timeo)
{
	ulong to;
	if ((to = xchg(timeo, 0))) {
		untimeout(to);
		printd(("%s: %p: stopping %s at %lu\n", mod, h, timer, jiffies));
		if (h->put)
			h->put(h);
		else
			printd(("%s: %p: object has no put procedure\n", mod, h));
	}
	return;
}
STATIC INLINE void ss7_start_timer(struct head *h, const char *timer, const char *mod, ulong * timeo,
				   void (*exp_func) (caddr_t), ulong val)
{
	printd(("%s: %p: starting %s %lu ms at %lu\n", mod, h, timer, val * 1000 / HZ, jiffies));
	if (h->get)
		h->get(h);
	else
		printd(("%s: %p: object has no get procedure\n", mod, h));
	*timeo = timeout(exp_func, (caddr_t) h, val);
}

#endif				/* __TIMER_H__ */


Home Index Prev Next More Download Info FAQ Mail   Home -> Resources -> Browse Source -> strss7/drivers/timer.h

OpenSS7
SS7 for the
Common Man
Home Overview Status News Documentation Resources About

© Copyright 1997-2004,OpenSS7 Corporation, All Rights Reserved.
Last modified: