proxygen
folly::Getcpu Struct Reference

#include <CacheLocality.h>

Public Types

typedef int(* Func) (unsigned *cpu, unsigned *node, void *unused)
 Function pointer to a function with the same signature as getcpu(2). More...
 

Static Public Member Functions

static Func resolveVdsoFunc ()
 

Detailed Description

Knows how to derive a function pointer to the VDSO implementation of getcpu(2), if available

Definition at line 122 of file CacheLocality.h.

Member Typedef Documentation

typedef int(* folly::Getcpu::Func) (unsigned *cpu, unsigned *node, void *unused)

Function pointer to a function with the same signature as getcpu(2).

Definition at line 124 of file CacheLocality.h.

Member Function Documentation

Getcpu::Func folly::Getcpu::resolveVdsoFunc ( )
static

Returns a pointer to the VDSO implementation of getcpu(2), if available, or nullptr otherwise. This function may be quite expensive, be sure to cache the result.

Definition at line 208 of file CacheLocality.cpp.

References h.

Referenced by folly::AccessSpreader< Atom >::pickGetcpuFunc(), and TEST().

208  {
209 #if !FOLLY_HAVE_LINUX_VDSO
210  return nullptr;
211 #else
212  void* h = dlopen("linux-vdso.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
213  if (h == nullptr) {
214  return nullptr;
215  }
216 
217  auto func = Getcpu::Func(dlsym(h, "__vdso_getcpu"));
218  if (func == nullptr) {
219  // technically a null result could either be a failure or a successful
220  // lookup of a symbol with the null value, but the second can't actually
221  // happen for this symbol. No point holding the handle forever if
222  // we don't need the code
223  dlclose(h);
224  }
225 
226  return func;
227 #endif
228 }
*than *hazptr_holder h
Definition: Hazptr.h:116
int(* Func)(unsigned *cpu, unsigned *node, void *unused)
Function pointer to a function with the same signature as getcpu(2).

The documentation for this struct was generated from the following files: