1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/threading/worker_pool.h"
6
7#include "base/logging.h"
8#include "base/task.h"
9
10namespace base {
11
12namespace {
13
14DWORD CALLBACK WorkItemCallback(void* param) {
15  Task* task = static_cast<Task*>(param);
16  task->Run();
17  delete task;
18  return 0;
19}
20
21}  // namespace
22
23bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
24                          Task* task, bool task_is_slow) {
25  task->SetBirthPlace(from_here);
26
27  ULONG flags = 0;
28  if (task_is_slow)
29    flags |= WT_EXECUTELONGFUNCTION;
30
31  if (!QueueUserWorkItem(WorkItemCallback, task, flags)) {
32    DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError();
33    delete task;
34    return false;
35  }
36
37  return true;
38}
39
40}  // namespace base
41