使用方法

free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE,hint % FSP_EXTENT_SIZE, mtr);
/**********************************************************************//**
Looks for a descriptor bit having the desired value. Starts from hint
and scans upward; at the end of the extent the search is wrapped to
the start of the extent.
@return    bit index of the bit, ULINT_UNDEFINED if not found */
UNIV_INLINE
ulint
xdes_find_bit(
/*==========*/
    xdes_t*    descr,    /*!< in: descriptor */
    ulint    bit,    /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */ // 0 or 1
    ibool    val,    /*!< in: desired bit value */
    ulint    hint,    /*!< in: hint of which bit position would be desirable */
    mtr_t*    mtr)    /*!< in: mtr */
{
    ulint    i;

    ut_ad(descr && mtr);
    ut_ad(val <= TRUE);
    ut_ad(hint < FSP_EXTENT_SIZE);
    ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
    for (i = hint; i < FSP_EXTENT_SIZE; i++) { //宏 #define FSP_EXTENT_SIZE (1 << (20 - UNIV_PAGE_SIZE_SHIFT)) 为1<<(20-14)
        if (val == xdes_get_bit(descr, bit, i, mtr)) {

            return(i);
        }
    }

    ; i < hint; i++) {
        if (val == xdes_get_bit(descr, bit, i, mtr)) {

            return(i);
        }
    }

    return(ULINT_UNDEFINED);
}

/**********************************************************************//**
Gets a descriptor bit of a page.
@return    TRUE if free */
UNIV_INLINE
ibool
xdes_get_bit(
/*=========*/
    const xdes_t*  descr,    /*!< in: descriptor */
    ulint          bit,    /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */ // 0 or 1
    ulint          offset,    /*!< in: page offset within extent: 0 ... FSP_EXTENT_SIZE - 1 */
    mtr_t*         mtr)    /*!< in: mtr */
{
    ulint    index;
    ulint    byte_index;
    ulint    bit_index;

    ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
    ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT));
    ut_ad(offset < FSP_EXTENT_SIZE);

    index = bit + XDES_BITS_PER_PAGE * offset; //#define XDES_BITS_PER_PAGE 2 /* How many bits are there per page */

    byte_index = index / ;
    bit_index = index % ;
    /**     *descr 是 XDES Entry的入口地址     *descr + 24 即XDES Entry中XDES BITMAP的入口地址     *     *#define XDES_BITMAP (FLST_NODE_SIZE + 12)     *#define FLST_NODE_SIZE (2 * FIL_ADDR_SIZE) /* The physical size of a list node in bytes */     *#define FIL_ADDR_SIZE 6 /* address size is 6 bytes */     */
    return(ut_bit_get_nth(mtr_read_ulint(descr + XDES_BITMAP + byte_index,MLOG_1BYTE, mtr),bit_index));
}
/********************************************************//**
Reads 1 - 4 bytes from a file page buffered in the buffer pool.
@return    value read */
UNIV_INTERN
ulint
mtr_read_ulint(
/*===========*/
    const byte*    ptr,    /*!< in: pointer from where to read */
    ulint        type,    /*!< in: MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES */
    mtr_t*        mtr __attribute__((unused)))
                /*!< in: mini-transaction handle */
{
    ut_ad(mtr->state == MTR_ACTIVE);
    ut_ad(mtr_memo_contains_page(mtr, ptr, MTR_MEMO_PAGE_S_FIX)
          || mtr_memo_contains_page(mtr, ptr, MTR_MEMO_PAGE_X_FIX));
    if (type == MLOG_1BYTE) {
        return(mach_read_from_1(ptr));
    } else if (type == MLOG_2BYTES) {
        return(mach_read_from_2(ptr));
    } else {
        ut_ad(type == MLOG_4BYTES);
        return(mach_read_from_4(ptr));
    }
}
/********************************************************//**
The following function is used to fetch data from one byte.
@return    ulint integer, >= 0, < 256 */
UNIV_INLINE
ulint
mach_read_from_1(
/*=============*/
    const byte*    b)    /*!< in: pointer to byte */
{
    ut_ad(b);
    ]));
}
/*****************************************************************//**
Gets the nth bit of a ulint.
@return    TRUE if nth bit is 1; 0th bit is defined to be the least significant */
UNIV_INLINE
ibool
ut_bit_get_nth(
/*===========*/
    ulint    a,    /*!< in: ulint */
    ulint    n)    /*!< in: nth bit requested */
{
    ut_ad(n <  * sizeof(ulint));
#if TRUE != 1
# error "TRUE != 1"
#endif
     & (a >> n));
}
/*****************************************************************//**
Sets the nth bit of a ulint.
@return    the ulint with the bit set as requested */
UNIV_INLINE
ulint
ut_bit_set_nth(
/*===========*/
    ulint    a,    /*!< in: ulint */
    ulint    n,    /*!< in: nth bit requested */
    ibool    val)    /*!< in: value for the bit to set */
{
    ut_ad(n <  * sizeof(ulint));
#if TRUE != 1
# error "TRUE != 1"
#endif
    if (val) {        /**         *n的值此时为 index%8 为 7 ,6 ,5,4,3,2,1,0 来决定属于哪一个         *假设在第5个,1 << 5 的二进制为 100000 最大的1的下标为5         */
         << n) | a);
    } else {
         << n) & a);
    }
}

函数xdes_find_bit的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. CBQW ---分组表单展示

    工作流审核表单后,将表单信息展示页面中. Rest读取展示 展示方式有2 一.              CBQW内容查询, 通过CBQW内容查询.分别通过设置itemstyle和header xsl ...

  2. 安装sinopia-ldap

    背景: 已经安装好sinopia,配置好本地npm源 安装sinopia-ldap: npm install -g sinopia-ldap 配置: 修改sinopia的配置文件config.yaml ...

  3. android 电话拨号器

    电话拨号器(重点)            1.产品经理: 需求分析文档,设计原型图    2.UI工程师: 设计UI界面    3.架构师: 写架构,接口文档    4.码农: 服务端,客户端     ...

  4. tomcat错误信息解决方案【严重:StandardServer.await: create[8005]

    1.独立运行的tomcat.exe没有关闭,关闭tomcat图标并结束掉tomcat进程.(我是这个原因,在开始菜单里找到tomcat,然后stop它) 2.安装了其他的软件占用了8080端口,tom ...

  5. ZOJ 2411 Link Link Look(BFS)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1411 题目大意:连连看,给出每次连线的两个坐标,求能消去多少方块,拐 ...

  6. CIFS与NFS(转)

    1.CIFS Microsoft推出SMB(server message block)后,进一步发展,使其扩展到Internet上,成为common internet file system. CIF ...

  7. Linux – RedHat7 / CentOS 7 忘记root密码修改

    1.(a) 开机出现grub boot loader 开机选项菜单时,立即点击键盘任意鍵,boot loader 会暂停. (b) 按下’e’,编辑选项菜单(c) 移动上下鍵至linux16 核心命令 ...

  8. 控制 WAP 网站上输入框的默认类型

    比如手机号,卡输入框应该默认显示数字键盘,邮箱输入框应该默认显示邮箱键盘.www . c s d n 1 2 3 . com/html/itweb/20130802/36036_36043_36004 ...

  9. WPF中实现根据拼音查找汉字

    1.WPF的一个触摸屏项目,需要输入姓名,但是屏幕不支持汉字输入,使用虚拟键盘不稳定,为了解决该问题特此进行处理. 2.新建一个类转换类,里面初始化一个数组,数组包含拼音,以及拼音下的常用的汉字. 3 ...

  10. MAC 上找不到.bash_profile或者ect/profile该怎么办?

      开发Android的环境要重新在Mac上搭建,结果在配置环境变量时找不到.bash_profile文件.查过很多资料解决方案都很笼统,结果还是在英文网站上找到解决方法. 1. 启动终端Termin ...