<commit_before>/* ----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 2005
 *
 * Macros for SMP support
 *
 * -------------------------------------------------------------------------- */

#ifndef SMP_H
#define SMP_H

/* SMP is currently not compatible with the following options:
 *
 *      INTERPRETER
 *      PROFILING
 *      TICKY_TICKY
 *      and unregisterised builds.
 */

#if defined(SMP)

#if  defined(PROFILING)  || defined(TICKY_TICKY)
#error Build options incompatible with SMP.
#endif

/* 
 * XCHG - the atomic exchange instruction.  Used for locking closures
 * during updates (see LOCK_CLOSURE below) and the MVar primops.
 */
INLINE_HEADER StgWord
xchg(StgPtr p, StgWord w)
{
    StgWord result;
    result = w;
    __asm__ __volatile__ (
 	  "xchgl %1,%0"
          :"+r" (result), "+m" (*p)
          : /* no input-only operands */
	);
    return result;
}

INLINE_HEADER StgInfoTable *
lockClosure(StgClosure *p)
{
    StgWord info;
#if 0
    do {
	info = xchg((P_)&p->header.info, (W_)&stg_WHITEHOLE_info);
	if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
	yieldThread();
    } while (1);
#else
    info = p->header.info;
#endif
}

#endif /* SMP */

#endif /* SMP_H */<commit_msg>[project @ 2005-05-24 15:43:32 by simonmar] implement lockClosure properly<commit_after>/* ----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 2005
 *
 * Macros for SMP support
 *
 * -------------------------------------------------------------------------- */

#ifndef SMP_H
#define SMP_H

/* SMP is currently not compatible with the following options:
 *
 *      INTERPRETER
 *      PROFILING
 *      TICKY_TICKY
 *      and unregisterised builds.
 */

#if defined(SMP)

#if  defined(PROFILING)  || defined(TICKY_TICKY)
#error Build options incompatible with SMP.
#endif

/* 
 * XCHG - the atomic exchange instruction.  Used for locking closures
 * during updates (see LOCK_CLOSURE below) and the MVar primops.
 */
INLINE_HEADER StgWord
xchg(StgPtr p, StgWord w)
{
    StgWord result;
    result = w;
    __asm__ __volatile__ (
 	  "xchg %1,%0"
          :"+r" (result), "+m" (*p)
          : /* no input-only operands */
	);
    return result;
}

INLINE_HEADER StgInfoTable *
lockClosure(StgClosure *p)
{
#if i386_HOST_ARCH || x86_64_HOST_ARCH
    StgWord info;
    do {
	info = xchg((P_)&p->header.info, (W_)&stg_WHITEHOLE_info);
	if (info != (W_)&stg_WHITEHOLE_info) return (StgInfoTable *)info;
	yieldThread();
    } while (1);
#else
   ACQUIRE_SM_LOCK
#endif
}

INLINE_HEADER void
unlockClosure(StgClosure *p, StgInfoTable *info)
{
#if i386_HOST_ARCH || x86_64_HOST_ARCH
    // This is safe enough, because lockClosure() does the memory barrier:
    p->header.info = info;
#else
    RELEASE_SM_LOCK;
#endif
}

#endif /* SMP */

#endif /* SMP_H */
{'fraction_non_alphanumeric': 0.21664925113200975, 'fraction_numerical': 0.014977359804946012, 'mean_word_length': 2.1353711790393013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842585', 'n_tokens_mistral': 1042, 'n_tokens_neox': 989, 'n_words': 253}