summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2018-06-25 15:15:29 -0400
committerMike Blumenkrantz <zmike@samsung.com>2018-06-25 15:15:29 -0400
commit73ba4006bd6e2a7cf66b6cfd24b972095dd514eb (patch)
tree9142335f28ce78706112b21da69d4f881c497644 /src
parenta522bf5d7625c49cfd4d25f477633b764f2317f8 (diff)
eina/lock: reorder inline posix lock functions
Summary: no functional changes Reviewers: ManMower, devilhorns Reviewed By: devilhorns Subscribers: cedric, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D6374
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_inline_lock_posix.x110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/lib/eina/eina_inline_lock_posix.x b/src/lib/eina/eina_inline_lock_posix.x
index 9dd96ebb4e..8ae3f89566 100644
--- a/src/lib/eina/eina_inline_lock_posix.x
+++ b/src/lib/eina/eina_inline_lock_posix.x
@@ -198,6 +198,45 @@ eina_lock_free(Eina_Lock *mutex)
198} 198}
199 199
200static inline Eina_Lock_Result 200static inline Eina_Lock_Result
201eina_lock_take_try(Eina_Lock *mutex)
202{
203 Eina_Lock_Result ret = EINA_LOCK_FAIL;
204 int ok;
205
206#ifdef EINA_HAVE_ON_OFF_THREADS
207 if (!_eina_threads_activated)
208 {
209 return EINA_LOCK_SUCCEED;
210 }
211#endif
212
213 ok = pthread_mutex_trylock(&(mutex->mutex));
214 if (ok == 0) ret = EINA_LOCK_SUCCEED;
215 else if (ok == EDEADLK)
216 {
217 eina_lock_debug(mutex);
218 ret = EINA_LOCK_DEADLOCK;
219 }
220 else if (ok != EBUSY) EINA_LOCK_ABORT_DEBUG(ok, trylock, mutex);
221#ifdef EINA_HAVE_DEBUG_THREADS
222 if (ret == EINA_LOCK_SUCCEED)
223 {
224 /* recursive locks can't make use of any of this */
225 if (mutex->recursive) return ret;
226 mutex->locked = 1;
227 mutex->lock_thread_id = pthread_self();
228 mutex->lock_bt_num = backtrace((void **)(mutex->lock_bt), EINA_LOCK_DEBUG_BT_NUM);
229
230 pthread_mutex_lock(&_eina_tracking_lock);
231 _eina_tracking = eina_inlist_append(_eina_tracking,
232 EINA_INLIST_GET(mutex));
233 pthread_mutex_unlock(&_eina_tracking_lock);
234 }
235#endif
236 return ret;
237}
238
239static inline Eina_Lock_Result
201eina_lock_take(Eina_Lock *mutex) 240eina_lock_take(Eina_Lock *mutex)
202{ 241{
203 Eina_Lock_Result ret = EINA_LOCK_FAIL; 242 Eina_Lock_Result ret = EINA_LOCK_FAIL;
@@ -265,45 +304,6 @@ eina_lock_take(Eina_Lock *mutex)
265} 304}
266 305
267static inline Eina_Lock_Result 306static inline Eina_Lock_Result
268eina_lock_take_try(Eina_Lock *mutex)
269{
270 Eina_Lock_Result ret = EINA_LOCK_FAIL;
271 int ok;
272
273#ifdef EINA_HAVE_ON_OFF_THREADS
274 if (!_eina_threads_activated)
275 {
276 return EINA_LOCK_SUCCEED;
277 }
278#endif
279
280 ok = pthread_mutex_trylock(&(mutex->mutex));
281 if (ok == 0) ret = EINA_LOCK_SUCCEED;
282 else if (ok == EDEADLK)
283 {
284 eina_lock_debug(mutex);
285 ret = EINA_LOCK_DEADLOCK;
286 }
287 else if (ok != EBUSY) EINA_LOCK_ABORT_DEBUG(ok, trylock, mutex);
288#ifdef EINA_HAVE_DEBUG_THREADS
289 if (ret == EINA_LOCK_SUCCEED)
290 {
291 /* recursive locks can't make use of any of this */
292 if (mutex->recursive) return ret;
293 mutex->locked = 1;
294 mutex->lock_thread_id = pthread_self();
295 mutex->lock_bt_num = backtrace((void **)(mutex->lock_bt), EINA_LOCK_DEBUG_BT_NUM);
296
297 pthread_mutex_lock(&_eina_tracking_lock);
298 _eina_tracking = eina_inlist_append(_eina_tracking,
299 EINA_INLIST_GET(mutex));
300 pthread_mutex_unlock(&_eina_tracking_lock);
301 }
302#endif
303 return ret;
304}
305
306static inline Eina_Lock_Result
307eina_lock_release(Eina_Lock *mutex) 307eina_lock_release(Eina_Lock *mutex)
308{ 308{
309 Eina_Lock_Result ret = EINA_LOCK_FAIL; 309 Eina_Lock_Result ret = EINA_LOCK_FAIL;
@@ -633,6 +633,22 @@ eina_spinlock_free(Eina_Spinlock *spinlock)
633} 633}
634 634
635static inline Eina_Lock_Result 635static inline Eina_Lock_Result
636eina_spinlock_take_try(Eina_Spinlock *spinlock)
637{
638#if defined(EINA_HAVE_POSIX_SPINLOCK)
639 int t = pthread_spin_trylock(spinlock);
640 if (t == 0) return EINA_LOCK_SUCCEED;
641 else if (t == EBUSY) return EINA_LOCK_FAIL;
642 else EINA_LOCK_ABORT_DEBUG(t, spin_trylock, spinlock);
643 return EINA_LOCK_FAIL;
644#elif defined(EINA_HAVE_OSX_SPINLOCK)
645 return _eina_spinlock_macos_take_try(spinlock);
646#else
647 return eina_lock_take_try(spinlock);
648#endif
649}
650
651static inline Eina_Lock_Result
636eina_spinlock_take(Eina_Spinlock *spinlock) 652eina_spinlock_take(Eina_Spinlock *spinlock)
637{ 653{
638#if defined(EINA_HAVE_POSIX_SPINLOCK) 654#if defined(EINA_HAVE_POSIX_SPINLOCK)
@@ -654,22 +670,6 @@ eina_spinlock_take(Eina_Spinlock *spinlock)
654} 670}
655 671
656static inline Eina_Lock_Result 672static inline Eina_Lock_Result
657eina_spinlock_take_try(Eina_Spinlock *spinlock)
658{
659#if defined(EINA_HAVE_POSIX_SPINLOCK)
660 int t = pthread_spin_trylock(spinlock);
661 if (t == 0) return EINA_LOCK_SUCCEED;
662 else if (t == EBUSY) return EINA_LOCK_FAIL;
663 else EINA_LOCK_ABORT_DEBUG(t, spin_trylock, spinlock);
664 return EINA_LOCK_FAIL;
665#elif defined(EINA_HAVE_OSX_SPINLOCK)
666 return _eina_spinlock_macos_take_try(spinlock);
667#else
668 return eina_lock_take_try(spinlock);
669#endif
670}
671
672static inline Eina_Lock_Result
673eina_spinlock_release(Eina_Spinlock *spinlock) 673eina_spinlock_release(Eina_Spinlock *spinlock)
674{ 674{
675#if defined(EINA_HAVE_POSIX_SPINLOCK) 675#if defined(EINA_HAVE_POSIX_SPINLOCK)