本文整理汇总了C++中Dispatch函数的典型用法代码示例。如果您正苦于以下问题:C++ Dispatch函数的具体用法?C++ Dispatch怎么用?C++ Dispatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ref
void
BenchmarkPlayback::InputExhausted()
{
RefPtr<Benchmark> ref(mMainThreadState);
Dispatch(NS_NewRunnableFunction([this, ref]() {
MOZ_ASSERT(OnThread());
if (mFinished || mSampleIndex >= mSamples.Length()) {
return;
}
mDecoder->Input(mSamples[mSampleIndex]);
mSampleIndex++;
if (mSampleIndex == mSamples.Length()) {
if (ref->mParameters.mStopAtFrame) {
mSampleIndex = 0;
} else {
mDecoder->Drain();
}
}
}));
}
示例2: Monitor_Start
void Monitor_Start(RingBuffer *inputBuffer)
{
dGuard(inputBuffer == NULL);
OpenConsole();
PrintLogo(Console);
while (1)
{
uint16_t read = ReadLineInto(inputBuffer);
StreamWriter_WriteLine(Console, inputBuffer->Buffer, read);
if (!Dispatch(inputBuffer, Console)) break;
}
StreamWriter_WriteLine(Console, "Bye.", 4);
Stream_Close(Console);
Console = NULL;
}
示例3: Decode
int Decode(int index, uint8_t bytes[])
{
Instruction instruction = DecodeInstruction(bytes[index]);
AddressingMode addressingMode = DecodeAddressingMode(bytes[index]);
/*
* Exceptions:
* STX:
* ZeroPageX -> ZeroPageY
* LDX:
* ZeroPageX -> ZeroPageY
* AbsoluteX -> AbsoluteY
*/
if ((instruction == STX || instruction == LDX) && addressingMode == ZeroPageX)
addressingMode = ZeroPageY;
if (instruction == LDX && addressingMode == AbsoluteX)
addressingMode = AbsoluteY;
Dispatch(instruction, addressingMode, index, bytes);
return FindInstructionLength(addressingMode);
}
示例4: MOZ_ASSERT
void
BenchmarkPlayback::InitDecoder(TrackInfo&& aInfo)
{
MOZ_ASSERT(OnThread());
RefPtr<PDMFactory> platform = new PDMFactory();
mDecoder = platform->CreateDecoder(aInfo, mDecoderTaskQueue, this);
if (!mDecoder) {
MainThreadShutdown();
return;
}
RefPtr<Benchmark> ref(mMainThreadState);
mDecoder->Init()->Then(
ref->Thread(), __func__,
[this, ref](TrackInfo::TrackType aTrackType) {
Dispatch(NS_NewRunnableFunction([this, ref]() { InputExhausted(); }));
},
[this, ref](MediaDataDecoder::DecoderFailureReason aReason) {
MainThreadShutdown();
});
}
示例5: Dispatch
void VSTPlugin::Create(VSTPlugin *plug)
{
h_dll=plug->h_dll;
_pEffect=plug->_pEffect;
_pEffect->user=this;
Dispatch( effMainsChanged, 0, 1, NULL, 0.0f);
// strcpy(_editName,plug->_editName); On current implementation, this replaces the right one.
strcpy(_sProductName,plug->_sProductName);
strcpy(_sVendorName,plug->_sVendorName);
_sDllName = new char[strlen(plug->_sDllName)+1];
strcpy(_sDllName,plug->_sDllName);
_isSynth=plug->_isSynth;
_version=plug->_version;
plug->instantiated=false; // We are "stoling" the plugin from the "plug" object so this
// is just a "trick" so that when destructing the "plug", it
// doesn't unload the Dll.
instantiated=true;
}
示例6: LOG
void
CacheStorageService::OnMemoryConsumptionChange(CacheMemoryConsumer* aConsumer,
uint32_t aCurrentMemoryConsumption)
{
LOG(("CacheStorageService::OnMemoryConsumptionChange [consumer=%p, size=%u]",
aConsumer, aCurrentMemoryConsumption));
uint32_t savedMemorySize = aConsumer->mReportedMemoryConsumption;
if (savedMemorySize == aCurrentMemoryConsumption)
return;
// Exchange saved size with current one.
aConsumer->mReportedMemoryConsumption = aCurrentMemoryConsumption;
mMemorySize -= savedMemorySize;
mMemorySize += aCurrentMemoryConsumption;
LOG((" mMemorySize=%u (+%u,-%u)", uint32_t(mMemorySize), aCurrentMemoryConsumption, savedMemorySize));
// Bypass purging when memory has not grew up significantly
if (aCurrentMemoryConsumption <= savedMemorySize)
return;
if (mPurging) {
LOG((" already purging"));
return;
}
if (mMemorySize <= CacheObserver::MemoryLimit())
return;
// Throw the oldest data or whole entries away when over certain limits
mPurging = true;
// Must always dipatch, since this can be called under e.g. a CacheFile's lock.
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &CacheStorageService::PurgeOverMemoryLimit);
Dispatch(event);
}
示例7: ProcessEvents
bool ProcessEvents()
{
// process pending wx events first as they correspond to low-level events
// which happened before, i.e. typically pending events were queued by a
// previous call to Dispatch() and if we didn't process them now the next
// call to it might enqueue them again (as happens with e.g. socket events
// which would be generated as long as there is input available on socket
// and this input is only removed from it when pending event handlers are
// executed)
if( wxTheApp )
{
wxTheApp->ProcessPendingEvents();
// One of the pending event handlers could have decided to exit the
// loop so check for the flag before trying to dispatch more events
// (which could block indefinitely if no more are coming).
if( m_shouldExit )
return false;
}
return Dispatch();
}
示例8: ref
void
BenchmarkPlayback::Output(MediaData* aData)
{
RefPtr<Benchmark> ref(mMainThreadState);
Dispatch(NS_NewRunnableFunction([this, ref]() {
mFrameCount++;
if (mFrameCount == ref->mParameters.mStartupFrame) {
mDecodeStartTime = TimeStamp::Now();
}
int32_t frames = mFrameCount - ref->mParameters.mStartupFrame;
TimeDuration elapsedTime = TimeStamp::Now() - mDecodeStartTime;
if (!mFinished &&
(frames == ref->mParameters.mFramesToMeasure ||
elapsedTime >= ref->mParameters.mTimeout)) {
uint32_t decodeFps = frames / elapsedTime.ToSeconds();
MainThreadShutdown();
ref->Dispatch(NS_NewRunnableFunction([ref, decodeFps]() {
ref->ReturnResult(decodeFps);
}));
}
}));
}
示例9: SOCKET_LOG
nsresult
nsSocketTransportService::DetachSocket(SocketContext *listHead, SocketContext *sock)
{
SOCKET_LOG(("nsSocketTransportService::DetachSocket [handler=%p]\n", sock->mHandler));
MOZ_ASSERT((listHead == mActiveList) || (listHead == mIdleList),
"DetachSocket invalid head");
// inform the handler that this socket is going away
sock->mHandler->OnSocketDetached(sock->mFD);
mSentBytesCount += sock->mHandler->ByteCountSent();
mReceivedBytesCount += sock->mHandler->ByteCountReceived();
// cleanup
sock->mFD = nullptr;
NS_RELEASE(sock->mHandler);
if (listHead == mActiveList)
RemoveFromPollList(sock);
else
RemoveFromIdleList(sock);
// NOTE: sock is now an invalid pointer
//
// notify the first element on the pending socket queue...
//
nsCOMPtr<nsIRunnable> event;
LinkedRunnableEvent *runnable = mPendingSocketQueue.getFirst();
if (runnable) {
event = runnable->TakeEvent();
runnable->remove();
delete runnable;
}
if (event) {
// move event from pending queue to dispatch queue
return Dispatch(event, NS_DISPATCH_NORMAL);
}
return NS_OK;
}
示例10: sizeof
void ConnectionHandler::DispatchIfCan() {
if (reading_status_ == ReadingStatus::Length && socket_buffer_.used() >= sizeof(UInt32)) {
UInt32Bytes length{};
socket_buffer_.read(length.bytes, sizeof(UInt32));
current_message_length = length.number;
// set reading status to next
reading_status_ = ReadingStatus::OpCode;
}
if (reading_status_ == ReadingStatus::OpCode && socket_buffer_.used() >= sizeof(UInt32)) {
UInt32Bytes opcode{};
socket_buffer_.read(opcode.bytes, sizeof(UInt32));
// initialize current message with the opcode
current_message_ = Message{opcode.number};
// set reading status to data
reading_status_ = ReadingStatus::Data;
}
if (reading_status_ == ReadingStatus::Data && socket_buffer_.used() >= current_message_length) {
// initialize the vector for the data
current_message_.data_vector().clear();
current_message_.data_vector().resize(current_message_length);
socket_buffer_.read(current_message_.data(), current_message_length);
// dispatch message
Dispatch(current_message_);
// set reading status back to length
reading_status_ = ReadingStatus::Length;
// if there is data in the buffer and we read the whole
// packet, launch socket readable once more
if (socket_buffer_.used() > sizeof(UInt32)) {
DispatchIfCan();
}
}
}
示例11: ASSERT_OWNING_THREAD
void
LazyIdleThread::EnableIdleTimeout()
{
ASSERT_OWNING_THREAD();
if (mIdleTimeoutEnabled) {
return;
}
mIdleTimeoutEnabled = true;
{
MutexAutoLock lock(mMutex);
MOZ_ASSERT(mPendingEventCount, "Mismatched calls to observer methods!");
--mPendingEventCount;
}
if (mThread) {
nsCOMPtr<nsIRunnable> runnable(new nsRunnable());
if (NS_FAILED(Dispatch(runnable, NS_DISPATCH_NORMAL))) {
NS_WARNING("Failed to dispatch!");
}
}
}
示例12: cairo_ps_surface_create
void Shape::Render(const char *path){
if(geom_ == NULL) return;
cairo_surface_t *surface = cairo_ps_surface_create(path, width_, height_);
if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
std::cout << cairo_status_to_string(cairo_surface_status(surface)) << std::endl;
exit(1);
return;
}
ctx_ = cairo_create(surface);
OGREnvelope env;
geom_->getEnvelope(&env);
cairo_matrix_t mat;
matrix_init(&mat, width_, height_, &env);
cairo_set_matrix(ctx_, &mat);
Dispatch(geom_);
cairo_show_page(ctx_);
cairo_destroy(ctx_);
cairo_surface_destroy(surface);
}
示例13: Dispatch
//*=================================================================================
//*原型: void ProcessRequest(SOCKET hSocket)
//*功能: 处理客户机的请求
//*参数: 无
//*返回: 无
//*说明: 先读入包头, 再读包数据, 然后再处理请求
//*=================================================================================
void TSmartOutThread::ProcessRequest(SOCKET hSocket, SOCKADDR_IN *psockAddr)
{
TSmartPacket Packet;
try
{
if( ReadRequestPacket(hSocket, Packet) )
{
if( CheckPacket(psockAddr, Packet) )
{
Dispatch(hSocket, psockAddr, Packet);
}
}
}
catch(TException& e)
{
WriteLog(e.GetText());
}
catch(...)
{
WriteLog("客户服务线程有未知异常!");
}
}
示例14: while
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
{
#if wxUSE_THREADS
if ( !wxThread::IsMain() )
return true; // can't process events from other threads
#endif // wxUSE_THREADS
m_isInsideYield = true;
m_eventsToProcessInsideYield = eventsToProcess;
#if wxUSE_LOG
wxLog::Suspend();
#endif // wxUSE_LOG
// TODO: implement event filtering using the eventsToProcess mask
// process all pending events:
while ( Pending() )
Dispatch();
// handle timers, sockets etc.
OnNextIteration();
// it's necessary to call ProcessIdle() to update the frames sizes which
// might have been changed (it also will update other things set from
// OnUpdateUI() which is a nice (and desired) side effect)
while ( ProcessIdle() ) {}
#if wxUSE_LOG
wxLog::Resume();
#endif // wxUSE_LOG
m_isInsideYield = false;
return true;
}
示例15: doSchedule
/* doSchedule() will do a Task Switch to a high priority task
* in ready state.It don't care wether OSCurTask are
* Preemptable or not,or INVALID_TASK.
* Note OSCurTsk also may be the highest priority Task in READY state.
* in ready or running state*/
void doSchedule(void)
{
/* The Situation that when the SEVERAL_TASKS_PER_PRIORITY Policy was adopted,
* there may be a task or more with the same xPriority as OSCurTsk in the
* ready state*/
if(OSCurTsk == OSHighRdyTsk)
{ /* higher priority task in ready or running state */
/* Search the table map to find OSHighPriority*/
OS_ENTER_CRITICAL();
#if (cfgOS_TASK_PER_PRIORITY == SEVERAL_TASKS_PER_PRIORITY)
if(listTskRdyIsEmpty(OSCurTcb->xPriority))
{ /* if OSTskRdyListHead[xPriority] is Empty, */
#endif /* Find out an Runnable Task */
OSHighRdyPrio = tableRdyMapFindHighPriority();
#if (cfgOS_TASK_PER_PRIORITY == SEVERAL_TASKS_PER_PRIORITY)
} /* if OSTcbRdyGrpList[xPriority] is not Empty, */
#endif /* make the head task runnable */
/* Get The Tcb with the highest Priority*/
OSHighRdyTsk = listGetRdyTsk(OSHighRdyPrio);
OSHighRdyTcb = &OSTcbTable[OSHighRdyTsk];
OS_EXIT_CRITICAL();
}
Dispatch();
}