多层位图查表法
具体的实现如下:
z的每一个bit对应着1个y。也就是一共对应8个y。
y的每一个bit对应着一个x,也就是一共对应着8*8个x。
每一个x刚好也就对应着8个任务优先级号。这样就能够通过x,y,z设置优先级。
因此可以采用下面的形式定义一个结构体:
#ifndef __HIGH_BITMAP_H_H__
#define __HIGH_BITMAP_H_H__
#define LENGTH_HIGHLAYER 8
#define LENGTH_BYTE 8
typedef unsigned char Byte;
typedef struct
{
Byte high_Layer;
Byte mid_Layer[LENGTH_HIGHLAYER];
Byte low_Layer[LENGTH_HIGHLAYER*LENGTH_BYTE];
}BitMaps;
#ifdef __cplusplus
extern "C"
{
#endif
void inital_bitmap(BitMaps *bitmap);
void set_bitmap(BitMaps *bitmap,int prio);
int calculate_high_prio(BitMaps *bitmap);
#ifdef __cplusplus
}
#endif
#endif
基本的操作函数如下:
#include"high_bitmap.h"
#include
int const OSUnMapTbl[256] = {
0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x00 to 0x0F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x10 to 0x1F */
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x20 to 0x2F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x30 to 0x3F */
6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x40 to 0x4F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x50 to 0x5F */
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x60 to 0x6F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x70 to 0x7F */
7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x80 to 0x8F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x90 to 0x9F */
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0xA0 to 0xAF */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0xB0 to 0xBF */
6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0xC0 to 0xCF */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0xD0 to 0xDF */
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0xE0 to 0xEF */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 /* 0xF0 to 0xFF */
};
void inital_bitmap(BitMaps *bitmap)
{
int i = 0;
if(NULL == bitmap)
{
return ;
}
bitmap->high_Layer = 0x00;
for(; i < sizeof(bitmap->mid_Layer); ++ i)
{
bitmap->mid_Layer[i] = 0x00;
}
for (i = 0; i < sizeof(bitmap->low_Layer); ++ i)
{
bitmap->low_Layer[i] = 0x00;
}
}
void set_bitmap(BitMaps *bitmap,int prio)
{
int x,y,z;
if(NULL == bitmap || prio >= 512)
{
return ;
}
z = (prio >> 6)& 0x7; x = prio & 0x7; int calculate_high_prio(BitMaps *bitmap) if(NULL == bitmap) z = OSUnMapTbl[bitmap->high_Layer]; z = (z < 6) + (y < 3) + x; return z; 这种分层的实现方式能够方便的解决位图中多种可能性问题,通过分层可以使得各个变量x,y,z都能过使
bitmap->high_Layer |= 1
y = (prio >> 3) & 0x7;
bitmap->mid_Layer[z] |= 1
bitmap->low_Layer[z*8+y] |= 1
{
int x,y,z;
{
return -1;
}
y = OSUnMapTbl[bitmap->mid_Layer[z]];
x = OSUnMapTbl[bitmap->low_Layer[(z < 3)+y]];
}
多层位图查表法操作系 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)