bitmap.h File Reference

Bitmaps for multicast downloads. More...

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  bitmap
 A bitmap. More...

Defines

#define BITMAP_BLKSIZE   ( sizeof ( bitmap_block_t ) * 8 )
 Size of a block of bits (in bits).
#define BITMAP_INDEX(bit)   ( (bit) / BITMAP_BLKSIZE )
 Block index within bitmap.
#define BITMAP_MASK(bit)   ( 1 << ( (bit) % BITMAP_BLKSIZE ) )
 Block mask within bitmap.

Typedefs

typedef unsigned long bitmap_block_t
 A single block of bits within a bitmap.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int bitmap_resize (struct bitmap *bitmap, unsigned int new_length)
 Resize bitmap.
int bitmap_test (struct bitmap *bitmap, unsigned int bit)
 Test bit in bitmap.
void bitmap_set (struct bitmap *bitmap, unsigned int bit)
 Set bit in bitmap.
static void bitmap_free (struct bitmap *bitmap)
 Free bitmap resources.
static unsigned int bitmap_first_gap (struct bitmap *bitmap)
 Get first gap within bitmap.
static int bitmap_full (struct bitmap *bitmap)
 Check to see if bitmap is full.


Detailed Description

Bitmaps for multicast downloads.

Definition in file bitmap.h.


Define Documentation

#define BITMAP_BLKSIZE   ( sizeof ( bitmap_block_t ) * 8 )

Size of a block of bits (in bits).

Definition at line 20 of file bitmap.h.

Referenced by bitmap_resize().

#define BITMAP_INDEX ( bit   )     ( (bit) / BITMAP_BLKSIZE )

Block index within bitmap.

Parameters:
bit Bit index
Return values:
index Block index

Definition at line 28 of file bitmap.h.

Referenced by bitmap_resize(), bitmap_set(), and bitmap_test().

#define BITMAP_MASK ( bit   )     ( 1 << ( (bit) % BITMAP_BLKSIZE ) )

Block mask within bitmap.

Parameters:
bit Bit index
Return values:
mask Block mask

Definition at line 36 of file bitmap.h.

Referenced by bitmap_set(), and bitmap_test().


Typedef Documentation

typedef unsigned long bitmap_block_t

A single block of bits within a bitmap.

Definition at line 17 of file bitmap.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int bitmap_resize ( struct bitmap bitmap,
unsigned int  new_length 
)

Resize bitmap.

Parameters:
bitmap Bitmap
new_length New length of bitmap, in bits
Return values:
rc Return status code

Definition at line 37 of file bitmap.c.

References BITMAP_BLKSIZE, BITMAP_INDEX, bitmap::blocks, DBGC, ENOMEM, bitmap::length, and realloc().

Referenced by slam_open(), slam_pull_header(), and tftp_presize().

00037                                                                      {
00038         unsigned int old_num_blocks;
00039         unsigned int new_num_blocks;
00040         size_t new_size;
00041         bitmap_block_t *new_blocks;
00042 
00043         old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
00044         new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );
00045 
00046         if ( old_num_blocks != new_num_blocks ) {
00047                 new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
00048                 new_blocks = realloc ( bitmap->blocks, new_size );
00049                 if ( ! new_blocks ) {
00050                         DBGC ( bitmap, "Bitmap %p could not resize to %d "
00051                                "bits\n", bitmap, new_length );
00052                         return -ENOMEM;
00053                 }
00054                 bitmap->blocks = new_blocks;
00055         }
00056         bitmap->length = new_length;
00057 
00058         while ( old_num_blocks < new_num_blocks ) {
00059                 bitmap->blocks[old_num_blocks++] = 0;
00060         }
00061 
00062         DBGC ( bitmap, "Bitmap %p resized to %d bits\n", bitmap, new_length );
00063         return 0;
00064 }

int bitmap_test ( struct bitmap bitmap,
unsigned int  bit 
)

Test bit in bitmap.

Parameters:
bitmap Bitmap
bit Bit index
Return values:
is_set Bit is set

Definition at line 73 of file bitmap.c.

References BITMAP_INDEX, BITMAP_MASK, bitmap::blocks, index, and bitmap::length.

Referenced by bitmap_set(), slam_mc_socket_deliver(), and slam_tx_nack().

00073                                                             {
00074         unsigned int index = BITMAP_INDEX ( bit );
00075         bitmap_block_t mask = BITMAP_MASK ( bit );
00076 
00077         if ( bit >= bitmap->length )
00078                 return 0;
00079         return ( bitmap->blocks[index] & mask );
00080 }

void bitmap_set ( struct bitmap bitmap,
unsigned int  bit 
)

Set bit in bitmap.

Parameters:
bitmap Bitmap
bit Bit index

Definition at line 88 of file bitmap.c.

References BITMAP_INDEX, BITMAP_MASK, bitmap_test(), bitmap::blocks, DBGC, bitmap::first_gap, and index.

Referenced by slam_mc_socket_deliver(), and tftp_rx_data().

00088                                                             {
00089         unsigned int index = BITMAP_INDEX ( bit );
00090         bitmap_block_t mask = BITMAP_MASK ( bit );
00091 
00092         DBGC ( bitmap, "Bitmap %p setting bit %d\n", bitmap, bit );
00093 
00094         /* Update bitmap */
00095         bitmap->blocks[index] |= mask;
00096 
00097         /* Update first gap counter */
00098         while ( bitmap_test ( bitmap, bitmap->first_gap ) ) {
00099                 bitmap->first_gap++;
00100         }
00101 }

static void bitmap_free ( struct bitmap bitmap  )  [inline, static]

Free bitmap resources.

Parameters:
bitmap Bitmap

Definition at line 57 of file bitmap.h.

References bitmap::blocks, and free().

Referenced by slam_free(), slam_pull_header(), tftp_free(), and tftp_timer_expired().

00057                                                          {
00058         free ( bitmap->blocks );
00059 }

static unsigned int bitmap_first_gap ( struct bitmap bitmap  )  [inline, static]

Get first gap within bitmap.

Parameters:
bitmap Bitmap
Return values:
first_gap First gap
The first gap is the first unset bit within the bitmap.

Definition at line 69 of file bitmap.h.

References bitmap::first_gap.

Referenced by slam_tx_nack(), tftp_rx_data(), and tftp_send_ack().

00069                                                                       {
00070         return bitmap->first_gap;
00071 }

static int bitmap_full ( struct bitmap bitmap  )  [inline, static]

Check to see if bitmap is full.

Parameters:
bitmap Bitmap
Return values:
is_full Bitmap is full
The bitmap is full if it has no gaps (i.e. no unset bits).

Definition at line 81 of file bitmap.h.

References bitmap::first_gap, and bitmap::length.

Referenced by slam_mc_socket_deliver(), and tftp_rx_data().

00081                                                         {
00082         return ( bitmap->first_gap == bitmap->length );
00083 }


Generated on Tue Apr 6 20:01:48 2010 for gPXE by  doxygen 1.5.7.1