File: bitmap.h

package info (click to toggle)
v4l-utils 1.32.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,276 kB
  • sloc: ansic: 85,528; cpp: 69,473; perl: 11,915; sh: 1,333; python: 883; php: 119; makefile: 39
file content (34 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#ifndef __BITMAP_H__
#define __BITMAP_H__

#define BITS_PER_LONG 64
#define BITS_TO_LONG(n) \
	(((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)


#define DECLARE_BITMAP(name, bits) \
	unsigned long name[BITS_TO_LONG(bits)]

static void inline bitmap_zero(unsigned long *bitmap, int bits)
{
	for (int i = 0; i < BITS_TO_LONG(bits); i++)
		bitmap[i] = 0;
}

static void inline bitmap_fill(unsigned long *bitmap, int bits)
{
	for (int i = 0; i < BITS_TO_LONG(bits); i++)
		bitmap[i] = ~0;
}

#define bitmap_set(b, n) \
	b[n / BITS_PER_LONG] |= 1 << (n % BITS_PER_LONG)

#define bitmap_clear(b, n) \
	b[n / BITS_PER_LONG] &= ~(1 << (n % BITS_PER_LONG))

#define bitmap_test(b, n) \
	(b[n / BITS_PER_LONG] & (1 << (n % BITS_PER_LONG))) != 0

#endif