From 44a418bd04f1edd51d1c346d64c722ce96e9fa11 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 15 Jan 2010 12:04:01 +0000 Subject: [PATCH] small orp fixes. --- OPTYap/opt.init.c | 2 +- OPTYap/opt.memory.c | 5 ++--- OPTYap/opt.structs.h | 2 +- OPTYap/or.scheduler.c | 2 +- OPTYap/or.threadengine.c | 14 +++++++------- OPTYap/pthread_locks.h | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/OPTYap/opt.init.c b/OPTYap/opt.init.c index 128e83e73..6a8508e32 100644 --- a/OPTYap/opt.init.c +++ b/OPTYap/opt.init.c @@ -180,7 +180,7 @@ void Yap_init_local(void) { LOCAL_top_or_fr = GLOBAL_root_or_fr; LOCAL_load = 0; LOCAL_share_request = MAX_WORKERS; - LOCAL_reply_signal = ready; + LOCAL_reply_signal = worker_ready; #ifdef ENV_COPY INIT_LOCK(LOCAL_lock_signals); #endif /* ENV_COPY */ diff --git a/OPTYap/opt.memory.c b/OPTYap/opt.memory.c index 852eabe65..6f3b0ed21 100644 --- a/OPTYap/opt.memory.c +++ b/OPTYap/opt.memory.c @@ -14,7 +14,7 @@ ** -------------------------------------- */ #include "Yap.h" -#ifdef YAPOR +#if defined(YAPOR) && !defined(THREADS) #include #include #include @@ -77,7 +77,6 @@ close_mapfile(void) { } #endif /* MMAP_MEMORY_MAPPING_SCHEME */ - void map_memory(long HeapArea, long GlobalLocalArea, long TrailAuxArea, int n_workers) { void *mmap_addr = (void *)MMAP_ADDR; #ifdef ACOW @@ -275,4 +274,4 @@ void remap_memory(void) { } #endif /* ENV_COPY */ } -#endif /* YAPOR */ +#endif /* YAPOR && !THREADS */ diff --git a/OPTYap/opt.structs.h b/OPTYap/opt.structs.h index 657022adf..8446c4d52 100644 --- a/OPTYap/opt.structs.h +++ b/OPTYap/opt.structs.h @@ -129,7 +129,7 @@ struct global_locks { lockvar bitmap_pruning_workers; #endif /* TABLING_INNER_CUTS */ - lockvar who_locked_heap; + int who_locked_heap; lockvar heap_access; lockvar alloc_block; #if defined(YAPOR_ERRORS) || defined(TABLING_ERRORS) diff --git a/OPTYap/or.scheduler.c b/OPTYap/or.scheduler.c index 314c3739e..392bfddea 100644 --- a/OPTYap/or.scheduler.c +++ b/OPTYap/or.scheduler.c @@ -167,7 +167,7 @@ int get_work(void) { #ifndef TABLING /* wait for incomplete installations */ - while (LOCAL_reply_signal != ready); + while (LOCAL_reply_signal != worker_ready); #endif /* TABLING */ if (or_fr_with_work) { diff --git a/OPTYap/or.threadengine.c b/OPTYap/or.threadengine.c index 6c3262a88..2f346f3a0 100644 --- a/OPTYap/or.threadengine.c +++ b/OPTYap/or.threadengine.c @@ -102,7 +102,7 @@ int p_share_work(void) { REMOTE_p_fase_signal(worker_q) = P_idle; #ifndef TABLING /* wait for incomplete installations */ - while (LOCAL_reply_signal != ready); + while (LOCAL_reply_signal != worker_ready); #endif /* TABLING */ LOCAL_reply_signal = sharing; REMOTE_reply_signal(worker_q) = sharing; @@ -140,8 +140,8 @@ int q_share_work(int worker_p) { OPTYAP_ERROR_MESSAGE("YOUNGER_CP(B_FZ, LOCAL_top_cp) (q_share_work)"); #endif /* OPTYAP_ERRORS */ #ifdef YAPOR_ERRORS - if (LOCAL_reply_signal != ready) - YAPOR_ERROR_MESSAGE("LOCAL_reply_signal != ready (q_share_work)"); + if (LOCAL_reply_signal != worker_ready) + YAPOR_ERROR_MESSAGE("LOCAL_reply_signal != worker_ready (q_share_work)"); #endif /* YAPOR_ERRORS */ /* make sharing request */ @@ -156,10 +156,10 @@ int q_share_work(int worker_p) { UNLOCK_WORKER(worker_p); /* wait for an answer */ - while (LOCAL_reply_signal == ready); + while (LOCAL_reply_signal == worker_ready); if (LOCAL_reply_signal == no_sharing) { /* sharing request refused */ - LOCAL_reply_signal = ready; + LOCAL_reply_signal = worker_ready; return FALSE; } while (LOCAL_reply_signal == sharing); @@ -168,9 +168,9 @@ int q_share_work(int worker_p) { /* update registers and return */ #ifndef TABLING - REMOTE_reply_signal(worker_p) = ready; + REMOTE_reply_signal(worker_p) = worker_ready; #endif /* TABLING */ - LOCAL_reply_signal = ready; + LOCAL_reply_signal = worker_ready; PUT_IN_REQUESTABLE(worker_id); return TRUE; } diff --git a/OPTYap/pthread_locks.h b/OPTYap/pthread_locks.h index 25610fe6f..8539a9f18 100644 --- a/OPTYap/pthread_locks.h +++ b/OPTYap/pthread_locks.h @@ -24,6 +24,24 @@ #define TRY_LOCK(LOCK_PTR) pthread_mutex_trylock(&(LOCK_VAR)) #define LOCK(LOCK_VAR) pthread_mutex_lock(&(LOCK_VAR)) #define UNLOCK(LOCK_VAR) pthread_mutex_unlock(&(LOCK_VAR)) +static inline int +xIS_LOCKED(pthread_mutex_t *LOCK_VAR) { + if (pthread_mutex_trylock(LOCK_VAR) == 0) { + pthread_mutex_unlock(LOCK_VAR); + return TRUE; + } + return FALSE; +} +static inline int +xIS_UNLOCKED(pthread_mutex_t *LOCK_VAR) { + if (pthread_mutex_trylock(LOCK_VAR) == 0) { + pthread_mutex_unlock(LOCK_VAR); + return FALSE; + } + return TRUE; +} +#define IS_LOCKED(LOCK_VAR) xIS_LOCKED(&(LOCK_VAR)) +#define IS_UNLOCKED(LOCK_VAR) xIS_UNLOCKED(&(LOCK_VAR)) #define INIT_RWLOCK(X) pthread_rwlock_init(&(X), NULL) #define DESTROY_RWLOCK(X) pthread_rwlock_destroy(&(X))