summaryrefslogtreecommitdiff
path: root/vp8/common/threading.h
diff options
context:
space:
mode:
Diffstat (limited to 'vp8/common/threading.h')
-rw-r--r--vp8/common/threading.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/vp8/common/threading.h b/vp8/common/threading.h
index f27b209c4..63fd4ccb9 100644
--- a/vp8/common/threading.h
+++ b/vp8/common/threading.h
@@ -193,6 +193,44 @@ static inline int sem_destroy(sem_t *sem) {
#include "vpx_util/vpx_thread.h"
+static INLINE void mutex_lock(pthread_mutex_t *const mutex) {
+ const int kMaxTryLocks = 4000;
+ int locked = 0;
+ int i;
+
+ for (i = 0; i < kMaxTryLocks; ++i) {
+ if (!pthread_mutex_trylock(mutex)) {
+ locked = 1;
+ break;
+ }
+ }
+
+ if (!locked) pthread_mutex_lock(mutex);
+}
+
+static INLINE int protected_read(pthread_mutex_t *const mutex, const int *p) {
+ int ret;
+ mutex_lock(mutex);
+ ret = *p;
+ pthread_mutex_unlock(mutex);
+ return ret;
+}
+
+static INLINE void sync_read(pthread_mutex_t *const mutex, int mb_col,
+ const int *last_row_current_mb_col,
+ const int nsync) {
+ while (mb_col > (protected_read(mutex, last_row_current_mb_col) - nsync)) {
+ x86_pause_hint();
+ thread_sleep(0);
+ }
+}
+
+static INLINE void protected_write(pthread_mutex_t *mutex, int *p, int v) {
+ mutex_lock(mutex);
+ *p = v;
+ pthread_mutex_unlock(mutex);
+}
+
#endif /* CONFIG_OS_SUPPORT && CONFIG_MULTITHREAD */
#ifdef __cplusplus