|
9 | 9 | #include "thread_state.hpp" |
10 | 10 | #include "../as.hpp" |
11 | 11 | #include "../core_export.hpp" |
| 12 | +#include "../date_time.hpp" |
| 13 | +#include "../intptr.hpp" |
12 | 14 | #include "../object.hpp" |
13 | 15 | #include "../time_span.hpp" |
14 | 16 | #include "../types.hpp" |
@@ -357,7 +359,7 @@ namespace xtd { |
357 | 359 | /// @remarks If this method succeeds, the rest of the thread's current time slice is yielded. The operating system schedules the calling thread for another time slice, according to its priority and the status of other threads that are available to run. |
358 | 360 | /// @remarks yielding is limited to the processor that is executing the calling thread. The operating system will not switch execution to another processor, even if that processor is idle or is running a thread of lower priority. If there are no other threads that are ready to execute on the current processor, the operating system does not yield execution, and this method returns false. |
359 | 361 | /// @remarks This method is equivalent to using platform invoke to call the native Win32 switch_to_thread function. You should call the xtd::threading::thread::yield method instead of using platform invoke, because platform invoke bypasses any custom threading behavior the host has requested. |
360 | | - static bool yield(); |
| 362 | + static bool yield() noexcept; |
361 | 363 | /// @} |
362 | 364 |
|
363 | 365 | /// @cond |
@@ -419,5 +421,159 @@ namespace xtd { |
419 | 421 | xtd::sptr<data> data_; |
420 | 422 | static intptr main_thread_id_; |
421 | 423 | }; |
| 424 | + |
| 425 | + /// @brief The xtd::threading::this_thread namespace contains some current thread properties and sheduling methods. |
| 426 | + namespace this_thread { |
| 427 | + /// @name Public Static Properties |
| 428 | + |
| 429 | + /// @{ |
| 430 | + /// @brief Gets the thread handle of the current thread. |
| 431 | + /// @return The thread handle of the current thread. |
| 432 | + /// @par Header |
| 433 | + /// ```cpp |
| 434 | + /// #include <xtd/threading/thread> |
| 435 | + /// ``` |
| 436 | + /// @par Namespace |
| 437 | + /// xtd |
| 438 | + /// @par Library |
| 439 | + /// xtd.core |
| 440 | + /// @ingroup xtd_core threading |
| 441 | + xtd::intptr handle() noexcept; |
| 442 | + |
| 443 | + /// @brief Gets the managed thread id of the current thread. |
| 444 | + /// @return The managed thread id of the current thread. |
| 445 | + /// @par Header |
| 446 | + /// ```cpp |
| 447 | + /// #include <xtd/threading/thread> |
| 448 | + /// ``` |
| 449 | + /// @par Namespace |
| 450 | + /// xtd |
| 451 | + /// @par Library |
| 452 | + /// xtd.core |
| 453 | + /// @ingroup xtd_core threading |
| 454 | + xtd::int32 managed_thread_id() noexcept; |
| 455 | + |
| 456 | + /// @brief Gets the thread name of the current thread. |
| 457 | + /// @return The thread name of the current thread. |
| 458 | + /// @par Header |
| 459 | + /// ```cpp |
| 460 | + /// #include <xtd/threading/thread> |
| 461 | + /// ``` |
| 462 | + /// @par Namespace |
| 463 | + /// xtd |
| 464 | + /// @par Library |
| 465 | + /// xtd.core |
| 466 | + /// @ingroup xtd_core threading |
| 467 | + xtd::string name() noexcept; |
| 468 | + /// @brief Sets the thread name of the current thread. |
| 469 | + /// @param name The thread name of the current thread. |
| 470 | + /// @par Header |
| 471 | + /// ```cpp |
| 472 | + /// #include <xtd/threading/thread> |
| 473 | + /// ``` |
| 474 | + /// @par Namespace |
| 475 | + /// xtd |
| 476 | + /// @par Library |
| 477 | + /// xtd.core |
| 478 | + /// @ingroup xtd_core threading |
| 479 | + void name(const xtd::string& name); |
| 480 | + |
| 481 | + /// @brief Gets the thread priority of the current thread. |
| 482 | + /// @return The thread priority of the current thread. |
| 483 | + /// @par Header |
| 484 | + /// ```cpp |
| 485 | + /// #include <xtd/threading/thread> |
| 486 | + /// ``` |
| 487 | + /// @par Namespace |
| 488 | + /// xtd |
| 489 | + /// @par Library |
| 490 | + /// xtd.core |
| 491 | + /// @ingroup xtd_core threading |
| 492 | + xtd::threading::thread_priority priority() noexcept; |
| 493 | + /// @brief Sets the thread priority of the current thread. |
| 494 | + /// @param priority The thread priority of the current thread. |
| 495 | + /// @par Header |
| 496 | + /// ```cpp |
| 497 | + /// #include <xtd/threading/thread> |
| 498 | + /// ``` |
| 499 | + /// @par Namespace |
| 500 | + /// xtd |
| 501 | + /// @par Library |
| 502 | + /// xtd.core |
| 503 | + /// @ingroup xtd_core threading |
| 504 | + void priority(xtd::threading::thread_priority priority); |
| 505 | + |
| 506 | + /// @brief Gets the thread id of the current thread. |
| 507 | + /// @return The thread id of the current thread. |
| 508 | + /// @par Header |
| 509 | + /// ```cpp |
| 510 | + /// #include <xtd/threading/thread> |
| 511 | + /// ``` |
| 512 | + /// @par Namespace |
| 513 | + /// xtd |
| 514 | + /// @par Library |
| 515 | + /// xtd.core |
| 516 | + /// @ingroup xtd_core threading |
| 517 | + xtd::intptr thread_id() noexcept; |
| 518 | + /// @} |
| 519 | + |
| 520 | + /// @name Public Static Methods |
| 521 | + |
| 522 | + /// @{ |
| 523 | + /// @brief Returns the thread id of the current thread. |
| 524 | + /// @return The thread id of the current thread. |
| 525 | + /// @par Header |
| 526 | + /// ```cpp |
| 527 | + /// #include <xtd/threading/thread> |
| 528 | + /// ``` |
| 529 | + /// @par Namespace |
| 530 | + /// xtd |
| 531 | + /// @par Library |
| 532 | + /// xtd.core |
| 533 | + /// @ingroup xtd_core threading |
| 534 | + xtd::intptr get_id() noexcept; |
| 535 | + |
| 536 | + /// @brief Stops the execution of the current thread for a specified time duration. |
| 537 | + /// @param sleep_duration The time duration to sleep. |
| 538 | + /// @remarks Blocks the execution of the current thread for at least the specified `sleep_duration`. |
| 539 | + /// @par Header |
| 540 | + /// ```cpp |
| 541 | + /// #include <xtd/threading/thread> |
| 542 | + /// ``` |
| 543 | + /// @par Namespace |
| 544 | + /// xtd |
| 545 | + /// @par Library |
| 546 | + /// xtd.core |
| 547 | + /// @ingroup xtd_core threading |
| 548 | + void sleep_for(const xtd::time_span& sleep_duration); |
| 549 | + |
| 550 | + /// @brief Stops the execution of the current thread until a specified time point. |
| 551 | + /// @param sleep_time The time to block until. |
| 552 | + /// @remarks Blocks the execution of the current thread until specified `sleep_time` has been reached. |
| 553 | + /// @par Header |
| 554 | + /// ```cpp |
| 555 | + /// #include <xtd/threading/thread> |
| 556 | + /// ``` |
| 557 | + /// @par Namespace |
| 558 | + /// xtd |
| 559 | + /// @par Library |
| 560 | + /// xtd.core |
| 561 | + /// @ingroup xtd_core threading |
| 562 | + void sleep_until(const xtd::date_time& sleep_time); |
| 563 | + |
| 564 | + /// @brief Suggests that the implementation reschedule execution of threads. |
| 565 | + /// @return true if the operating system switched execution to another thread; otherwise, false. |
| 566 | + /// @par Header |
| 567 | + /// ```cpp |
| 568 | + /// #include <xtd/threading/thread> |
| 569 | + /// ``` |
| 570 | + /// @par Namespace |
| 571 | + /// xtd |
| 572 | + /// @par Library |
| 573 | + /// xtd.core |
| 574 | + /// @ingroup xtd_core threading |
| 575 | + bool yield() noexcept; |
| 576 | + /// @} |
| 577 | + } |
422 | 578 | } |
423 | 579 | } |
0 commit comments