affinity.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "nspr.h"
  6. #include "pprthred.h"
  7. #include "plgetopt.h"
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. /*
  12. * Test PR_GetThreadAffinityMask
  13. * The function is called by each of local, global and global bound threads
  14. * The test should be run on both single and multi-cpu systems
  15. */
  16. static void PR_CALLBACK thread_start(void *arg)
  17. {
  18. PRUint32 mask = 0;
  19. if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) {
  20. printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n");
  21. }
  22. else {
  23. printf("\tthread_start: AffinityMask = 0x%x\n",mask);
  24. }
  25. }
  26. int main(int argc, char **argv)
  27. {
  28. PRThread *t;
  29. printf("main: creating local thread\n");
  30. t = PR_CreateThread(PR_USER_THREAD,
  31. thread_start, 0,
  32. PR_PRIORITY_NORMAL,
  33. PR_LOCAL_THREAD,
  34. PR_JOINABLE_THREAD,
  35. 0);
  36. if (NULL == t) {
  37. printf("main: cannot create local thread\n");
  38. exit(1);
  39. }
  40. PR_JoinThread(t);
  41. printf("main: creating global thread\n");
  42. t = PR_CreateThread(PR_USER_THREAD,
  43. thread_start, 0,
  44. PR_PRIORITY_NORMAL,
  45. PR_GLOBAL_THREAD,
  46. PR_JOINABLE_THREAD,
  47. 0);
  48. if (NULL == t) {
  49. printf("main: cannot create global thread\n");
  50. exit(1);
  51. }
  52. PR_JoinThread(t);
  53. printf("main: creating global bound thread\n");
  54. t = PR_CreateThread(PR_USER_THREAD,
  55. thread_start, 0,
  56. PR_PRIORITY_NORMAL,
  57. PR_GLOBAL_BOUND_THREAD,
  58. PR_JOINABLE_THREAD,
  59. 0);
  60. if (NULL == t) {
  61. printf("main: cannot create global bound thread\n");
  62. exit(1);
  63. }
  64. PR_JoinThread(t);
  65. return 0;
  66. }