pthread.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <stdlib.h>
  6. #include <pthread.h>
  7. int
  8. ocall_pthread_rwlock_init(void **rwlock, void *attr)
  9. {
  10. int ret = 0;
  11. *rwlock = malloc(sizeof(pthread_rwlock_t));
  12. if (*rwlock == NULL)
  13. return -1;
  14. ret = pthread_rwlock_init((pthread_rwlock_t *)*rwlock, NULL);
  15. if (ret != 0) {
  16. free(*rwlock);
  17. *rwlock = NULL;
  18. }
  19. (void)attr;
  20. return ret;
  21. }
  22. int
  23. ocall_pthread_rwlock_destroy(void *rwlock)
  24. {
  25. pthread_rwlock_t *lock = (pthread_rwlock_t *)rwlock;
  26. int ret;
  27. ret = pthread_rwlock_destroy(lock);
  28. free(lock);
  29. return ret;
  30. }
  31. int
  32. ocall_pthread_rwlock_rdlock(void *rwlock)
  33. {
  34. return pthread_rwlock_rdlock((pthread_rwlock_t *)rwlock);
  35. }
  36. int
  37. ocall_pthread_rwlock_wrlock(void *rwlock)
  38. {
  39. return pthread_rwlock_wrlock((pthread_rwlock_t *)rwlock);
  40. }
  41. int
  42. ocall_pthread_rwlock_unlock(void *rwlock)
  43. {
  44. return pthread_rwlock_unlock((pthread_rwlock_t *)rwlock);
  45. }