[BACK]Return to bitmap.3 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / man / man3

File: [cvs.NetBSD.org] / src / share / man / man3 / bitmap.3 (download)

Revision 1.9, Tue Mar 18 18:20:39 2014 UTC (10 years ago) by riastradh
Branch: MAIN
CVS Tags: yamt-pagecache-base9, tls-maxphys-base, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, netbsd-8-base, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan
Branch point for: netbsd-8
Changes since 1.8: +1 -1 lines

Merge riastradh-drm2 to HEAD.

.\"	$NetBSD: bitmap.3,v 1.9 2014/03/18 18:20:39 riastradh Exp $
.\"
.\" Copyright (c) 2012 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Christos Zoulas.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd December 6, 2012
.Dt BITMAP 3
.Os
.Sh NAME
.Nm __BITMAP_CLR ,
.Nm __BITMAP_ISSET ,
.Nm __BITMAP_SET ,
.Nm __BITMAP_SIZE ,
.Nm __BITMAP_TYPE ,
.Nm __BITMAP_ZERO
.Nd bitmap manipulation macros
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In sys/bitops.h
.Fn __BITMAP_CLR "int bit" "type *bitmap"
.Fn __BITMAP_ISSET "int bit" "type *bitmap"
.Fn __BITMAP_SET "int bit" "type *bitmap"
.Fn __BITMAP_SIZE "type" "int nbits"
.Fn __BITMAP_TYPE "name" "type" "int nbits"
.Fn __BITMAP_ZERO "type *bitmap"
.Sh DESCRIPTION
The supplied macros are similar to the
.Xr select 2
.Fn FD_SET
family, to the
.Xr setbit 9 ,
macros and the
.Xr bitstring 3
library.
They are different from
.Fn FD_SET
because they are designed to handle multiple sized bitmaps at the same time,
and they can be of any integral type.
They are different from
.Xr setbit 9
because they can operate on different integral types, not just on bytes.
They are different from
.Xr bitstring 3
because they are just macros, they don't allocate memory or use code,
and they can be used in both kernel and userland.
.Pp
The following macros are provided for manipulating creating and manipulating
bitmaps:
.Pp
.Fn __BITMAP_CLR bit bitmap
removes the given
.Fa bit
from the
.Fa bitmap .
.Pp
.Fn __BITMAP_ISSET bit bitmap
is non-zero if
.Fa bit
is a member of
.Fa bitmap ,
zero otherwise.
.Pp
.Fn __BITMAP_SET bit bitmap
Sets the given
.Fa bit
in the
.Fa bitmap .
.Pp
.Fn __BITMAP_SIZE type nbits
Returns the number of elements would be required of the given
.Fa type
to hold
.Fa nbits .
.Pp
.Fn __BITMAP_TYPE name type nbits
Declares the properly sized bitmap structure
of the given
.Fa type
that holds
.Fa nbits
and is named
.Fa name .
.Pp
.Fn __BITMAP_ZERO bit bitmap
initializes a descriptor set pointed to by
.Fa bitmap
to the null set.
.Pp
The behavior of these macros is undefined for negative
bit values or ones greater than the number of bits the bitmap can hold.
.Sh EXAMPLES
.Bd -literal
#include \*[Lt]sys/bitops.h\*[Gt]

int
main(int argc, char **argv)
{
	__BITMAP_TYPE(, uint32_t, 5000) bitmap;

	/* Initialize the read set to null */
	__BITMAP_ZERO(\*[Am]bitmap);

	/* Set bit 1 */
	__BITMAP_SET(1, \*[Am]bitmap);

	for (size_t i = 0; i \*[Lt] 5000; i++) {
		if (__BITMAP_ISSET(i, \*[Am]bitmap)) {
			/* Should just print 1 */
			printf("Bit %zu is set\en", i);
			__BITMAP_CLR(i, \*[Am]bitmap);
		}
		break;
	}
	return 0;
}
.Ed
.Sh SEE ALSO
.Xr select 2 ,
.Xr bitops 3 ,
.Xr bitstring 3 ,
.Xr setbit 9
.Sh HISTORY
The
.Fn __BITMAP_*
macros appeared in
.Nx 7.0 .