1/* 2 * Copyright 2007 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Niels Sascha Reedijk, niels.reedijk@gmail.com 7 * 8 * Corresponds to: 9 * headers/os/support/SupportDefs.h rev 35018 10 */ 11 12 13/*! 14 \file SupportDefs.h 15 \ingroup support 16 \ingroup libbe 17 \brief Defines basic types and definitions for the Haiku API. 18*/ 19 20 21/*! 22 \name Fixed-Size Integer Types 23*/ 24 25 26//! @{ 27 28 29/*! 30 \typedef typedef __haiku_int8 int8 31*/ 32 33 34/*! 35 \typedef typedef __haiku_uint8 uint8 36*/ 37 38 39/*! 40 \typedef typedef __haiku_int16 int16 41*/ 42 43 44/*! 45 \typedef typedef __haiku_uint16 uint16 46*/ 47 48 49/*! 50 \typedef typedef __haiku_int32 int32 51*/ 52 53 54/*! 55 \typedef typedef __haiku_uint32 uint32 56*/ 57 58 59/*! 60 \typedef typedef __haiku_int64 int64 61*/ 62 63 64/*! 65 \typedef typedef __haiku_uint64 uint64 66*/ 67 68 69//! @} 70 71 72/*! 73 \name Fixed-size Volatile Types 74*/ 75 76 77//! @{ 78 79 80/*! 81 \typedef typedef volatile int8 vint8 82*/ 83 84 85/*! 86 \typedef typedef volatile uint8 vuint8 87*/ 88 89 90/*! 91 \typedef typedef volatile int16 vint16 92*/ 93 94 95/*! 96 \typedef typedef volatile uint16 vuint16 97*/ 98 99 100/*! 101 \typedef typedef volatile int32 vint32 102*/ 103 104 105/*! 106 \typedef typedef volatile uint32 vuint32 107*/ 108 109 110/*! 111 \typedef typedef volatile int64 vint64 112*/ 113 114 115/*! 116 \typedef typedef volatile uint64 vuint64 117*/ 118 119 120//! @} 121 122 123/*! 124 \name Short-hand Volatile Type Names 125*/ 126 127 128//! @{ 129 130 131/*! 132 \typedef typedef volatile long vlong 133*/ 134 135 136/*! 137 \typedef typedef volatile int vint 138*/ 139 140 141/*! 142 \typedef typedef volatile short vshort 143*/ 144 145 146/*! 147 \typedef typedef volatile char vchar 148*/ 149 150 151/*! 152 \typedef typedef volatile unsigned long vulong 153*/ 154 155 156/*! 157 \typedef typedef volatile unsigned int vuint 158*/ 159 160 161/*! 162 \typedef typedef volatile unsigned short vushort 163*/ 164 165 166/*! 167 \typedef typedef volatile unsigned char vuchar 168*/ 169 170 171//! @} 172 173 174/*! 175 \name Character Type Formats 176*/ 177 178 179//! @{ 180 181 182/*! 183 \typedef typedef unsigned char uchar 184*/ 185 186 187/*! 188 \typedef typedef unsigned short unichar 189*/ 190 191 192//! @} 193 194 195/*! 196 \name Descriptive Type Formats 197*/ 198 199 200//! @{ 201 202 203/*! 204 \typedef typedef int32 status_t 205 \brief Represents one of the status codes defined in Error.h 206*/ 207 208 209/*! 210 \typedef typedef int64 bigtime_t 211 \brief Represents time. The unit depends on the context of the function. 212*/ 213 214 215/*! 216 \typedef typedef int64 nanotime_t 217 \brief Represents time in nanoseconds. 218*/ 219 220 221/*! 222 \typedef typedef uint32 type_code 223 \brief Represents a certain type of data. See TypeConstants.h for 224 possible values. 225*/ 226 227 228/*! 229 \typedef typedef uint32 perform_code 230 \brief Defined to support 'hidden' commands or extensions to classes. 231 232 The Haiku API has none of these. 233*/ 234 235 236//! @} 237 238 239/*! 240 \name Format strings for printf() and scanf() 241*/ 242 243 244//! @{ 245 246 247/*! 248 \def B_PRId8 249*/ 250 251 252/*! 253 \def B_PRIi8 254*/ 255 256 257/*! 258 \def B_PRId16 259*/ 260 261 262/*! 263 \def B_PRIi16 264*/ 265 266 267/*! 268 \def B_PRId32 269*/ 270 271 272/*! 273 \def B_PRIi32 274*/ 275 276 277/*! 278 \def B_PRId64 279*/ 280 281 282/*! 283 \def B_PRIi64 284*/ 285 286 287/*! 288 \def B_PRIu8 289*/ 290 291 292/*! 293 \def B_PRIo8 294*/ 295 296 297/*! 298 \def B_PRIx8 299*/ 300 301 302/*! 303 \def B_PRIX8 304*/ 305 306 307/*! 308 \def B_PRIu16 309*/ 310 311 312/*! 313 \def B_PRIo16 314*/ 315 316 317/*! 318 \def B_PRIx16 319*/ 320 321 322/*! 323 \def B_PRIX16 324*/ 325 326 327/*! 328 \def B_PRIu32 329*/ 330 331 332/*! 333 \def B_PRIo32 334*/ 335 336 337/*! 338 \def B_PRIx32 339*/ 340 341 342/*! 343 \def B_PRIX32 344*/ 345 346 347/*! 348 \def B_PRIu64 349*/ 350 351 352/*! 353 \def B_PRIo64 354*/ 355 356 357/*! 358 \def B_PRIx64 359*/ 360 361 362/*! 363 \def B_PRIX64 364*/ 365 366 367/*! 368 \def B_SCNd8 369*/ 370 371 372/*! 373 \def B_SCNi8 374*/ 375 376 377/*! 378 \def B_SCNd16 379*/ 380 381 382/*! 383 \def B_SCNi16 384*/ 385 386 387/*! 388 \def B_SCNd32 389*/ 390 391 392/*! 393 \def B_SCNi32 394*/ 395 396 397/*! 398 \def B_SCNd64 399*/ 400 401 402/*! 403 \def B_SCNi64 404*/ 405 406 407/*! 408 \def B_SCNu8 409*/ 410 411 412/*! 413 \def B_SCNo8 414*/ 415 416 417/*! 418 \def B_SCNx8 419*/ 420 421 422/*! 423 \def B_SCNu16 424*/ 425 426 427/*! 428 \def B_SCNo16 429*/ 430 431 432/*! 433 \def B_SCNx16 434*/ 435 436 437/*! 438 \def B_SCNu32 439*/ 440 441 442/*! 443 \def B_SCNo32 444*/ 445 446 447/*! 448 \def B_SCNx32 449*/ 450 451 452/*! 453 \def B_SCNu64 454*/ 455 456 457/*! 458 \def B_SCNo64 459*/ 460 461 462/*! 463 \def B_SCNx64 464*/ 465 466 467//! @} 468 469 470/*! 471 \name Format strings for several standard types 472*/ 473 474 475//! @{ 476 477 478/*! 479 \def B_PRIuSIZE 480 \brief size_t 481*/ 482 483 484/*! 485 \def B_PRIoSIZE 486 \brief size_t 487*/ 488 489 490/*! 491 \def B_PRIxSIZE 492 \brief size_t 493*/ 494 495 496/*! 497 \def B_PRIXSIZE 498 \brief size_t 499*/ 500 501 502/*! 503 \def B_PRIdSSIZE 504 \brief ssize_t 505*/ 506 507 508/*! 509 \def B_PRIiSSIZE 510 \brief ssize_t 511*/ 512 513 514/*! 515 \def B_PRIuADDR 516 \brief addr_t 517*/ 518 519 520/*! 521 \def B_PRIoADDR 522 \brief addr_t 523*/ 524 525 526/*! 527 \def B_PRIxADDR 528 \brief addr_t 529*/ 530 531 532/*! 533 \def B_PRIXADDR 534 \brief addr_t 535*/ 536 537 538/*! 539 \def B_PRIdOFF 540 \brief off_t 541*/ 542 543 544/*! 545 \def B_PRIiOFF 546 \brief off_t 547*/ 548 549 550/*! 551 \def B_PRIdDEV 552 \brief dev_t 553*/ 554 555 556/*! 557 \def B_PRIiDEV 558 \brief dev_t 559*/ 560 561 562/*! 563 \def B_PRIdINO 564 \brief ino_t 565*/ 566 567 568/*! 569 \def B_PRIiINO 570 \brief ino_t 571*/ 572 573 574/*! 575 \def B_PRIdTIME 576 \brief time_t 577*/ 578 579 580/*! 581 \def B_PRIiTIME 582 \brief time_t 583*/ 584 585 586//! @} 587 588 589//////////////// Odds and ends 590 591 592/*! 593 \var const char *B_EMPTY_STRING 594 \brief Defines an empty string. Currently defined as the string "". 595*/ 596 597 598/*! 599 \def min_c(a,b) 600 \brief Returns the minimum of the values a and b. 601 602 \note When including this header in a C file, use the C equivalent called 603 \c min(a,b). 604*/ 605 606 607/*! 608 \def max_c(a,b) 609 \brief Returns the maximum of values a and b. 610 611 \note When including this header in a C file, use the C equivalent called 612 \c max(a,b). 613*/ 614 615 616/*! 617 \def NULL 618 \brief Defines the constant \c NULL if it hasn't already been defined. 619*/ 620 621 622/*! 623 \addtogroup support_globals 624*/ 625 626 627//! @{ 628 629 630/*! \fn int32 atomic_set(vint32 *value, int32 newValue) 631 \brief Atomically set the variable \a value to \a newvalue. 632 633 This is a thread-safe way of performing the \c *value \c = \c newValue 634 operation. You should use these function when two or more threads might 635 access the variable simultaneously. You don't have to use a semaphore or a 636 mutex in this case. 637 638 \return The original value of \c value. 639 640 \sa atomic_set64() for a version that works on \c long \c long. 641 \sa atomic_test_and_set() 642 \sa atomic_add() 643 \sa atomic_and() 644 \sa atomic_or(), 645 \sa atomic_get() 646*/ 647 648 649/*! \fn int32 atomic_test_and_set(vint32 *value, int32 newValue, 650 int32 testAgainst) 651 \brief Atomically set the variable \a value to \a newValue if the current 652 value is \a testAgainst. 653 654 This is a thread-safe way of conditionally performing the \c *value \c += 655 \c newValue operation. You should use these function when two or more 656 threads might access the variable simultaneously. You don't have to use 657 a semaphore or a mutex in this case. 658 659 \return The original value of \c value. 660 661 \sa atomic_test_and_set64() for a version that works on \c long \c long. 662 \sa atomic_set() 663 \sa atomic_add() 664 \sa atomic_and() 665 \sa atomic_or() 666 \sa atomic_get() 667*/ 668 669 670/*! 671 \fn int32 atomic_add(vint32 *value, int32 addValue) 672 \brief Atomically add the value of \a addValue to \a value. 673 674 This is a thread-safe way of performing the \c *value \c += \c addValue 675 operation. You should use these function when two or more threads might 676 access the variable simultaneously. You don't have to use a semaphore or a 677 mutex in this case. 678 679 \return The original value of \c value. 680 681 \sa atomic_add64() for a version that works on \c long \c long. 682 \sa atomic_set() 683 \sa atomic_test_and_set() 684 \sa atomic_and() 685 \sa atomic_or() 686 \sa atomic_get() 687*/ 688 689 690/*! \fn int32 atomic_and(vint32 *value, int32 andValue) 691 \brief Atomically perform a bitwise AND operation of \a andValue to the 692 variable \a andValue. 693 694 This is a thread-safe way of performing the \c *value \c &= \c andValue 695 operation. You should use these function when two or more threads might 696 access the variable simultaneously. You don't have to use a semaphore or a 697 mutex in this case. 698 699 \return The original value of \c value. 700 701 \sa atomic_and64() for a version that works on \c long \c long. 702 \sa atomic_set() 703 \sa atomic_test_and_set() 704 \sa atomic_add() 705 \sa atomic_or() 706 \sa atomic_get() 707*/ 708 709 710 711/*! 712 \fn int32 atomic_or(vint32 *value, int32 orValue) 713 \brief Atomically perform a bitwise OR operation of \a orValue to the 714 variable \a andValue. 715 716 This is a thread-safe way of performing the \c *value \c |= \c orValue 717 operation. You should use these function when two or more threads might 718 access the variable simultaneously. You don't have to use a semaphore or a 719 mutex in this case. 720 721 \return The original value of \c value. 722 723 \sa atomic_or64() for a version that works on \c long \c long. 724 \sa atomic_set() 725 \sa atomic_test_and_set() 726 \sa atomic_add() 727 \sa atomic_and() 728 \sa atomic_get() 729*/ 730 731 732/*! 733 \fn int32 atomic_get(vint32 *value) 734 \brief Atomically return the value of \c value. 735 736 This is a thread-safe way of reading the contents of the \c value 737 operation. You should use these function when two or more threads might 738 access the variable simultaneously. You don't have to use a semaphore or a 739 mutex in this case. 740 741 \return The original value of \c value. 742 743 \sa atomic_get64() for a version that works on \c long \c long. 744 \sa atomic_set() 745 \sa atomic_test_and_set() 746 \sa atomic_add() 747 \sa atomic_and() 748 \sa atomic_or() 749*/ 750 751 752/*! 753 \fn int64 atomic_set64(vint64 *value, int64 newValue) 754 \brief Atomically set the variable \a value to \a newvalue. 755 756 This is a thread-safe way of performing the \c *value \c = \c newValue 757 operation. You should use these function when two or more threads might 758 access the variable simultaneously. You don't have to use a semaphore or a 759 mutex in this case. 760 761 \return The original value of \c value. 762 763 \sa atomic_set() for a version that works on an \c int32. 764 \sa atomic_test_and_set64() 765 \sa atomic_add64() 766 \sa atomic_and64() 767 \sa atomic_or64() 768 \sa atomic_get64() 769*/ 770 771 772/*! 773 \fn int64 atomic_test_and_set64(vint64 *value, int64 newValue, 774 int64 testAgainst) 775 \brief Atomically set the variable \a value to \a newValue if the current 776 value is \a testAgainst. 777 778 This is a thread-safe way of conditionally performing the \c *value 779 \c += \c newValue operation. You should use these function when two 780 or more threads might access the variable simultaneously. You don't 781 have to use a semaphore or a mutex in this case. 782 783 \return The original value of \c value. 784 785 \sa atomic_test_and_set() for a version that works on an \c int32. 786 \sa atomic_set64() 787 \sa atomic_add64() 788 \sa atomic_and64() 789 \sa atomic_or64() 790 \sa atomic_get64() 791*/ 792 793 794/*! 795 \fn int64 atomic_add64(vint64 *value, int64 addValue) 796 \brief Atomically add the value of \a addValue to \a value. 797 798 This is a thread-safe way of performing the \c *value \c += \c addValue 799 operation. You should use these function when two or more threads might 800 access the variable simultaneously. You don't have to use a semaphore or a 801 mutex in this case. 802 803 \return The original value of \c value. 804 805 \sa atomic_add() for a version that works on an \c int32. 806 \sa atomic_set64() 807 \sa atomic_test_and_set64() 808 \sa atomic_and64() 809 \sa atomic_or64() 810 \sa atomic_get64() 811*/ 812 813 814/*! 815 \fn int64 atomic_and64(vint64 *value, int64 andValue) 816 \brief Atomically perform a bitwise AND operation of \a andValue to the 817 variable \a andValue. 818 819 This is a thread-safe way of performing the \c *value \c &= \c andValue 820 operation. You should use these function when two or more threads might 821 access the variable simultaneously. You don't have to use a semaphore or a 822 mutex in this case. 823 824 \return The original value of \c value. 825 826 \sa atomic_and() for a version that works on an \c int32. 827 \sa atomic_set64() 828 \sa atomic_test_and_set64() 829 \sa atomic_add64() 830 \sa atomic_or64() 831 \sa atomic_get64() 832*/ 833 834 835/*! \fn int64 atomic_or64(vint64 *value, int64 orValue) 836 \brief Atomically perform a bitwise OR operation of \a orValue to the 837 variable \a andValue. 838 839 This is a thread-safe way of performing the \c *value \c |= \c orValue 840 operation. You should use these function when two or more threads might 841 access the variable simultaneously. You don't have to use a semaphore or a 842 mutex in this case. 843 844 \return The original value of \c value. 845 846 \sa atomic_or() for a version that works on an \c int32. 847 \sa atomic_set64() 848 \sa atomic_test_and_set64() 849 \sa atomic_add64() 850 \sa atomic_and64() 851 \sa atomic_get64() 852*/ 853 854 855/*! 856 \fn int64 atomic_get64(vint64 *value) 857 \brief Atomically return the value of \c value. 858 859 This is a thread-safe way of reading the contents of the \c value 860 operation. You should use these function when two or more threads might 861 access the variable simultaneously. You don't have to use a semaphore or a 862 mutex in this case. 863 864 \return The original value of \c value. 865 866 \sa atomic_get() for a version that works on an \c int32. 867 \sa atomic_set64() 868 \sa atomic_test_and_set64() 869 \sa atomic_add64() 870 \sa atomic_and64() 871 \sa atomic_or64() 872*/ 873 874 875//! @} 876 877 878/*! 879 \fn void* get_stack_frame(void) 880 \brief Internal function. 881 \internal 882*/ 883 884 885/*! 886 \name Deprecated defines 887*/ 888 889 890//! @{ 891 892 893/*! 894 \def FALSE 895 \brief Obsolete. Use \c false. 896*/ 897 898 899/*! 900 \def TRUE 901 \brief Obsolete. Use \c true. 902*/ 903 904 905//! @} 906