本文整理汇总了C++中ThreadContext类的典型用法代码示例。如果您正苦于以下问题:C++ ThreadContext类的具体用法?C++ ThreadContext怎么用?C++ ThreadContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ThreadContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: worker
static void* attribute_align_arg worker(void *v)
{
AVCodecContext *avctx = v;
ThreadContext *c = avctx->thread_opaque;
int our_job = c->job_count;
int thread_count = avctx->thread_count;
int self_id;
pthread_mutex_lock(&c->current_job_lock);
self_id = c->current_job++;
for (;;){
while (our_job >= c->job_count) {
if (c->current_job == thread_count + c->job_count)
pthread_cond_signal(&c->last_job_cond);
pthread_cond_wait(&c->current_job_cond, &c->current_job_lock);
our_job = self_id;
if (c->done) {
pthread_mutex_unlock(&c->current_job_lock);
return NULL;
}
}
pthread_mutex_unlock(&c->current_job_lock);
c->rets[our_job%c->rets_count] = c->func ? c->func(avctx, (char*)c->args + our_job*c->job_size):
c->func2(avctx, c->args, our_job, self_id);
pthread_mutex_lock(&c->current_job_lock);
our_job = c->current_job++;
}
}
示例2: Assert
BOOL DynamicObject::CallToPrimitiveFunction(Var toPrimitiveFunction, PropertyId propertyId, Var* result, ScriptContext * requestContext)
{
if (JavascriptConversion::IsCallable(toPrimitiveFunction))
{
RecyclableObject* toStringFunction = RecyclableObject::FromVar(toPrimitiveFunction);
ThreadContext * threadContext = requestContext->GetThreadContext();
Var aResult = threadContext->ExecuteImplicitCall(toStringFunction, ImplicitCall_ToPrimitive, [=]() -> Js::Var
{
// Stack object should have a pre-op bail on implicit call. We shouldn't see them here.
Assert(!ThreadContext::IsOnStack(this) || threadContext->HasNoSideEffect(toStringFunction));
return toStringFunction->GetEntryPoint()(toStringFunction, CallInfo(CallFlags_Value, 1), this);
});
if (!aResult)
{
// There was an implicit call and implicit calls are disabled. This would typically cause a bailout.
Assert(threadContext->IsDisableImplicitCall());
*result = requestContext->GetLibrary()->GetNull();
return true;
}
if (JavascriptOperators::GetTypeId(aResult) <= TypeIds_LastToPrimitiveType)
{
*result = aResult;
return true;
}
}
return false;
}
示例3: ThreadContext
ThreadContext& DebugThreadManager::StartThread(const Common::StackPreparator& stack, size_t stackSize, const PEF::TransitionVector& entryPoint, bool startNow)
{
// lldb enforces some alignment constraints on the stack, so align it correctly by allocating some additional memory
ThreadContext* context = new ThreadContext(allocator, nextId, stackSize + 0x200);
uint32_t stackAddress = allocator.ToIntPtr(*context->stack);
stackAddress += 0x200;
stackAddress &= ~0x1ff;
auto info = stack.WriteStack(allocator.ToPointer<char>(stackAddress), stackAddress, stackSize);
context->machineState.r1 = allocator.ToIntPtr(info.sp);
context->machineState.r2 = entryPoint.TableOfContents;
context->machineState.r3 = context->machineState.r27 = info.argc;
context->machineState.r4 = context->machineState.r28 = allocator.ToIntPtr(info.argv);
context->machineState.r5 = context->machineState.r29 = allocator.ToIntPtr(info.envp);
context->machineState.lr = allocator.ToIntPtr(context->interpreter.GetEndAddress());
context->pc = entryPoint.EntryPoint;
context->thread = std::thread(&DebugThreadManager::DebugLoop, this, std::ref(*context), startNow);
// this should stay at the end of the method or be scoped
std::lock_guard<std::mutex> lock(threadsLock);
threads[context->GetThreadId()].reset(context);
nextId += 0x10;
return *context;
}
示例4: GetFreeContext
ThreadContext* PhysicalOperator::CreateOrReuseContext(context_reuse_mode crm) {
ThreadContext* target = GetFreeContext(crm);
if (target != NULL) {
return target;
}
target = CreateContext();
target->set_locality_(GetCurrentCpuAffinity());
InitContext(target);
return target;
}
示例5: RecyclerNew
SourceDynamicProfileManager *
SourceDynamicProfileManager::Deserialize(T * reader, Recycler* recycler)
{
uint functionCount;
if (!reader->Peek(&functionCount))
{
return nullptr;
}
BVFixed * startupFunctions = BVFixed::New(functionCount, recycler);
if (!reader->ReadArray(((char *)startupFunctions),
BVFixed::GetAllocSize(functionCount)))
{
return nullptr;
}
uint profileCount;
if (!reader->Read(&profileCount))
{
return nullptr;
}
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
SourceDynamicProfileManager * sourceDynamicProfileManager = RecyclerNew(threadContext->GetRecycler(), SourceDynamicProfileManager, recycler);
sourceDynamicProfileManager->cachedStartupFunctions = startupFunctions;
#if DBG_DUMP
if(Configuration::Global.flags.Dump.IsEnabled(DynamicProfilePhase))
{
Output::Print(L"Loaded: Startup functions bit vector:");
startupFunctions->Dump();
}
#endif
for (uint i = 0; i < profileCount; i++)
{
Js::LocalFunctionId functionId;
DynamicProfileInfo * dynamicProfileInfo = DynamicProfileInfo::Deserialize(reader, recycler, &functionId);
if (dynamicProfileInfo == nullptr || functionId >= functionCount)
{
return nullptr;
}
sourceDynamicProfileManager->dynamicProfileInfoMap.Add(functionId, dynamicProfileInfo);
}
return sourceDynamicProfileManager;
}
示例6: while
// This is called at process detach.
// threadcontext created from runtime should not be destroyed in ThreadBoundThreadContext
// we should clean them up at process detach only as runtime can be used in other threads
// even after the current physical thread was destroyed.
// This is called after ThreadBoundThreadContext are cleaned up, so the remaining items
// in the globalthreadContext linklist should be for jsrt only.
void JsrtRuntime::Uninitialize()
{
ThreadContext* currentThreadContext = ThreadContext::GetThreadContextList();
ThreadContext* tmpThreadContext;
while (currentThreadContext)
{
Assert(!currentThreadContext->IsScriptActive());
JsrtRuntime* currentRuntime = static_cast<JsrtRuntime*>(currentThreadContext->GetJSRTRuntime());
tmpThreadContext = currentThreadContext;
currentThreadContext = currentThreadContext->Next();
currentRuntime->CloseContexts();
RentalThreadContextManager::DestroyThreadContext(tmpThreadContext);
HeapDelete(currentRuntime);
}
}
示例7: sizeof
void
LRWMode::EncryptBlock(ThreadContext& context, uint8 *data, size_t length,
uint64 blockIndex)
{
uint8 i[8];
uint8 t[16];
uint32 b;
blockIndex = ((blockIndex - fOffset) << 5) + 1;
*(uint64*)i = B_HOST_TO_BENDIAN_INT64(blockIndex);
for (b = 0; b < length >> 4; b++) {
gf128_mul_by_tab64(i, t,
(galois_field_context*)context.BufferFor(fGaloisField));
xor128((uint64*)data, (uint64*)t);
fAlgorithm->Encrypt(context, data, 16);
xor128((uint64*)data, (uint64*)t);
data += 16;
if (i[7] != 0xff)
i[7]++;
else {
*(uint64*)i = B_HOST_TO_BENDIAN_INT64(
B_BENDIAN_TO_HOST_INT64(*(uint64*)i) + 1);
}
}
memset(t, 0, sizeof (t));
}
示例8:
void
AESAlgorithm::Encrypt(ThreadContext& context, uint8 *data, size_t length)
{
//dprintf(" aes-encrypt-pre: %x\n", *(int*)data);
aes_encrypt(data, data,
(const aes_encrypt_ctx*)context.BufferFor(fEncryptScheduler));
//dprintf(" aes-encrypt-post: %x\n", *(int*)data);
}
示例9: RecoverUnusedMemory
// Recover/Release unused memory and give it back to OS.
// The function doesn't throw if the attempt to recover memory fails, in which case it simply does nothing.
// Useful when running out of memory e.g. for Arena but there is some recycler memory which has been committed but is unused.
void Exception::RecoverUnusedMemory()
{
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
if (threadContext)
{
Recycler* threadRecycler = threadContext->GetRecycler();
if (threadRecycler)
{
try
{
threadRecycler->CollectNow<CollectOnRecoverFromOutOfMemory>();
}
catch (...)
{
// Technically, exception is a valid scenario: we asked to recover mem, and it couldn't.
// Do not let the exception leak out.
}
}
}
}
示例10: lock
void ThreadBoundThreadContextManager::DestroyContextAndEntryForCurrentThread()
{
AutoCriticalSection lock(ThreadContext::GetCriticalSection());
ThreadContextTLSEntry * entry = ThreadContextTLSEntry::GetEntryForCurrentThread();
if (entry == NULL)
{
return;
}
ThreadContext * threadContext = static_cast<ThreadContext *>(entry->GetThreadContext());
entries.Remove(entry);
if (threadContext != NULL && threadContext->IsThreadBound())
{
ShutdownThreadContext(threadContext);
}
ThreadContextTLSEntry::CleanupThread();
}
示例11: RaiseIfScriptActive
bool Exception::RaiseIfScriptActive(ScriptContext *scriptContext, unsigned kind, PVOID returnAddress)
{
ThreadContext *threadContext = ThreadContext::GetContextForCurrentThread();
if (threadContext != nullptr && threadContext->IsScriptActive())
{
switch (kind) {
case ExceptionKind_OutOfMemory:
AssertMsg(returnAddress == NULL, "should not have returnAddress passed in");
JavascriptError::ThrowOutOfMemoryError(scriptContext);
case ExceptionKind_StackOverflow:
JavascriptError::ThrowStackOverflowError(scriptContext, returnAddress);
default:
AssertMsg(false, "Invalid ExceptionKind");
}
}
return false;
}
示例12: GetSnapShotSemantics
void DynamicObjectPropertyEnumerator::Reset()
{
if (this->object)
{
enumeratedCount = 0;
initialType = object->GetDynamicType();
objectIndex = Constants::NoBigSlot;
initialPropertyCount = GetSnapShotSemantics() ? this->object->GetPropertyCount() : Constants::NoBigSlot;
// Create the appropriate enumerator object.
if (GetSnapShotSemantics() && this->initialType->PrepareForTypeSnapshotEnumeration())
{
ScriptContext* scriptContext = this->object->GetScriptContext();
ThreadContext * threadContext = scriptContext->GetThreadContext();
CachedData * data = (CachedData *)threadContext->GetDynamicObjectEnumeratorCache(this->initialType);
if (data == nullptr || data->scriptContext != this->requestContext || data->enumNonEnumerable != GetEnumNonEnumerable() || data->enumSymbols != GetEnumSymbols())
{
data = RecyclerNewStructPlus(scriptContext->GetRecycler(),
this->initialPropertyCount * sizeof(PropertyString *) + this->initialPropertyCount * sizeof(BigPropertyIndex) + this->initialPropertyCount * sizeof(PropertyAttributes), CachedData);
data->scriptContext = requestContext;
data->cachedCount = 0;
data->strings = (PropertyString **)(data + 1);
data->indexes = (BigPropertyIndex *)(data->strings + this->initialPropertyCount);
data->attributes = (PropertyAttributes*)(data->indexes + this->initialPropertyCount);
data->completed = false;
data->enumNonEnumerable = GetEnumNonEnumerable();
data->enumSymbols = GetEnumSymbols();
threadContext->AddDynamicObjectEnumeratorCache(this->initialType, data);
}
this->cachedData = data;
this->cachedDataType = this->initialType;
}
else
{
this->cachedData = nullptr;
this->cachedDataType = nullptr;
}
}
}
示例13: Assert
/* static */
bool JsrtContext::TrySetCurrent(JsrtContext * context)
{
Assert(s_tlsSlot != TLS_OUT_OF_INDEXES);
ThreadContext * threadContext;
//We are not pinning the context after SetCurrentContext, so if the context is not pinned
//it might be reclaimed half way during execution. In jsrtshell the runtime was optimized out
//at time of JsrtContext::Run by the compiler.
//The change is to pin the context at setconcurrentcontext, and unpin the previous one. In
//JsDisposeRuntime we'll reject if current context is active, so that will make sure all
//contexts are unpinned at time of JsDisposeRuntime.
if (context != nullptr)
{
threadContext = context->GetScriptContext()->GetThreadContext();
if (!ThreadContextTLSEntry::TrySetThreadContext(threadContext))
{
return false;
}
threadContext->GetRecycler()->RootAddRef((LPVOID)context);
}
else
{
if (!ThreadContextTLSEntry::ClearThreadContext(true))
{
return false;
}
}
JsrtContext* originalContext = (JsrtContext*) TlsGetValue(s_tlsSlot);
if (originalContext != nullptr)
{
originalContext->GetScriptContext()->GetRecycler()->RootRelease((LPVOID) originalContext);
}
TlsSetValue(s_tlsSlot, context);
return true;
}
示例14: RecyclerNew
void Utf8SourceInfo::EnsureInitialized(int initialFunctionCount)
{
ThreadContext* threadContext = ThreadContext::GetContextForCurrentThread();
Recycler* recycler = threadContext->GetRecycler();
if (this->functionBodyDictionary == nullptr)
{
// This collection is allocated with leaf allocation policy. The references to the function body
// here does not keep the function alive. However, the functions remove themselves at finalize
// so if a function actually is in this map, it means that it is alive.
this->functionBodyDictionary = RecyclerNew(recycler, FunctionBodyDictionary, recycler,
initialFunctionCount, threadContext->GetEtwRundownCriticalSection());
}
if (CONFIG_FLAG(DeferTopLevelTillFirstCall) && !m_deferredFunctionsInitialized)
{
Assert(this->m_deferredFunctionsDictionary == nullptr);
this->m_deferredFunctionsDictionary = RecyclerNew(recycler, DeferredFunctionsDictionary, recycler,
initialFunctionCount, threadContext->GetEtwRundownCriticalSection());
m_deferredFunctionsInitialized = true;
}
}
示例15: while
// This is called at process detach.
// threadcontext created from runtime should not be destroyed in ThreadBoundThreadContext
// we should clean them up at process detach only as runtime can be used in other threads
// even after the current physical thread was destroyed.
// This is called after ThreadBoundThreadContext are cleaned up, so the remaining items
// in the globalthreadContext linklist should be for jsrt only.
void JsrtRuntime::Uninitialize()
{
ThreadContext* currentThreadContext = ThreadContext::GetThreadContextList();
ThreadContext* tmpThreadContext;
while (currentThreadContext)
{
Assert(!currentThreadContext->IsScriptActive());
JsrtRuntime* currentRuntime = static_cast<JsrtRuntime*>(currentThreadContext->GetJSRTRuntime());
tmpThreadContext = currentThreadContext;
currentThreadContext = currentThreadContext->Next();
#ifdef CHAKRA_STATIC_LIBRARY
// xplat-todo: Cleanup staticlib shutdown. This only shuts down threads.
// Other closing contexts / finalizers having trouble with current
// runtime/context.
RentalThreadContextManager::DestroyThreadContext(tmpThreadContext);
#else
currentRuntime->CloseContexts();
RentalThreadContextManager::DestroyThreadContext(tmpThreadContext);
HeapDelete(currentRuntime);
#endif
}
}