我在哪里可以找到 atomicity.h 中的函数定义? [英] Where can I find the function definition in atomicity.h?

查看:36
本文介绍了我在哪里可以找到 atomicity.h 中的函数定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

atomicity.h 是 c++ stl 的一部分.在它的源文件中,它声明了两个关于原子操作的函数.这是整个源代码.我在哪里可以找到这些函数的定义.我在 stl 源代码中没有找到.

atomicity.h is part of c++ stl. In its source file, it declares two functions about atomic operation. Here is the whole source code. Where can I find the definition of these functions. I don't find it in stl source code.

#ifndef _GLIBCXX_ATOMICITY_H
#define _GLIBCXX_ATOMICITY_H    1
#include <bits/atomic_word.h>
namespace __gnu_cxx
{
  _Atomic_word 
  __attribute__ ((__unused__))
  __exchange_and_add(volatile _Atomic_word* __mem, int __val); 

  void
  __attribute__ ((__unused__))
  __atomic_add(volatile _Atomic_word* __mem, int __val); 
} // namespace __gnu_cxx
#endif 

推荐答案

它们由 libstdc++ 定义,具体取决于您的 GCC 安装,但对于最近的 GCC 版本,很容易找到:

They're defined by libstdc++, where exactly depends on your GCC installation, but for recent GCC releases it's easy to find out:

$ cat t.cc
#include <ext/atomicity.h>

int main()
{
  int i=0;
  __gnu_cxx::__exchange_and_add(&i, 0);
}
$ g++ -g t.cc
$ gdb -quiet ./a.out
Reading symbols from /dev/shm/a.out...done.
(gdb) start 
Temporary breakpoint 1 at 0x8570: file t.cc, line 5.
Starting program: /dev/shm/a.out 

Temporary breakpoint 1, main () at t.cc:5
5     int i=0;
Missing separate debuginfos, use: debuginfo-install glibc-2.16-33.fc18.armv7hl libgcc-4.7.2-8.fc18.armv7hl libstdc++-4.7.2-8.fc18.armv7hl
(gdb) n
6     __gnu_cxx::__exchange_and_add(&i, 0);
(gdb) step
__gnu_cxx::__exchange_and_add (__mem=0x7efff13c, __val=0)
    at /usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2/ext/atomicity.h:48
48    { return __atomic_fetch_add(__mem, __val, __ATOMIC_ACQ_REL); }
(gdb) 

GDB 告诉你定义在哪里,在我的例子中它在 /usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2/ext/atomicity.h 即它们在 atomicity.h

GDB tells you where the definition is, in my case it's in /usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2/ext/atomicity.h i.e. they're defined inline in atomicity.h

从您发布的代码看来,您使用的是 GCC 4.1(相当旧),在这种情况下,函数是在库中定义的,而不是在头文件中.代码是特定于 CPU 的,因此它再次取决于您的 GCC 安装.代码可以在 GCC 源代码中找到,i386 实现在文件 libstdc++-v3/config/cpu/i386/atomicity.h 和实现i486 及更高版本位于 libstdc++-v3/config/cpu/i486/atomicity.h

From the code you posted it looks like you're using GCC 4.1 (which is pretty old) in which case the functions are defined in the library, not in a header. The code is CPU-specific, so again it depends on your GCC installation. The code can be found in the GCC sources, the i386 implementation is in the file libstdc++-v3/config/cpu/i386/atomicity.h and the implementation for i486 and later is in libstdc++-v3/config/cpu/i486/atomicity.h

这篇关于我在哪里可以找到 atomicity.h 中的函数定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆