Rev 5372 | Rev 6106 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5372 | Rev 5603 | ||
---|---|---|---|
Line 8... | Line 8... | ||
8 | #include "fplay.h" |
8 | #include "fplay.h" |
9 | 9 | ||
Line 10... | Line 10... | ||
10 | extern uint32_t hw2d ; |
10 | extern uint32_t hw2d ; |
Line -... | Line 11... | ||
- | 11 | ||
- | 12 | #if 0 |
|
- | 13 | #define FUTEX_INIT 0 |
|
- | 14 | #define FUTEX_DESTROY 1 |
|
- | 15 | #define FUTEX_WAIT 2 |
|
- | 16 | #define FUTEX_WAKE 3 |
|
- | 17 | ||
- | 18 | int __fastcall mutex_init(mutex_t *mutex) |
|
- | 19 | { |
|
- | 20 | unsigned int handle; |
|
- | 21 | ||
- | 22 | mutex->lock = 0; |
|
- | 23 | ||
- | 24 | asm volatile( |
|
- | 25 | "int $0x40\t" |
|
- | 26 | :"=a"(handle) |
|
- | 27 | :"a"(77),"b"(FUTEX_INIT),"c"(mutex)); |
|
- | 28 | mutex->handle = handle; |
|
- | 29 | ||
- | 30 | return handle; |
|
- | 31 | }; |
|
- | 32 | ||
- | 33 | int __fastcall mutex_destroy(mutex_t *mutex) |
|
- | 34 | { |
|
- | 35 | int retval; |
|
- | 36 | ||
- | 37 | asm volatile( |
|
- | 38 | "int $0x40\t" |
|
- | 39 | :"=a"(retval) |
|
- | 40 | :"a"(77),"b"(FUTEX_DESTROY),"c"(mutex->handle)); |
|
- | 41 | ||
- | 42 | return retval; |
|
- | 43 | }; |
|
- | 44 | ||
- | 45 | #define exchange_acquire(ptr, new) \ |
|
- | 46 | __atomic_exchange_4((ptr), (new), __ATOMIC_ACQUIRE) |
|
- | 47 | ||
- | 48 | #define exchange_release(ptr, new) \ |
|
- | 49 | __atomic_exchange_4((ptr), (new), __ATOMIC_RELEASE) |
|
11 | 50 | ||
12 | void mutex_lock(volatile uint32_t *val) |
51 | void __fastcall mutex_lock(mutex_t *mutex) |
13 | { |
52 | { |
Line 14... | Line 53... | ||
14 | uint32_t tmp; |
53 | int tmp; |
15 | - | ||
16 | __asm__ __volatile__ ( |
- | |
17 | "0:\n\t" |
- | |
18 | "mov %0, %1\n\t" |
54 | |
19 | "testl %1, %1\n\t" |
55 | if( __sync_fetch_and_add(&mutex->lock, 1) == 0) |
20 | "jz 1f\n\t" |
56 | return; |
21 | 57 | ||
22 | "movl $68, %%eax\n\t" |
58 | while (exchange_acquire (&mutex->lock, 2) != 0) |
23 | "movl $1, %%ebx\n\t" |
59 | { |
24 | "int $0x40\n\t" |
- | |
25 | "jmp 0b\n\t" |
60 | asm volatile( |
26 | "1:\n\t" |
61 | "int $0x40\t" |
27 | "incl %1\n\t" |
62 | :"=a"(tmp) |
28 | "xchgl %0, %1\n\t" |
63 | :"a"(77),"b"(FUTEX_WAIT), |
- | 64 | "c"(mutex->handle),"d"(2),"S"(0)); |
|
- | 65 | } |
|
29 | "testl %1, %1\n\t" |
66 | } |
- | 67 | ||
30 | "jnz 0b\n" |
68 | int __fastcall mutex_trylock (mutex_t *mutex) |
- | 69 | { |
|
- | 70 | int zero = 0; |
|
31 | : "+m" (*val), "=&r"(tmp) |
71 | |
Line -... | Line 72... | ||
- | 72 | return __atomic_compare_exchange_4(&mutex->lock, &zero, 1,0,__ATOMIC_ACQUIRE,__ATOMIC_RELAXED); |
|
- | 73 | } |
|
- | 74 | ||
- | 75 | void __fastcall mutex_unlock(mutex_t *mutex) |
|
- | 76 | { |
|
- | 77 | int prev; |
|
- | 78 | ||
- | 79 | prev = exchange_release (&mutex->lock, 0); |
|
- | 80 | ||
- | 81 | if (prev != 1) |
|
- | 82 | { |
|
- | 83 | asm volatile( |
|
- | 84 | "int $0x40\t" |
|
- | 85 | :"=a"(prev) |
|
- | 86 | :"a"(77),"b"(FUTEX_WAKE), |
|
- | 87 | "c"(mutex->handle),"d"(1)); |
|
Line 32... | Line 88... | ||
32 | ::"eax","ebx" ); |
88 | }; |
33 | } |
89 | }; |
34 | 90 | #endif |
|
35 | 91 | ||
36 | int64_t _lseeki64(int fd, int64_t offset, int origin ) |
92 | int64_t _lseeki64(int fd, int64_t offset, int origin ) |
Line 37... | Line -... | ||
37 | { |
- | |
38 | int off = offset; |
93 | { |
39 | return lseek(fd, off, origin); |
94 | int off = offset; |
40 | } |
95 | return lseek(fd, off, origin); |
Line 41... | Line 96... | ||
41 | 96 | } |