本文整理汇总了C++中TaskQueue类的典型用法代码示例。如果您正苦于以下问题:C++ TaskQueue类的具体用法?C++ TaskQueue怎么用?C++ TaskQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AsyncDecodeWebAudio
void AsyncDecodeWebAudio(const char* aContentType, uint8_t* aBuffer,
uint32_t aLength, WebAudioDecodeJob& aDecodeJob) {
Maybe<MediaContainerType> containerType =
MakeMediaContainerType(aContentType);
// Do not attempt to decode the media if we were not successful at sniffing
// the container type.
if (!*aContentType || strcmp(aContentType, APPLICATION_OCTET_STREAM) == 0 ||
!containerType) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob, &WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownContent);
JS_free(nullptr, aBuffer);
aDecodeJob.mContext->Dispatch(event.forget());
return;
}
RefPtr<MediaDecodeTask> task =
new MediaDecodeTask(*containerType, aBuffer, aLength, aDecodeJob);
if (!task->CreateReader()) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob, &WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownError);
aDecodeJob.mContext->Dispatch(event.forget());
} else {
// If we did this without a temporary:
// task->Reader()->OwnerThread()->Dispatch(task.forget())
// we might evaluate the task.forget() before calling Reader(). Enforce
// a non-crashy order-of-operations.
TaskQueue* taskQueue = task->Reader()->OwnerThread();
nsresult rv = taskQueue->Dispatch(task.forget());
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
Unused << rv;
}
}
示例2: main
int main( int argc, char* argv[] )
{
// Our progress counter.
auto counter = pc::ProgressCounter::Create();
// Our tasks queue.
TaskQueue tasks;
// Produce the tasks.
std::mt19937 rnd_device( (uint32_t)time( 0 ) );
for( int32_t task_id = 0; task_id < 680; ++task_id )
{
auto goal = counter->ProduceGoal();
std::chrono::milliseconds interval{ 600 + rnd_device() % 1400 };
tasks.PushTask( { [goal, interval](){ std::this_thread::sleep_for( interval ); } } );
};
// Produce the workers.
tasks.Lock();
size_t threads_count = std::thread::hardware_concurrency();
while( threads_count-- > 0 )
{
std::thread t( ThreadFunction, std::ref( tasks ) );
t.detach();
};
tasks.Unlock();
// Display the progress of tasks completion until the progress reaches 100%
do
{
printf( "\rCurrent progress : %3.3f%%; Tasks remained : %zd;", 100.0f * counter->GetFinisedPercent(), tasks.GetCount() );
std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) );
}
while( counter->GetRemainsPercent() > 0.0f );
};
示例3: loadQueue
int loadQueue(const char *pPath, TaskQueue &queue)
{
DIR *pDir = opendir(pPath);
if (!pDir){
if (errno == ENOTDIR && access(pPath, F_OK) == 0) {
char *pFile = new char[strlen(pPath) + 1];
strcpy(pFile, pPath);
queue.pushBack(pFile);
return 0;
}
return -1;
}
struct dirent *de = NULL;
while ((de=readdir(pDir))!=NULL) {
if (de->d_type != DT_REG && de->d_type != DT_LNK) {
continue;
}
char *pFile = new char[strlen(pPath) + strlen(de->d_name) + 2];
snprintf(pFile, strlen(pPath) + strlen(de->d_name) + 2, "%s/%s", pPath, de->d_name);
queue.pushBack(pFile);
TNOTE("find file %s", pFile);
}
closedir(pDir);
return 0;
}
示例4: IDB_TRACE
void IDBTransactionBackendImpl::taskTimerFired(Timer<IDBTransactionBackendImpl>*)
{
IDB_TRACE("IDBTransactionBackendImpl::taskTimerFired");
ASSERT(!isTaskQueueEmpty());
if (m_state == StartPending) {
m_transaction.begin();
m_state = Running;
}
// The last reference to this object may be released while performing the
// tasks. Take take a self reference to keep this object alive so that
// the loop termination conditions can be checked.
RefPtr<IDBTransactionBackendImpl> protect(this);
TaskQueue* taskQueue = m_pendingPreemptiveEvents ? &m_preemptiveTaskQueue : &m_taskQueue;
while (!taskQueue->isEmpty() && m_state != Finished) {
ASSERT(m_state == Running);
OwnPtr<Operation> task(taskQueue->takeFirst());
task->perform(this);
// Event itself may change which queue should be processed next.
taskQueue = m_pendingPreemptiveEvents ? &m_preemptiveTaskQueue : &m_taskQueue;
}
// If there are no pending tasks, we haven't already committed/aborted,
// and the front-end requested a commit, it is now safe to do so.
if (!hasPendingTasks() && m_state != Finished && m_commitPending)
commit();
}
示例5: str
map<uint32_t, NodeList> Worker::get_map(TaskQueue &mqueue) {
map<uint32_t, NodeList> update_map;
/*Package package;
package.set_operation(operation);
if(operation == 25) {
package.set_currnode(toid);
}*/
uint32_t num_nodes = svrclient.memberList.size();
for (TaskQueue::iterator it = mqueue.begin(); it != mqueue.end(); ++it) {
uint32_t serverid = myhash(((*it)->task_id).c_str(), num_nodes);
string str((*it)->task_id);
str.append("\'");
if (update_map.find(serverid) == update_map.end()) {
str.append("\"");
NodeList new_list;
new_list.push_back(str);
update_map.insert(make_pair(serverid, new_list));
} else {
NodeList &exist_list = update_map[serverid];
string last_str(exist_list.back());
if ((last_str.size() + str.size()) > STRING_THRESHOLD) {
str.append("\"");
exist_list.push_back(str);
} else {
exist_list.pop_back();
str.append(last_str);
exist_list.push_back(str);
}
}
}
return update_map;
}
示例6: AsyncDecodeWebAudio
void
AsyncDecodeWebAudio(const char* aContentType, uint8_t* aBuffer,
uint32_t aLength, WebAudioDecodeJob& aDecodeJob)
{
// Do not attempt to decode the media if we were not successful at sniffing
// the content type.
if (!*aContentType ||
strcmp(aContentType, APPLICATION_OCTET_STREAM) == 0) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob,
&WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownContent);
JS_free(nullptr, aBuffer);
NS_DispatchToMainThread(event);
return;
}
RefPtr<MediaDecodeTask> task =
new MediaDecodeTask(aContentType, aBuffer, aLength, aDecodeJob);
if (!task->CreateReader()) {
nsCOMPtr<nsIRunnable> event =
new ReportResultTask(aDecodeJob,
&WebAudioDecodeJob::OnFailure,
WebAudioDecodeJob::UnknownError);
NS_DispatchToMainThread(event);
} else {
// If we did this without a temporary:
// task->Reader()->OwnerThread()->Dispatch(task.forget())
// we might evaluate the task.forget() before calling Reader(). Enforce
// a non-crashy order-of-operations.
TaskQueue* taskQueue = task->Reader()->OwnerThread();
taskQueue->Dispatch(task.forget());
}
}
示例7: updateFramesClass
void TaskScheduler::updateFramesClass(TaskQueue& queue, Class* klass)
{
for(TaskQueue::iterator it = queue.begin(); it != queue.end(); it++)
{
Task* task = *it;
task->getContext()->updateFramesClass(klass);
}
}
示例8: main
int main()
{
TaskQueue q;
q.post([]{ std::cout << "Hello World!" << std::endl; });
q.post([]{ std::cout << "Hello World!" << std::endl; });
q.poll_one();
q.post([]{ std::cout << "Hello World!" << std::endl; });
q.poll_all();
}
示例9: ThreadFunction
void ThreadFunction( TaskQueue& tasks )
{
while( !tasks.IsEmpty() )
{
{
auto task = tasks.PullTask();
// Process this task.
task();
};
};
};
示例10: executeQueuedTasks
void HTMLConstructionSite::executeQueuedTasks()
{
const size_t size = m_taskQueue.size();
if (!size)
return;
// Copy the task queue into a local variable in case executeTask
// re-enters the parser.
TaskQueue queue;
queue.swap(m_taskQueue);
for (size_t i = 0; i < size; ++i)
executeTask(queue[i]);
// We might be detached now.
}
示例11: main
int main() {
TaskQueue<FibonacciTask> fibonacciTasks;
for (int i = 42; i >= 39; --i) {
fibonacciTasks.add([i](size_t threadId) { runFibonacci(i, threadId); });
}
ThreadPool<FibonacciTask> threadPool(4, fibonacciTasks);
for (int j = 0; j < 5; ++j) {
for (int i = 35; i > 20; --i) {
fibonacciTasks.add([i](size_t threadId) { runFibonacci(i, threadId); });
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return 0;
}
示例12: run
void run() {
tot = 0;
TaskQueue<V> d;
int x = 0;
for( int i = 0; i < 100; i++ ) {
if( i % 30 == 0 )
d.invoke();
x += i;
writelock lk;
V v;
v.val = i;
d.defer(v);
}
d.invoke();
assert( x == tot );
}
示例13: ActivateOneOutputTask
INLINE void ActivateOneOutputTask(TaskQueue& queue, int task, int* tasknum)
{
if (DEC_ATOMIC(&fTaskList[task]) == 0) {
*tasknum = task;
} else {
*tasknum = queue.PopHead();
}
}
示例14: move_task_to_ready_queue
int Worker::move_task_to_ready_queue(TaskQueue_Item **qi) {
//pthread_mutex_lock(&w_lock);
pthread_mutex_lock(&lock);
rqueue.push_back(*qi);
//wqueue.erase(*qi);
pthread_mutex_unlock(&lock);
//pthread_mutex_unlock(&w_lock);
}
示例15: fun1
void fun1(void* data) {
TaskQueue* queue = static_cast<TaskQueue*>(data);
cout<< " thread "<< std::this_thread::get_id()<<" run" << endl;
std::chrono::milliseconds dura( 5);
cout.flush();
for (int i = 0; i < 10; i++) {
Task* task = new DemonTask();
queue->PushBack(task);
//std::this_thread::sleep_for(dura);
}
cout<<"f1:queue size" << queue->size()<<endl;;
cout.flush();
Task* task = queue->PopFront();
task->Action();
//task->Release();
cout<<"f1:queue size" << queue->size()<<endl;;
cout.flush();
}