win_thread.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. int os_mutex_lock(korp_mutex *mutex)
  55. {
  56. return BHT_ERROR;
  57. }
  58. int os_mutex_unlock(korp_mutex *mutex)
  59. {
  60. return BHT_OK;
  61. }
  62. int os_cond_init(korp_cond *cond)
  63. {
  64. return BHT_OK;
  65. }
  66. int os_cond_destroy(korp_cond *cond)
  67. {
  68. return BHT_OK;
  69. }
  70. int os_cond_wait(korp_cond *cond, korp_mutex *mutex)
  71. {
  72. return BHT_OK;
  73. }
  74. int gettimeofday(struct timeval * tp, struct timezone * tzp)
  75. {
  76. /* Note: some broken versions only have 8 trailing zero's,
  77. the correct epoch has 9 trailing zero's
  78. This magic number is the number of 100 nanosecond intervals
  79. since January 1, 1601 (UTC) until 00:00:00 January 1, 1970 */
  80. static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL);
  81. SYSTEMTIME system_time;
  82. FILETIME file_time;
  83. uint64_t time;
  84. GetSystemTime(&system_time);
  85. SystemTimeToFileTime(&system_time, &file_time);
  86. time = ((uint64_t)file_time.dwLowDateTime);
  87. time += ((uint64_t)file_time.dwHighDateTime) << 32;
  88. tp->tv_sec = (long)((time - EPOCH) / 10000000L);
  89. tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
  90. return 0;
  91. }
  92. static void msec_nsec_to_abstime(struct timespec *ts, int usec)
  93. {
  94. struct timeval tv;
  95. gettimeofday(&tv, NULL);
  96. ts->tv_sec = (long int)(tv.tv_sec + usec / 1000000);
  97. ts->tv_nsec = (long int)(tv.tv_usec * 1000 + (usec % 1000000) * 1000);
  98. if (ts->tv_nsec >= 1000000000L) {
  99. ts->tv_sec++;
  100. ts->tv_nsec -= 1000000000L;
  101. }
  102. }
  103. int os_cond_reltimedwait(korp_cond *cond, korp_mutex *mutex, int useconds)
  104. {
  105. return BHT_OK;
  106. }
  107. int os_cond_signal(korp_cond *cond)
  108. {
  109. return BHT_OK;
  110. }
  111. int os_thread_join(korp_tid thread, void **value_ptr)
  112. {
  113. return BHT_OK;
  114. }
  115. int os_thread_detach(korp_tid thread)
  116. {
  117. return BHT_OK;
  118. }
  119. void os_thread_exit(void *retval)
  120. {
  121. }
  122. uint8 *os_thread_get_stack_boundary()
  123. {
  124. return NULL;
  125. }