当前位置: 首页>>代码示例>>C++>>正文


C++ mozilla::ThreadLocal类代码示例

本文整理汇总了C++中mozilla::ThreadLocal的典型用法代码示例。如果您正苦于以下问题:C++ ThreadLocal类的具体用法?C++ ThreadLocal怎么用?C++ ThreadLocal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ThreadLocal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PR_Now

namespace tasktracer {

static mozilla::ThreadLocal<TraceInfo*> sTraceInfoTLS;
static mozilla::StaticMutex sMutex;

// The generation of TraceInfo. It will be > 0 if the Task Tracer is started and
// <= 0 if stopped.
static mozilla::Atomic<bool> sStarted;
static nsTArray<nsAutoPtr<TraceInfo>>* sTraceInfos = nullptr;
static PRTime sStartTime;

static const char sJSLabelPrefix[] = "#tt#";

namespace {

static PRTime
GetTimestamp()
{
  return PR_Now() / 1000;
}

static TraceInfo*
AllocTraceInfo(int aTid)
{
  StaticMutexAutoLock lock(sMutex);

  nsAutoPtr<TraceInfo>* info = sTraceInfos->AppendElement(
                                 new TraceInfo(aTid));

  return info->get();
}

static void
SaveCurTraceInfo()
{
  TraceInfo* info = GetOrCreateTraceInfo();
  ENSURE_TRUE_VOID(info);

  info->mSavedCurTraceSourceId = info->mCurTraceSourceId;
  info->mSavedCurTraceSourceType = info->mCurTraceSourceType;
  info->mSavedCurTaskId = info->mCurTaskId;
}

static void
RestoreCurTraceInfo()
{
  TraceInfo* info = GetOrCreateTraceInfo();
  ENSURE_TRUE_VOID(info);

  info->mCurTraceSourceId = info->mSavedCurTraceSourceId;
  info->mCurTraceSourceType = info->mSavedCurTraceSourceType;
  info->mCurTaskId = info->mSavedCurTaskId;
}

static void
CreateSourceEvent(SourceEventType aType)
{
  // Save the currently traced source event info.
  SaveCurTraceInfo();

  // Create a new unique task id.
  uint64_t newId = GenNewUniqueTaskId();
  TraceInfo* info = GetOrCreateTraceInfo();
  ENSURE_TRUE_VOID(info);

  info->mCurTraceSourceId = newId;
  info->mCurTraceSourceType = aType;
  info->mCurTaskId = newId;

  int* namePtr;
#define SOURCE_EVENT_NAME(type)         \
  case SourceEventType::type:           \
  {                                     \
    static int CreateSourceEvent##type; \
    namePtr = &CreateSourceEvent##type; \
    break;                              \
  }

  switch (aType) {
#include "SourceEventTypeMap.h"
    default:
      MOZ_CRASH("Unknown SourceEvent.");
  };
#undef CREATE_SOURCE_EVENT_NAME

  // Log a fake dispatch and start for this source event.
  LogDispatch(newId, newId, newId, aType);
  LogVirtualTablePtr(newId, newId, namePtr);
  LogBegin(newId, newId);
}

static void
DestroySourceEvent()
{
  // Log a fake end for this source event.
  TraceInfo* info = GetOrCreateTraceInfo();
  ENSURE_TRUE_VOID(info);

  LogEnd(info->mCurTraceSourceId, info->mCurTraceSourceId);

//.........这里部分代码省略.........
开发者ID:bolt-dev,项目名称:gecko-dev,代码行数:101,代码来源:GeckoTaskTracer.cpp

示例2: Push

namespace dom {

class ScriptSettingsStack;
static mozilla::ThreadLocal<ScriptSettingsStack*> sScriptSettingsTLS;

ScriptSettingsStackEntry ScriptSettingsStackEntry::NoJSAPISingleton;

class ScriptSettingsStack {
public:
  static ScriptSettingsStack& Ref() {
    return *sScriptSettingsTLS.get();
  }
  ScriptSettingsStack() {};

  void Push(ScriptSettingsStackEntry* aSettings) {
    // The bottom-most entry must always be a candidate entry point.
    MOZ_ASSERT_IF(mStack.Length() == 0 || mStack.LastElement()->NoJSAPI(),
                  aSettings->mIsCandidateEntryPoint);
    mStack.AppendElement(aSettings);
  }

  void PushNoJSAPI() {
    mStack.AppendElement(&ScriptSettingsStackEntry::NoJSAPISingleton);
  }

  void Pop() {
    MOZ_ASSERT(mStack.Length() > 0);
    mStack.RemoveElementAt(mStack.Length() - 1);
  }

  ScriptSettingsStackEntry* Incumbent() {
    if (!mStack.Length()) {
      return nullptr;
    }
    return mStack.LastElement();
  }

  nsIGlobalObject* IncumbentGlobal() {
    ScriptSettingsStackEntry *entry = Incumbent();
    return entry ? entry->mGlobalObject : nullptr;
  }

  ScriptSettingsStackEntry* EntryPoint() {
    if (!mStack.Length())
      return nullptr;
    for (int i = mStack.Length() - 1; i >= 0; --i) {
      if (mStack[i]->mIsCandidateEntryPoint) {
        return mStack[i];
      }
    }
    MOZ_CRASH("Non-empty stack should always have an entry point");
  }

  nsIGlobalObject* EntryGlobal() {
    ScriptSettingsStackEntry *entry = EntryPoint();
    return entry ? entry->mGlobalObject : nullptr;
  }

private:
  // These pointers are caller-owned.
  nsTArray<ScriptSettingsStackEntry*> mStack;
};

void
InitScriptSettings()
{
  if (!sScriptSettingsTLS.initialized()) {
    bool success = sScriptSettingsTLS.init();
    if (!success) {
      MOZ_CRASH();
    }
  }

  ScriptSettingsStack* ptr = new ScriptSettingsStack();
  sScriptSettingsTLS.set(ptr);
}

void DestroyScriptSettings()
{
  ScriptSettingsStack* ptr = sScriptSettingsTLS.get();
  MOZ_ASSERT(ptr);
  sScriptSettingsTLS.set(nullptr);
  delete ptr;
}

// This mostly gets the entry global, but doesn't entirely match the spec in
// certain edge cases. It's good enough for some purposes, but not others. If
// you want to call this function, ping bholley and describe your use-case.
nsIGlobalObject*
BrokenGetEntryGlobal()
{
  // We need the current JSContext in order to check the JS for
  // scripted frames that may have appeared since anyone last
  // manipulated the stack. If it's null, that means that there
  // must be no entry global on the stack.
  JSContext *cx = nsContentUtils::GetCurrentJSContextForThread();
  if (!cx) {
    MOZ_ASSERT(ScriptSettingsStack::Ref().EntryGlobal() == nullptr);
    return nullptr;
  }
//.........这里部分代码省略.........
开发者ID:rperez08,项目名称:gecko-dev,代码行数:101,代码来源:ScriptSettings.cpp

示例3:

bool
NS_IsMainThread()
{
  return sTLSIsMainThread.get();
}
开发者ID:Acidburn0zzz,项目名称:tor-browser,代码行数:5,代码来源:nsThreadManager.cpp

示例4: glDeleteProgram_mozilla

GrGLvoid glDeleteProgram_mozilla(GrGLuint program)
{
    return sGLContext.get()->fDeleteProgram(program);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例5: glDeleteShader_mozilla

GrGLvoid glDeleteShader_mozilla(GrGLuint shader)
{
    return sGLContext.get()->fDeleteShader(shader);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例6: glCreateProgram_mozilla

GrGLuint glCreateProgram_mozilla(void)
{
    return sGLContext.get()->fCreateProgram();
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例7: glCullFace_mozilla

GrGLvoid glCullFace_mozilla(GrGLenum mode)
{
    return sGLContext.get()->fCullFace(mode);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例8: glClearStencil_mozilla

GrGLvoid glClearStencil_mozilla(GrGLint s)
{
    return sGLContext.get()->fClearStencil(s);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例9: glCompileShader_mozilla

GrGLvoid glCompileShader_mozilla(GrGLuint shader)
{
    return sGLContext.get()->fCompileShader(shader);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例10: FreeTraceInfo

void FreeTraceInfo()
{
  FreeTraceInfo(sTraceInfoTLS.get());
}
开发者ID:bolt-dev,项目名称:gecko-dev,代码行数:4,代码来源:GeckoTaskTracer.cpp

示例11: Top

 static ScriptSettingsStackEntry* Top() {
   return sScriptSettingsTLS.get();
 }
开发者ID:dirkschulze,项目名称:gecko-dev,代码行数:3,代码来源:ScriptSettings.cpp

示例12: Pop

 static void Pop(ScriptSettingsStackEntry *aEntry) {
   MOZ_ASSERT(aEntry == Top());
   sScriptSettingsTLS.set(aEntry->mOlder);
 }
开发者ID:dirkschulze,项目名称:gecko-dev,代码行数:4,代码来源:ScriptSettings.cpp

示例13:

bool
ScriptSettingsInitialized()
{
  return sScriptSettingsTLS.initialized();
}
开发者ID:dirkschulze,项目名称:gecko-dev,代码行数:5,代码来源:ScriptSettings.cpp

示例14: glClear_mozilla

GrGLvoid glClear_mozilla(GrGLbitfield mask)
{
    return sGLContext.get()->fClear(mask);
}
开发者ID:zoodles,项目名称:zoodlesgamesplayer,代码行数:4,代码来源:SkiaGLGlue.cpp

示例15: Run

  NS_IMETHOD Run() {
    TableTicker *t = tlsTicker.get();

    // Pause the profiler during saving.
    // This will prevent us from recording sampling
    // regarding profile saving. This will also
    // prevent bugs caused by the circular buffer not
    // being thread safe. Bug 750989.
    t->SetPaused(true);

    // Get file path
    nsCOMPtr<nsIFile> tmpFile;
    nsCAutoString tmpPath;
    if (NS_FAILED(NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpFile)))) {
      LOG("Failed to find temporary directory.");
      return NS_ERROR_FAILURE;
    }
    tmpPath.AppendPrintf("profile_%i_%i.txt", XRE_GetProcessType(), getpid());

    nsresult rv = tmpFile->AppendNative(tmpPath);
    if (NS_FAILED(rv))
      return rv;

    rv = tmpFile->GetNativePath(tmpPath);
    if (NS_FAILED(rv))
      return rv;

    // Create a JSContext to run a JSObjectBuilder :(
    // Based on XPCShellEnvironment
    JSRuntime *rt;
    JSContext *cx;
    nsCOMPtr<nsIJSRuntimeService> rtsvc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
    if (!rtsvc || NS_FAILED(rtsvc->GetRuntime(&rt)) || !rt) {
      LOG("failed to get RuntimeService");
      return NS_ERROR_FAILURE;;
    }

    cx = JS_NewContext(rt, 8192);
    if (!cx) {
      LOG("Failed to get context");
      return NS_ERROR_FAILURE;
    }

    {
      JSAutoRequest ar(cx);
      static JSClass c = {
          "global", JSCLASS_GLOBAL_FLAGS,
          JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
          JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub
      };
      JSObject *obj = JS_NewGlobalObject(cx, &c, NULL);

      std::ofstream stream;
      stream.open(tmpPath.get());
      // Pause the profiler during saving.
      // This will prevent us from recording sampling
      // regarding profile saving. This will also
      // prevent bugs caused by the circular buffer not
      // being thread safe. Bug 750989.
      t->SetPaused(true);
      if (stream.is_open()) {
        JSAutoEnterCompartment autoComp;
        if (autoComp.enter(cx, obj)) {
          JSObject* profileObj = mozilla_sampler_get_profile_data(cx);
          jsval val = OBJECT_TO_JSVAL(profileObj);
          JS_Stringify(cx, &val, nsnull, JSVAL_NULL, WriteCallback, &stream);
        } else {
          LOG("Failed to enter compartment");
        }
        stream.close();
        LOGF("Saved to %s", tmpPath.get());
      } else {
        LOG("Fail to open profile log file.");
      }
    }
    JS_EndRequest(cx);
    JS_DestroyContext(cx);

    t->SetPaused(false);

    return NS_OK;
  }
开发者ID:lofter2011,项目名称:Icefox,代码行数:82,代码来源:TableTicker.cpp


注:本文中的mozilla::ThreadLocal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。