Make comparison IR ops layout agnostic
[hiphop-php.git] / hphp / runtime / base / vm-worker.h
blobf25defd3c0b53dd059041744c786eb517362abe7
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_RUNTIME_VM_WORKER_H
18 #define incl_HPHP_RUNTIME_VM_WORKER_H
20 #include "hphp/util/async-func.h"
21 #include <functional>
23 namespace HPHP {
25 struct WorkerSpec {
26 int numaNode{-1};
27 unsigned hugeStackKb{0};
28 unsigned tlExtraKb{0};
31 // Run arbitrary code in a thread/fiber with VM context.
32 struct VMWorker : private std::function<void(void)>
33 , private AsyncFuncImpl {
34 template<class F>
35 explicit VMWorker(F&& f)
36 : std::function<void(void)>(f)
37 , AsyncFuncImpl(this, run_, -1, 0, 0)
40 template<class F>
41 VMWorker(WorkerSpec s, F&& f)
42 : std::function<void(void)>(f)
43 , AsyncFuncImpl(this, run_, s.numaNode, s.hugeStackKb, s.tlExtraKb)
46 VMWorker(const VMWorker&) = delete;
48 using AsyncFuncImpl::start;
49 using AsyncFuncImpl::run;
50 using AsyncFuncImpl::waitForEnd;
52 private:
53 static void run_(void* obj) {
54 // hphp_thread_init/exit are called as hooks of AsyncFuncImpl, see struct
55 // SetThreadInitFini.
56 auto p = static_cast<VMWorker*>(obj);
57 (*p)();
63 #endif