src/osd/sdl/sdlsync.c
| r1188 | r1189 | |
| 47 | 47 | struct _osd_lock { |
| 48 | 48 | volatile pthread_t holder; |
| 49 | 49 | INT32 count; |
| 50 | #ifdef PTR64 |
| 51 | INT8 padding[52]; // Fill a 64-byte cache line |
| 52 | #else |
| 53 | INT8 padding[56]; // A bit more padding |
| 54 | #endif |
| 50 | 55 | }; |
| 51 | 56 | |
| 52 | 57 | struct _osd_event { |
| r1188 | r1189 | |
| 54 | 59 | pthread_cond_t cond; |
| 55 | 60 | volatile INT32 autoreset; |
| 56 | 61 | volatile INT32 signalled; |
| 62 | #ifdef PTR64 |
| 63 | INT8 padding[40]; // Fill a 64-byte cache line |
| 64 | #else |
| 65 | INT8 padding[48]; // A bit more padding |
| 66 | #endif |
| 57 | 67 | }; |
| 58 | 68 | |
| 59 | 69 | struct _osd_thread { |
| 60 | | pthread_t thread; |
| 70 | pthread_t thread; |
| 61 | 71 | }; |
| 62 | 72 | |
| 63 | 73 | static osd_lock *atomic_lck = NULL; |
| r1188 | r1189 | |
| 93 | 103 | |
| 94 | 104 | lock = (osd_lock *)calloc(1, sizeof(osd_lock)); |
| 95 | 105 | |
| 96 | | lock->holder = NULL; |
| 106 | lock->holder = 0; |
| 97 | 107 | lock->count = 0; |
| 98 | 108 | |
| 99 | 109 | return lock; |
| r1188 | r1189 | |
| 108 | 118 | pthread_t current, prev; |
| 109 | 119 | |
| 110 | 120 | current = pthread_self(); |
| 111 | | prev = osd_compare_exchange_pthread_t(&lock->holder, NULL, current); |
| 112 | | if (prev != NULL && prev != current) |
| 121 | prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); |
| 122 | if (prev != (size_t)NULL && prev != current) |
| 113 | 123 | { |
| 114 | 124 | do { |
| 115 | 125 | register INT32 spin = 10000; // Convenient spin count |
| r1188 | r1189 | |
| 120 | 130 | " mov %[holder], %[tmp] ;" |
| 121 | 131 | " test %[tmp], %[tmp] ;" |
| 122 | 132 | " loopne 1b ;" |
| 123 | | : [spin] "+c" (spin) |
| 133 | : [spin] "+c" (spin) |
| 124 | 134 | , [tmp] "=&r" (tmp) |
| 125 | | : [holder] "m" (lock->holder) |
| 135 | : [holder] "m" (lock->holder) |
| 126 | 136 | : "%cc" |
| 127 | 137 | ); |
| 128 | 138 | #elif defined(__ppc__) || defined(__PPC__) |
| r1188 | r1189 | |
| 164 | 174 | nanosleep(&sleep, &remaining); // sleep for 100us |
| 165 | 175 | } |
| 166 | 176 | #endif |
| 167 | | } while (osd_compare_exchange_pthread_t(&lock->holder, NULL, current) != NULL); |
| 177 | } while (osd_compare_exchange_pthread_t(&lock->holder, 0, current) != (size_t)NULL); |
| 168 | 178 | } |
| 169 | 179 | lock->count++; |
| 170 | 180 | } |
| r1188 | r1189 | |
| 178 | 188 | pthread_t current, prev; |
| 179 | 189 | |
| 180 | 190 | current = pthread_self(); |
| 181 | | prev = osd_compare_exchange_pthread_t(&lock->holder, NULL, current); |
| 182 | | if (prev == NULL || prev == current) |
| 191 | prev = osd_compare_exchange_pthread_t(&lock->holder, 0, current); |
| 192 | if (prev == (size_t)NULL || prev == current) |
| 183 | 193 | { |
| 184 | 194 | lock->count++; |
| 185 | 195 | return 1; |
| r1188 | r1189 | |
| 200 | 210 | { |
| 201 | 211 | if (--lock->count == 0) |
| 202 | 212 | #if defined(__ppc__) || defined(__PPC__) || defined(__ppc64__) || defined(__PPC64__) |
| 203 | | lock->holder = NULL; |
| 213 | lock->holder = 0; |
| 204 | 214 | __asm__ __volatile__( " eieio " : : ); |
| 205 | 215 | #else |
| 206 | | osd_exchange_pthread_t(&lock->holder, NULL); |
| 216 | osd_exchange_pthread_t(&lock->holder, 0); |
| 207 | 217 | #endif |
| 208 | 218 | return; |
| 209 | 219 | } |
src/osd/sdl/osinline.h
| r1188 | r1189 | |
| 352 | 352 | ATTR_UNUSED |
| 353 | 353 | INLINE INT64 _osd_exchange64(INT64 volatile *ptr, INT64 exchange) |
| 354 | 354 | { |
| 355 | | register INT32 ret; |
| 355 | register INT64 ret; |
| 356 | 356 | __asm__ __volatile__ ( |
| 357 | | "1: lwarx %[ret], 0, %[ptr] \n" |
| 358 | | " stwcx. %[exchange], 0, %[ptr] \n" |
| 359 | | " bne- 1b \n" |
| 357 | "1: ldarx %[ret], 0, %[ptr] \n" |
| 358 | " stdcx. %[exchange], 0, %[ptr] \n" |
| 359 | " bne-- 1b \n" |
| 360 | 360 | : [ret] "=&r" (ret) |
| 361 | 361 | : [ptr] "r" (ptr) |
| 362 | 362 | , [exchange] "r" (exchange) |