@@ -246,6 +246,16 @@ class PageAllocator { |
246 | 246 | */ |
247 | 247 | class Platform { |
248 | 248 | public: |
| 249 | + /** |
| 250 | + * This enum is used to indicate whether a task is potentially long running, |
| 251 | + * or causes a long wait. The embedder might want to use this hint to decide |
| 252 | + * whether to execute the task on a dedicated thread. |
| 253 | + */ |
| 254 | + enum ExpectedRuntime { |
| 255 | + kShortRunningTask, |
| 256 | + kLongRunningTask |
| 257 | + }; |
| 258 | + |
249 | 259 | virtual ~Platform() = default; |
250 | 260 |
|
251 | 261 | /** |
@@ -280,25 +290,101 @@ class Platform { |
280 | 290 | virtual bool OnCriticalMemoryPressure(size_t length) { return false; } |
281 | 291 |
|
282 | 292 | /** |
283 | | - * Gets the number of worker threads used by |
284 | | - * Call(BlockingTask)OnWorkerThread(). This can be used to estimate the number |
285 | | - * of tasks a work package should be split into. A return value of 0 means |
286 | | - * that there are no worker threads available. Note that a value of 0 won't |
287 | | - * prohibit V8 from posting tasks using |CallOnWorkerThread|. |
| 293 | + * Gets the number of worker threads used by GetWorkerThreadsTaskRunner() and |
| 294 | + * CallOnWorkerThread(). This can be used to estimate the number of tasks a |
| 295 | + * work package should be split into. A return value of 0 means that there are |
| 296 | + * no worker threads available. Note that a value of 0 won't prohibit V8 from |
| 297 | + * posting tasks using |CallOnWorkerThread|. |
| 298 | + */ |
| 299 | + virtual int NumberOfWorkerThreads() { |
| 300 | + return static_cast<int>(NumberOfAvailableBackgroundThreads()); |
| 301 | + } |
| 302 | + |
| 303 | + /** |
| 304 | + * Deprecated. Use NumberOfWorkerThreads() instead. |
| 305 | + * TODO(gab): Remove this when all embedders override |
| 306 | + * NumberOfWorkerThreads() instead. |
288 | 307 | */ |
289 | | - virtual int NumberOfWorkerThreads() = 0; |
| 308 | + V8_DEPRECATE_SOON( |
| 309 | + "NumberOfAvailableBackgroundThreads() is deprecated, use " |
| 310 | + "NumberOfAvailableBackgroundThreads() instead.", |
| 311 | + virtual size_t NumberOfAvailableBackgroundThreads()) { |
| 312 | + return 0; |
| 313 | + } |
290 | 314 |
|
291 | 315 | /** |
292 | 316 | * Returns a TaskRunner which can be used to post a task on the foreground. |
293 | 317 | * This function should only be called from a foreground thread. |
294 | 318 | */ |
295 | 319 | virtual std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner( |
296 | | - Isolate* isolate) = 0; |
| 320 | + Isolate* isolate) { |
| 321 | + // TODO(ahaas): Make this function abstract after it got implemented on all |
| 322 | + // platforms. |
| 323 | + return {}; |
| 324 | + } |
| 325 | + |
| 326 | + /** |
| 327 | + * Returns a TaskRunner which can be used to post a task on a background. |
| 328 | + * This function should only be called from a foreground thread. |
| 329 | + */ |
| 330 | + V8_DEPRECATE_SOON( |
| 331 | + "GetBackgroundTaskRunner() is deprecated, use " |
| 332 | + "GetWorkerThreadsTaskRunner() " |
| 333 | + "instead.", |
| 334 | + virtual std::shared_ptr<v8::TaskRunner> GetBackgroundTaskRunner( |
| 335 | + Isolate* isolate)) { |
| 336 | + // TODO(gab): Remove this method when all embedders have moved to |
| 337 | + // GetWorkerThreadsTaskRunner(). |
| 338 | + |
| 339 | + // An implementation needs to be provided here because this is called by the |
| 340 | + // default GetWorkerThreadsTaskRunner() implementation below. In practice |
| 341 | + // however, all code either: |
| 342 | + // - Overrides GetWorkerThreadsTaskRunner() (thus not making this call) -- |
| 343 | + // i.e. all v8 code. |
| 344 | + // - Overrides this method (thus not making this call) -- i.e. all |
| 345 | + // unadapted embedders. |
| 346 | + abort(); |
| 347 | + } |
| 348 | + |
| 349 | + /** |
| 350 | + * Returns a TaskRunner which can be used to post async tasks on a worker. |
| 351 | + * This function should only be called from a foreground thread. |
| 352 | + */ |
| 353 | + virtual std::shared_ptr<v8::TaskRunner> GetWorkerThreadsTaskRunner( |
| 354 | + Isolate* isolate) { |
| 355 | + // TODO(gab): Make this function abstract after it got implemented on all |
| 356 | + // platforms. |
| 357 | + return GetBackgroundTaskRunner(isolate); |
| 358 | + } |
| 359 | + |
| 360 | + /** |
| 361 | + * Schedules a task to be invoked on a background thread. |expected_runtime| |
| 362 | + * indicates that the task will run a long time. The Platform implementation |
| 363 | + * takes ownership of |task|. There is no guarantee about order of execution |
| 364 | + * of tasks wrt order of scheduling, nor is there a guarantee about the |
| 365 | + * thread the task will be run on. |
| 366 | + */ |
| 367 | + V8_DEPRECATE_SOON( |
| 368 | + "ExpectedRuntime is deprecated, use CallOnWorkerThread() instead.", |
| 369 | + virtual void CallOnBackgroundThread(Task* task, |
| 370 | + ExpectedRuntime expected_runtime)) { |
| 371 | + // An implementation needs to be provided here because this is called by the |
| 372 | + // default implementation below. In practice however, all code either: |
| 373 | + // - Overrides the new method (thus not making this call) -- i.e. all v8 |
| 374 | + // code. |
| 375 | + // - Overrides this method (thus not making this call) -- i.e. all |
| 376 | + // unadapted embedders. |
| 377 | + abort(); |
| 378 | + } |
297 | 379 |
|
298 | 380 | /** |
299 | 381 | * Schedules a task to be invoked on a worker thread. |
| 382 | + * TODO(gab): Make pure virtual when all embedders override this instead of |
| 383 | + * CallOnBackgroundThread(). |
300 | 384 | */ |
301 | | - virtual void CallOnWorkerThread(std::unique_ptr<Task> task) = 0; |
| 385 | + virtual void CallOnWorkerThread(std::unique_ptr<Task> task) { |
| 386 | + CallOnBackgroundThread(task.release(), kShortRunningTask); |
| 387 | + } |
302 | 388 |
|
303 | 389 | /** |
304 | 390 | * Schedules a task that blocks the main thread to be invoked with |
@@ -310,13 +396,6 @@ class Platform { |
310 | 396 | CallOnWorkerThread(std::move(task)); |
311 | 397 | } |
312 | 398 |
|
313 | | - /** |
314 | | - * Schedules a task to be invoked on a worker thread after |delay_in_seconds| |
315 | | - * expires. |
316 | | - */ |
317 | | - virtual void CallDelayedOnWorkerThread(std::unique_ptr<Task> task, |
318 | | - double delay_in_seconds) = 0; |
319 | | - |
320 | 399 | /** |
321 | 400 | * Schedules a task to be invoked on a foreground thread wrt a specific |
322 | 401 | * |isolate|. Tasks posted for the same isolate should be execute in order of |
@@ -342,14 +421,14 @@ class Platform { |
342 | 421 | * The definition of "foreground" is opaque to V8. |
343 | 422 | */ |
344 | 423 | virtual void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) { |
345 | | - // This must be overriden if |IdleTasksEnabled()|. |
346 | | - abort(); |
| 424 | + // TODO(ulan): Make this function abstract after V8 roll in Chromium. |
347 | 425 | } |
348 | 426 |
|
349 | 427 | /** |
350 | 428 | * Returns true if idle tasks are enabled for the given |isolate|. |
351 | 429 | */ |
352 | 430 | virtual bool IdleTasksEnabled(Isolate* isolate) { |
| 431 | + // TODO(ulan): Make this function abstract after V8 roll in Chromium. |
353 | 432 | return false; |
354 | 433 | } |
355 | 434 |
|
|