OLD | NEW |
1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // is not linked with -pthread). | 113 // is not linked with -pthread). |
114 static bool pthread_once_ran_before_threads = false; | 114 static bool pthread_once_ran_before_threads = false; |
115 if (pthread_once_ran_before_threads) { | 115 if (pthread_once_ran_before_threads) { |
116 return 0; | 116 return 0; |
117 } | 117 } |
118 if (!__isthreaded) { | 118 if (!__isthreaded) { |
119 init_routine(); | 119 init_routine(); |
120 pthread_once_ran_before_threads = true; | 120 pthread_once_ran_before_threads = true; |
121 return 0; | 121 return 0; |
122 } | 122 } |
123 #endif | 123 #elif defined(__ANDROID__) |
| 124 // Android >= 2.3 (GB) always implement pthread_once. |
| 125 return pthread_once(ctl, init_routine); |
| 126 #else |
124 if (pthread_once) { | 127 if (pthread_once) { |
125 return pthread_once(ctl, init_routine); | 128 return pthread_once(ctl, init_routine); |
126 } else { | 129 } else { |
127 if (memcmp(ctl, &pthread_once_init, sizeof(*ctl)) == 0) { | 130 if (memcmp(ctl, &pthread_once_init, sizeof(*ctl)) == 0) { |
128 init_routine(); | 131 init_routine(); |
129 ++*(char*)(ctl); // make it so it's no longer equal to init | 132 ++*(char*)(ctl); // make it so it's no longer equal to init |
130 } | 133 } |
131 return 0; | 134 return 0; |
132 } | 135 } |
| 136 #endif |
133 } | 137 } |
OLD | NEW |