arch.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * @Author: jiejie
  3. * @Github: https://github.com/jiejieTop
  4. * @Date: 2019-12-26 19:11:37
  5. * @LastEditTime: 2020-02-25 04:01:18
  6. * @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
  7. */
  8. #include "salof_defconfig.h"
  9. #ifdef SALOF_USING_LOG
  10. void *salof_alloc(unsigned int size)
  11. {
  12. return malloc((size_t)size);
  13. }
  14. void salof_free(void *mem)
  15. {
  16. free(mem);
  17. }
  18. salof_tcb salof_task_create(const char *name,
  19. void (*task_entry)(void *param),
  20. void * const param,
  21. unsigned int stack_size,
  22. unsigned int priority,
  23. unsigned int tick)
  24. {
  25. int res;
  26. salof_tcb task;
  27. void *(*__start_routine) (void *);
  28. __start_routine = (void *(*)(void*))task_entry;
  29. task = salof_alloc(sizeof(pthread_t));
  30. res = pthread_create(task, NULL, __start_routine, param);
  31. if(res != 0) {
  32. salof_free(task);
  33. }
  34. return task;
  35. }
  36. salof_mutex salof_mutex_create(void)
  37. {
  38. salof_mutex mutex;
  39. mutex = salof_alloc(sizeof(pthread_mutex_t));
  40. if (NULL != mutex)
  41. pthread_mutex_init(mutex, NULL);
  42. return mutex;
  43. }
  44. void salof_mutex_delete(salof_mutex mutex)
  45. {
  46. pthread_mutex_destroy(mutex);
  47. }
  48. int salof_mutex_pend(salof_mutex mutex, unsigned int timeout)
  49. {
  50. if (timeout == 0)
  51. return pthread_mutex_trylock(mutex);
  52. return pthread_mutex_lock(mutex);
  53. }
  54. int salof_mutex_post(salof_mutex mutex)
  55. {
  56. return pthread_mutex_unlock(mutex);
  57. }
  58. salof_sem salof_sem_create(void)
  59. {
  60. salof_sem sem;
  61. sem = salof_alloc(sizeof(sem_t));
  62. if (NULL != sem)
  63. sem_init(sem, 0, 0);
  64. return sem;
  65. }
  66. void salof_sem_delete(salof_sem sem)
  67. {
  68. sem_destroy(sem);
  69. }
  70. int salof_sem_pend(salof_sem sem, unsigned int timeout)
  71. {
  72. (void) timeout;
  73. return sem_wait(sem);
  74. }
  75. int salof_sem_post(salof_sem sem)
  76. {
  77. return sem_post(sem);
  78. }
  79. unsigned int salof_get_tick(void)
  80. {
  81. return (unsigned int)time(NULL);
  82. }
  83. char *salof_get_task_name(void)
  84. {
  85. return NULL;
  86. }
  87. int send_buff(char *buf, int len)
  88. {
  89. fputs(buf, stdout);
  90. fflush(stdout);
  91. return len;
  92. }
  93. #endif