win_thread.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _GNU_SOURCE
  6. #define _GNU_SOURCE
  7. #endif
  8. #include "platform_api_vmcore.h"
  9. #include "platform_api_extension.h"
  10. typedef struct {
  11. thread_start_routine_t start;
  12. void* stack;
  13. uint32 stack_size;
  14. void* arg;
  15. } thread_wrapper_arg;
  16. static void *os_thread_wrapper(void *arg)
  17. {
  18. thread_wrapper_arg * targ = arg;
  19. thread_start_routine_t start_func = targ->start;
  20. void *thread_arg = targ->arg;
  21. os_printf("THREAD CREATED %p\n", &targ);
  22. targ->stack = (void *)((uintptr_t)(&arg) & (uintptr_t)~0xfff);
  23. BH_FREE(targ);
  24. start_func(thread_arg);
  25. return NULL;
  26. }
  27. int os_thread_create_with_prio(korp_tid *tid, thread_start_routine_t start,
  28. void *arg, unsigned int stack_size, int prio)
  29. {
  30. return BHT_ERROR;
  31. }
  32. int os_thread_create(korp_tid *tid, thread_start_routine_t start, void *arg,
  33. unsigned int stack_size)
  34. {
  35. return os_thread_create_with_prio(tid, start, arg, stack_size,
  36. BH_THREAD_DEFAULT_PRIORITY);
  37. }
  38. korp_tid os_self_thread()
  39. {
  40. return NULL;
  41. }
  42. int os_mutex_init(korp_mutex *mutex)
  43. {
  44. return BHT_OK;
  45. }
  46. int os_recursive_mutex_init(korp_mutex *mutex)
  47. {
  48. return BHT_OK;
  49. }
  50. int os_mutex_destroy(korp_mutex *mutex)
  51. {
  52. return BHT_OK;
  53. }
  54. /* Returned error (EINVAL, EAGAIN and EDEADLK) from
  55. locking the mutex indicates some logic error present in
  56. the program somewhere.
  57. Don't try to recover error for an existing unknown error.*/
  58. int os_mutex_lock(korp_mutex *mutex)
  59. {
  60. return BHT_ERROR;
  61. }
  62. /* Returned error (EINVAL, EAGAIN and EPERM) from
  63. unlocking the mutex indicates some logic error present
  64. in the program somewhere.
  65. Don't try to recover error for an existing unknown error.*/
  66. int os_mutex_unlock(korp_mutex *mutex)
  67. {
  68. return BHT_OK;
  69. }
  70. int os_cond_init(korp_cond *cond)
  71. {
  72. return BHT_OK;
  73. }
  74. int os_cond_destroy(korp_cond *cond)
  75. {
  76. return BHT_OK;
  77. }
  78. int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
  79. {
  80. return BHT_OK;
  81. }
  82. int gettimeofday(struct timeval * tp, struct timezone * tzp)
  83. {
  84. // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
  85. // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
  86. // until 00:00:00 January 1, 1970
  87. static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
  88. SYSTEMTIME system_time;
  89. FILETIME file_time;
  90. uint64_t time;
  91. GetSystemTime( &system_time );
  92. SystemTimeToFileTime( &system_time, &file_time );
  93. time = ((uint64_t)file_time.dwLowDateTime ) ;
  94. time += ((uint64_t)file_time.dwHighDateTime) << 32;
  95. tp->tv_sec = (long) ((time - EPOCH) / 10000000L);
  96. tp->tv_usec = (long) (system_time.wMilliseconds * 1000);
  97. return 0;
  98. }
  99. static void msec_nsec_to_abstime(struct timespec *ts, int usec)
  100. {
  101. struct timeval tv;
  102. gettimeofday(&tv, NULL);
  103. ts->tv_sec = (long int)(tv.tv_sec + usec / 1000000);
  104. ts->tv_nsec = (long int)(tv.tv_usec * 1000 + (usec % 1000000) * 1000);
  105. if (ts->tv_nsec >= 1000000000L) {
  106. ts->tv_sec++;
  107. ts->tv_nsec -= 1000000000L;
  108. }
  109. }
  110. int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int useconds)
  111. {
  112. return BHT_OK;
  113. }
  114. int os_cond_signal(korp_cond *cond)
  115. {
  116. return BHT_OK;
  117. }
  118. int os_thread_join(korp_tid thread, void **value_ptr)
  119. {
  120. return BHT_OK;
  121. }
  122. int os_thread_detach(korp_tid thread)
  123. {
  124. return BHT_OK;
  125. }
  126. void os_thread_exit(void *retval)
  127. {
  128. return BHT_OK;
  129. }
  130. uint8 *os_thread_get_stack_boundary()
  131. {
  132. return NULL;
  133. }