Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef __MYTHREADS_h__
  2. #define __MYTHREADS_h__
  3. #include <pthread.h>
  4. #include <assert.h>
  5. #include <stdlib.h>
  6. #include <sys/time.h>
  7. void *Malloc(size_t size) {
  8. void *rc = malloc(size);
  9. assert(rc != NULL);
  10. return rc;
  11. }
  12. double Time_GetSeconds() {
  13. struct timeval t;
  14. int rc = gettimeofday(&t, NULL);
  15. assert(rc == 0);
  16. return (double) ((double)t.tv_sec + (double)t.tv_usec / 1e6);
  17. }
  18. void Pthread_mutex_init(pthread_mutex_t *mutex,
  19. const pthread_mutexattr_t *attr) {
  20. int rc = pthread_mutex_init(mutex, attr);
  21. assert(rc == 0);
  22. }
  23. void Pthread_mutex_lock(pthread_mutex_t *m) {
  24. int rc = pthread_mutex_lock(m);
  25. assert(rc == 0);
  26. }
  27. void Pthread_mutex_unlock(pthread_mutex_t *m) {
  28. int rc = pthread_mutex_unlock(m);
  29. assert(rc == 0);
  30. }
  31. void Pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  32. void *(*start_routine)(void*), void *arg) {
  33. int rc = pthread_create(thread, attr, start_routine, arg);
  34. assert(rc == 0);
  35. }
  36. void Pthread_join(pthread_t thread, void **value_ptr) {
  37. int rc = pthread_join(thread, value_ptr);
  38. assert(rc == 0);
  39. }
  40. #endif // __MYTHREADS_h__