aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuji Mano <yuji.mano@am.sony.com>2009-06-15 17:03:50 -0700
committerYuji Mano <yuji.mano@am.sony.com>2009-07-07 12:24:23 -0700
commitfab8eb53d9f74410946f8a08c342e65cc9d51641 (patch)
tree4a85bacdd19dc072aea2df8261321ec578049395
parent0ad710a69acf37916364bc57d7b47e65380c74df (diff)
downloadmars-src-fab8eb53d9f74410946f8a08c342e65cc9d51641.tar.gz
base: host side mutex contention
This reduces the chances of mutex lock contention on the host-side which becomes apparent when a large number of pthreads are created and access the mutex simultaneously. Signed-off-by: Yuji Mano <yuji.mano@am.sony.com> Acked-by: Kazunori Asayama <asayama@sm.sony.co.jp>
-rw-r--r--base/src/host/lib/mutex_cell.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/base/src/host/lib/mutex_cell.c b/base/src/host/lib/mutex_cell.c
index 740b897..f1d0eea 100644
--- a/base/src/host/lib/mutex_cell.c
+++ b/base/src/host/lib/mutex_cell.c
@@ -108,16 +108,17 @@ int mars_mutex_lock(uint64_t mutex_ea)
uint8_t id;
int retry;
- if (!mutex_ea) {
+ if (!mutex_ea)
return MARS_ERROR_NULL;
- }
do {
header.bits = __lwarx(&mutex->status);
/* get my id */
id = header.status.next_id++;
- } while (!__stwcx(&mutex->status, header.bits));
+ if ((retry = !__stwcx(&mutex->status, header.bits)))
+ sched_yield();
+ } while (retry);
do {
header.bits = __lwarx(&mutex->status);
@@ -125,7 +126,7 @@ int mars_mutex_lock(uint64_t mutex_ea)
if (header.status.lock == MARS_MUTEX_LOCKED ||
header.status.current_id != id) {
/* wait until mutex is released */
- usleep(1);
+ sched_yield();
retry = 1;
}
else {