052f7688bb9f36d804529eca4ca65176fc04c428
10 #define container_of(ptr, type, member) ({ \
11 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
12 (type *)( (char *)__mptr - offsetof(type,member) );})
15 #define KERN_NOTICE ""
19 #define KERN_WARNING ""
23 #define MAX_ERRNO 4095
25 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
27 static inline void *ERR_PTR(long error
)
29 return (void *) error
;
32 static inline long PTR_ERR(const void *ptr
)
37 static inline long IS_ERR(const void *ptr
)
39 return IS_ERR_VALUE((unsigned long)ptr
);
43 /* FIXED SIZE INTEGERS */
48 //typedef uint16_t u16;
49 //typedef uint32_t u32;
50 //typedef uint64_t u64;
52 #define min_t(type, x, y) ({ \
55 __min1 < __min2 ? __min1: __min2; })
57 #define max_t(type, x, y) ({ \
60 __max1 > __max2 ? __max1: __max2; })
67 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
68 #define DECLARE_MUTEX(m) extern pthread_mutex_t (m);
70 #define mutex_lock(m) pthread_mutex_lock(m)
72 #define mutex_unlock(m) pthread_mutex_unlock(m)
76 typedef int spinlock_t
;
78 #define spin_lock(a) /* nothing */
79 #define spin_unlock(a) /* nothing */
80 #define spin_lock_init(a) /* nothing */
87 #define kmalloc(s, t) malloc(s)
88 #define kzalloc(s, t) zmalloc(s)
89 #define kfree(p) free((void *)p)
90 #define kstrdup(s, t) strdup(s)
92 #define zmalloc(s) calloc(1, s)
99 #define printk(fmt, args...) printf(fmt, ## args)
101 /* MEMORY BARRIERS */
103 #define smp_mb__after_atomic_inc() do {} while(0)
108 #define call_rcu_sched(a,b) b(a); synchronize_rcu()
109 #define rcu_barrier_sched() do {} while(0) /* this nop is ok if call_rcu_sched does a synchronize_rcu() */
110 #define rcu_read_lock_sched_notrace() rcu_read_lock()
111 #define rcu_read_unlock_sched_notrace() rcu_read_unlock()
117 static inline int atomic_dec_and_test(atomic_t
*p
)
123 static inline void atomic_set(atomic_t
*p
, int v
)
128 static inline void atomic_inc(atomic_t
*p
)
133 static int atomic_read(atomic_t
*p
)
138 #define atomic_long_t atomic_t
139 #define atomic_long_set atomic_set
140 #define atomic_long_read atomic_read
144 //#define __xg(x) ((volatile long *)(x))
146 #define cmpxchg(ptr, o, n) \
147 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
148 (unsigned long)(n), sizeof(*(ptr))))
150 //#define local_cmpxchg cmpxchg
151 #define local_cmpxchg(l, o, n) (cmpxchg(&((l)->a.counter), (o), (n)))
153 #define atomic_long_cmpxchg(v, old, new) (cmpxchg(&((v)->counter), (old), (new)))
158 //typedef int local_t;
165 static inline void local_inc(local_t
*l
)
170 static inline void local_set(local_t
*l
, int v
)
175 static inline void local_add(int v
, local_t
*l
)
180 static int local_add_return(int v
, local_t
*l
)
182 return l
->a
.counter
+= v
;
185 static inline int local_read(local_t
*l
)
193 #define ____cacheline_aligned
199 static inline unsigned int hweight32(unsigned int w
)
201 unsigned int res
= w
- ((w
>> 1) & 0x55555555);
202 res
= (res
& 0x33333333) + ((res
>> 2) & 0x33333333);
203 res
= (res
+ (res
>> 4)) & 0x0F0F0F0F;
204 res
= res
+ (res
>> 8);
205 return (res
+ (res
>> 16)) & 0x000000FF;
208 static inline int fls(int x
)
211 //ust// #ifdef CONFIG_X86_CMOV
214 : "=&r" (r
) : "rm" (x
), "rm" (-1));
216 //ust// asm("bsrl %1,%0\n\t"
218 //ust// "movl $-1,%0\n"
219 //ust// "1:" : "=r" (r) : "rm" (x));
224 static __inline__
int get_count_order(unsigned int count
)
228 order
= fls(count
) - 1;
229 if (count
& (count
- 1))
239 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
240 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
241 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
242 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
243 #define PAGE_MASK (PAGE_SIZE-1)
250 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
254 //ust// static inline u64 trace_clock_read64(void)
256 //ust// uint32_t low;
257 //ust// uint32_t high;
258 //ust// uint64_t retval;
259 //ust// __asm__ volatile ("rdtsc\n" : "=a" (low), "=d" (high));
261 //ust// retval = high;
262 //ust// retval <<= 32;
263 //ust// return retval | low;
266 static inline u64
trace_clock_read64(void)
271 gettimeofday(&tv
, NULL
);
274 retval
+= tv
.tv_usec
;
279 static inline u64
trace_clock_frequency(void)
284 static inline u32
trace_clock_freq_scale(void)
292 #define list_add_rcu list_add
293 #define list_for_each_entry_rcu list_for_each_entry
296 #define EXPORT_SYMBOL_GPL(a) /*nothing*/
298 #define smp_processor_id() (-1)
300 #endif /* KERNELCOMPAT_H */
This page took 0.066337 seconds and 3 git commands to generate.