----------------->  GNU Sather - compiler configuration file  <----------------
-- Copyright (C) 199x by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

#ifndef LM_INCLUDE_CONFIG
#define LM_INCLUDE_CONFIG


LM_SINGLE_MUTEX_MANAGER_AASL:   volatile, no_pre, no_post,
        reads   "@0::.ll_mutex" "@0::locked" "@0::locked_by" "@0::my_manager",
        writes  "@0::locked" "@0::locked_by",
        var     "BR_spinlock_t lm_ll_mutex;"
                "@.locked_by lm_thread_id;"
                "@r $$;",
        exec    "if (FAR($0)) { $$=FALSE;"
                "} else {"
                " lm_ll_mutex = ATTR(ATTR($0,$.ll_mutex),lck);"
                " BR_SPINLOCK_LOCK(lm_ll_mutex);"
                " if((void*)(ATTR($0,$.my_manager))!=(void*)($0)) { $$=FALSE;"
                " } else {"
                "  lm_thread_id = PSATHER_THREAD_ID;"
                "  if (ATTR($0,$.locked) == 0 || BR_SAME_THREAD(ATTR($0,$.locked_by),lm_thread_id)) {"
                "   ATTR($0,$.locked) ++; ATTR($0,$.locked_by) = lm_thread_id;"
                "   BR_SPINLOCK_UNLOCK(lm_ll_mutex);"
                "   $$ = TRUE;"
                "  } else { $$ = FALSE;}"
                " }"
                "}"
                "$$";

LM_SINGLE_MUTEX_MANAGER_ATSL:   volatile, no_pre, no_post,
        reads   "@0::.ll_mutex" "@0::locked" "@0::locked_by" "@0::my_manager",
        writes  "@0::locked" "@0::locked_by",
        var     "BR_spinlock_t lm_ll_mutex;"
                "@.locked_by lm_thread_id;"
                "@r $$;",
        exec    "if (FAR($0)) { $$=FALSE;"
                "} else {"
                " lm_ll_mutex = ATTR(ATTR($0,$.ll_mutex),lck);"
                " BR_SPINLOCK_LOCK(lm_ll_mutex);"
                " if((void*)(ATTR($0,$.my_manager))!=(void*)($0)) { $$ = -1;"
                " } else {"
                "  lm_thread_id = BR_THREAD_ID();"
                "  if (ATTR($0,$.locked) == 0 || BR_SAME_THREAD(ATTR($0,$.locked_by),lm_thread_id)) {"
                "   ATTR($0,$.locked) ++; ATTR($0,$.locked_by) = lm_thread_id;"
                "   $$ = 0;"
                "  } else { $$ = 1;}"
                "  BR_SPINLOCK_UNLOCK(lm_ll_mutex);"
                " }"
                "}"
                "$$";

LM_SINGLE_MUTEX_MANAGER_ARSL:   volatile, no_pre, no_post,
        reads   "@0::.ll_mutex"
                "@0::locked"
                "@0::my_manager"
                "@0::no_thread_waiting",
        writes  "@0::locked",
        var     "BR_spinlock_t lm_ll_mutex;"
                "@.locked_by lm_thread_id;"
                "@r $$;",
        exec    "if (FAR($0)) { $$=FALSE;"
                "} else {"
                " lm_ll_mutex = ATTR(ATTR($0,$.ll_mutex),lck);"
                " BR_SPINLOCK_LOCK(lm_ll_mutex);"
                " if((void*)(ATTR($0,$.my_manager))!=(void*)($0)) { $$ = FALSE;"
                " } else {"
                "  ATTR($0,$.locked) -= 1;"
                "  if (ATTR($0,$.locked) != 0) {"
                "   BR_SPINLOCK_UNLOCK(lm_ll_mutex);"
                "   $$ = TRUE;"
                "  } else {"
                "   if (ATTR($0,$.no_thread_waiting)) {"
                "    BR_SPINLOCK_UNLOCK(lm_ll_mutex);"
                "    $$ = TRUE;"
                "   } else { $$ = FALSE; }"
                "  }"
                " }"
                "}"
                "$$";

#endif
