Açıklama Yok
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.

mythreads.h 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. double Time_GetSeconds() {
  8. struct timeval t;
  9. int rc = gettimeofday(&t, NULL);
  10. assert(rc == 0);
  11. return (double) ((double)t.tv_sec + (double)t.tv_usec / 1e6);
  12. }
  13. void Pthread_mutex_init(pthread_mutex_t *mutex,
  14. const pthread_mutexattr_t *attr) {
  15. int rc = pthread_mutex_init(mutex, attr);
  16. assert(rc == 0);
  17. }
  18. void Pthread_mutex_lock(pthread_mutex_t *m) {
  19. int rc = pthread_mutex_lock(m);
  20. assert(rc == 0);
  21. }
  22. void Pthread_mutex_unlock(pthread_mutex_t *m) {
  23. int rc = pthread_mutex_unlock(m);
  24. assert(rc == 0);
  25. }
  26. void Pthread_cond_init(pthread_cond_t *cond,
  27. const pthread_condattr_t *attr) {
  28. int rc = pthread_cond_init(cond, attr);
  29. assert(rc == 0);
  30. }
  31. void Pthread_cond_wait(pthread_cond_t *cond,
  32. pthread_mutex_t *mutex) {
  33. int rc = pthread_cond_wait(cond, mutex);
  34. assert(rc == 0);
  35. }
  36. void Pthread_cond_signal(pthread_cond_t *cond) {
  37. int rc = pthread_cond_signal(cond);
  38. assert(rc == 0);
  39. }
  40. void Pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  41. void *(*start_routine)(void*), void *arg) {
  42. int rc = pthread_create(thread, attr, start_routine, arg);
  43. assert(rc == 0);
  44. }
  45. void Pthread_join(pthread_t thread, void **value_ptr) {
  46. int rc = pthread_join(thread, value_ptr);
  47. assert(rc == 0);
  48. }
  49. #endif // __MYTHREADS_h__