/*******************************************************************//**
Does a synchronous read operation in Posix.
@return    number of bytes read, -1 if error */
static
ssize_t
os_file_pread(
/*==========*/
    os_file_t    file,    /*!< in: handle to a file */
    void*        buf,    /*!< in: buffer where to read */
    ulint        n,    /*!< in: number of bytes to read */
    ulint        offset,    /*!< in: least significant 32 bits of file
                offset from where to read */
    ulint        offset_high) /*!< in: most significant 32 bits of
                offset */
{
    off_t    offs;
#if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
    ssize_t    n_bytes;
#endif /* HAVE_PREAD && !HAVE_BROKEN_PREAD */

    ut_a((offset & 0xFFFFFFFFUL) == offset);

    /* If off_t is > 4 bytes in size, then we assume we can pass a
    64-bit address */

    ) {
        offs = (off_t)offset + (((off_t)offset_high) << );

    } else {
        offs = (off_t)offset;

        ) {
            fprintf(stderr,
                "InnoDB: Error: file read at offset > 4 GB\n");
        }
    }

    os_n_file_reads++;

#if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
    os_mutex_enter(os_file_count_mutex);
    os_file_n_pending_preads++;
    os_n_pending_reads++;
    os_mutex_exit(os_file_count_mutex);

    n_bytes = pread(file, buf, (ssize_t)n, offs);

    os_mutex_enter(os_file_count_mutex);
    os_file_n_pending_preads--;
    os_n_pending_reads--;
    os_mutex_exit(os_file_count_mutex);

    return(n_bytes);
#else
    {
        off_t    ret_offset;
        ssize_t    ret;
#ifndef UNIV_HOTBACKUP
        ulint    i;
#endif /* !UNIV_HOTBACKUP */

        os_mutex_enter(os_file_count_mutex);
        os_n_pending_reads++;
        os_mutex_exit(os_file_count_mutex);

#ifndef UNIV_HOTBACKUP
        /* Protect the seek / read operation with a mutex */
        i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES;

        os_mutex_enter(os_file_seek_mutexes[i]);
#endif /* !UNIV_HOTBACKUP */

        ret_offset = lseek(file, offs, SEEK_SET);

        ) {
            ret = -;
        } else {
            ret = read(file, buf, (ssize_t)n);
        }

#ifndef UNIV_HOTBACKUP
        os_mutex_exit(os_file_seek_mutexes[i]);
#endif /* !UNIV_HOTBACKUP */

        os_mutex_enter(os_file_count_mutex);
        os_n_pending_reads--;
        os_mutex_exit(os_file_count_mutex);

        return(ret);
    }
#endif
}

函数os_file_pread的更多相关文章

  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. SQL Server数据库事务日志序列号(LSN)介绍

    原文:http://blog.csdn.net/tjvictor/article/details/5251463     日志序列编号(LSN)是事务日志里面每条记录的编号. 当你执行一次备份时,一些 ...

  2. 用MSBuild和Jenkins搭建持续集成环境 - 转

    http://www.infoq.com/cn/articles/MSBuild-1 http://www.infoq.com/cn/articles/MSBuild-2 MSBuild是在.NET ...

  3. Win7超级终端查看单片机printf输出

    问题描述:     编写单片机C程序时,经常会用到printf输出信息进行查看,如何查看printf输出? 问题解决:     (1)编写单片机C程序     ucos是一个实时多任务操作系统,以上是 ...

  4. Castle 开发系统文章

    转: http://www.cnblogs.com/Jebel/archive/2008/06/24/1228766.html

  5. StringTokenizer用法

    import java.util.StringTokenizer; public class StringTokenizerTest { public static void main(String[ ...

  6. Javascript操作元素属性方法总结

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. 青鸟 王云鹏老师写的SqlHelper 泛型方法,反射,支持实体类

    1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: ...

  8. Thread的第四天学习

    线程通信 wait notify synchronized + 同对象 才可 互斥 锁不是放在线程上的,放在共享资源内部的. wait 线程等待 notify 线程唤醒

  9. C++ Primer笔记整理

    1. 迭代器:迭代器是一种对象,它可以看做是游标,用来遍历标准模板库中的部分或者全部元素. 每个迭代器指向容器中确定的地址,此外,迭代器还提供一些基本操作符:*.++.==.!=.=. 2. 模板:是 ...

  10. python 判断操作系统类型

    #!/bin/python # import platform def TestPlatform(): print ("----------Operation System--------- ...