| 2125 | }; |
| 2126 | |
| 2127 | static BOOLEAN createThreadPool(leftv result, leftv arg) { |
| 2128 | long n; |
| 2129 | Command cmd("createThreadPool", result, arg); |
| 2130 | cmd.check_argc(1, 2); |
| 2131 | cmd.check_arg(0, INT_CMD, "first argument must be an integer"); |
| 2132 | if (cmd.ok()) { |
| 2133 | n = (long) cmd.arg(0); |
| 2134 | if (n < 0) cmd.report("number of threads must be non-negative"); |
| 2135 | else if (n >= 256) cmd.report("number of threads too large"); |
| 2136 | if (!have_threads && n != 0) |
| 2137 | cmd.report("in single-threaded mode, number of threads must be zero"); |
| 2138 | } |
| 2139 | if (cmd.ok()) { |
| 2140 | ThreadPool *pool = new ThreadPool((int) n); |
| 2141 | pool->set_type(type_threadpool); |
| 2142 | for (int i = 0; i <n; i++) { |
| 2143 | const char *error; |
| 2144 | SchedInfo *info = new SchedInfo(); |
| 2145 | info->scheduler = pool->scheduler; |
| 2146 | acquireShared(pool->scheduler); |
| 2147 | info->job = NULL; |
| 2148 | info->num = i; |
| 2149 | ThreadState *thread = newThread(Scheduler::main, info, &error); |
| 2150 | if (!thread) { |
| 2151 | // TODO: clean up bad pool |
| 2152 | return cmd.abort(error); |
| 2153 | } |
| 2154 | pool->addThread(thread); |
| 2155 | } |
| 2156 | cmd.set_result(type_threadpool, new_shared(pool)); |
| 2157 | } |
| 2158 | return cmd.status(); |
| 2159 | } |
| 2160 | |
| 2161 | static BOOLEAN createThreadPoolSet(leftv result, leftv arg) { |
| 2162 | Command cmd("createThreadPoolSet", result, arg); |
nothing calls this directly
no test coverage detected