Guest User

sheepthreads.c.diff

a guest
Sep 13th, 2012
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- sheepthreads.c.orig 2012-09-13 18:01:18.000000000 -0400
  2. +++ sheepthreads.c  2012-09-13 20:40:16.000000000 -0400
  3. @@ -48,19 +48,19 @@
  4.  /* Linux kernel calls */
  5.  extern int __clone(int (*fn)(void *), void *, int, void *);
  6.  
  7. -/* struct sem_t */
  8. +/* libc no longer provides struct _pthread_fastlock in pthread.h */
  9. +struct fastlock {
  10. +   int status;
  11. +   int spinlock;
  12. +};
  13. +
  14.  typedef struct {
  15. -   struct _pthread_fastlock __sem_lock;
  16. -   int __sem_value;
  17. -   _pthread_descr __sem_waiting;
  18. +   struct fastlock sem_lock;
  19. +   int sem_value;
  20. +   int sem_waiting;
  21.  } sem_t;
  22.  
  23.  #define SEM_VALUE_MAX 64
  24. -#define status __status
  25. -#define spinlock __spinlock
  26. -#define sem_lock __sem_lock
  27. -#define sem_value __sem_value
  28. -#define sem_waiting __sem_waiting
  29.  
  30.  /* Wait for "clone" children only (Linux 2.4+ specific) */
  31.  #ifndef __WCLONE
  32. @@ -185,13 +185,13 @@
  33.     need to make sure that the compiler has flushed everything to memory.  */
  34.  #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
  35.  
  36. -static void fastlock_init(struct _pthread_fastlock *lock)
  37. +static void fastlock_init(struct fastlock *lock)
  38.  {
  39.     lock->status = 0;
  40.     lock->spinlock = 0;
  41.  }
  42.  
  43. -static int fastlock_try_acquire(struct _pthread_fastlock *lock)
  44. +static int fastlock_try_acquire(struct fastlock *lock)
  45.  {
  46.     int res = EBUSY;
  47.     if (test_and_set(&lock->spinlock, 1) == 0) {
  48. @@ -205,14 +205,14 @@
  49.     return res;
  50.  }
  51.  
  52. -static void fastlock_acquire(struct _pthread_fastlock *lock)
  53. +static void fastlock_acquire(struct fastlock *lock)
  54.  {
  55.     MEMORY_BARRIER();
  56.     while (test_and_set(&lock->spinlock, 1))
  57.         usleep(0);
  58.  }
  59.  
  60. -static void fastlock_release(struct _pthread_fastlock *lock)
  61. +static void fastlock_release(struct fastlock *lock)
  62.  {
  63.     MEMORY_BARRIER();
  64.     lock->spinlock = 0;
  65. @@ -226,10 +226,7 @@
  66.  
  67.  int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr)
  68.  {
  69. -   fastlock_init(&mutex->__m_lock);
  70. -   mutex->__m_kind = mutex_attr ? mutex_attr->__mutexkind : PTHREAD_MUTEX_TIMED_NP;
  71. -   mutex->__m_count = 0;
  72. -   mutex->__m_owner = NULL;
  73. +   fastlock_init((struct fastlock *)mutex);
  74.     return 0;
  75.  }
  76.  
  77. @@ -240,12 +237,7 @@
  78.  
  79.  int pthread_mutex_destroy(pthread_mutex_t *mutex)
  80.  {
  81. -   switch (mutex->__m_kind) {
  82. -   case PTHREAD_MUTEX_TIMED_NP:
  83. -       return (mutex->__m_lock.__status != 0) ? EBUSY : 0;
  84. -   default:
  85. -       return EINVAL;
  86. -   }
  87. +   return (((struct fastlock *)mutex)->status != 0) ? EBUSY : 0;
  88.  }
  89.  
  90.  
  91. @@ -255,13 +247,8 @@
  92.  
  93.  int pthread_mutex_lock(pthread_mutex_t *mutex)
  94.  {
  95. -   switch (mutex->__m_kind) {
  96. -   case PTHREAD_MUTEX_TIMED_NP:
  97. -       fastlock_acquire(&mutex->__m_lock);
  98. -       return 0;
  99. -   default:
  100. -       return EINVAL;
  101. -   }
  102. +   fastlock_acquire((struct fastlock *)mutex);
  103. +   return 0;
  104.  }
  105.  
  106.  
  107. @@ -271,12 +258,7 @@
  108.  
  109.  int pthread_mutex_trylock(pthread_mutex_t *mutex)
  110.  {
  111. -   switch (mutex->__m_kind) {
  112. -   case PTHREAD_MUTEX_TIMED_NP:
  113. -       return fastlock_try_acquire(&mutex->__m_lock);
  114. -   default:
  115. -       return EINVAL;
  116. -   }
  117. +   return fastlock_try_acquire((struct fastlock *)mutex);
  118.  }
  119.  
  120.  
  121. @@ -286,13 +268,8 @@
  122.  
  123.  int pthread_mutex_unlock(pthread_mutex_t *mutex)
  124.  {
  125. -   switch (mutex->__m_kind) {
  126. -   case PTHREAD_MUTEX_TIMED_NP:
  127. -       fastlock_release(&mutex->__m_lock);
  128. -       return 0;
  129. -   default:
  130. -       return EINVAL;
  131. -   }
  132. +   fastlock_release((struct fastlock *)mutex);
  133. +   return 0;
  134.  }
  135.  
  136.  
  137. @@ -302,7 +279,6 @@
  138.  
  139.  int pthread_mutexattr_init(pthread_mutexattr_t *attr)
  140.  {
  141. -   attr->__mutexkind = PTHREAD_MUTEX_TIMED_NP;
  142.     return 0;
  143.  }
  144.  
  145. @@ -333,7 +309,7 @@
  146.     }
  147.     fastlock_init(&sem->sem_lock);
  148.     sem->sem_value = value;
  149. -   sem->sem_waiting = NULL;
  150. +   sem->sem_waiting = 0;
  151.     return 0;
  152.  }
  153.  
  154. @@ -353,7 +329,7 @@
  155.         return -1;
  156.     }
  157.     sem->sem_value = 0;
  158. -   sem->sem_waiting = NULL;
  159. +   sem->sem_waiting = 0;
  160.     return 0;
  161.  }
  162.  
  163. @@ -374,7 +350,7 @@
  164.         fastlock_release(&sem->sem_lock);
  165.         return 0;
  166.     }
  167. -   sem->sem_waiting = (struct _pthread_descr_struct *)((long)sem->sem_waiting + 1);
  168. +   sem->sem_waiting++;
  169.     while (sem->sem_value == 0) {
  170.         fastlock_release(&sem->sem_lock);
  171.         usleep(0);
  172. @@ -398,7 +374,7 @@
  173.     }
  174.     fastlock_acquire(&sem->sem_lock);
  175.     if (sem->sem_waiting)
  176. -       sem->sem_waiting = (struct _pthread_descr_struct *)((long)sem->sem_waiting - 1);
  177. +       sem->sem_waiting--;
  178.     else {
  179.         if (sem->sem_value >= SEM_VALUE_MAX) {
  180.             errno = ERANGE;
RAW Paste Data