OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [osf-share/] [cma_mutex.h] - Diff between revs 107 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 107 Rev 1765
/*
/*
 * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC.
 * (c) Copyright 1990-1996 OPEN SOFTWARE FOUNDATION, INC.
 * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY
 * (c) Copyright 1990-1996 HEWLETT-PACKARD COMPANY
 * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION
 * (c) Copyright 1990-1996 DIGITAL EQUIPMENT CORPORATION
 * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems
 * (c) Copyright 1991, 1992 Siemens-Nixdorf Information Systems
 * To anyone who acknowledges that this file is provided "AS IS" without
 * To anyone who acknowledges that this file is provided "AS IS" without
 * any express or implied warranty: permission to use, copy, modify, and
 * any express or implied warranty: permission to use, copy, modify, and
 * distribute this file for any purpose is hereby granted without fee,
 * distribute this file for any purpose is hereby granted without fee,
 * provided that the above copyright notices and this notice appears in
 * provided that the above copyright notices and this notice appears in
 * all source code copies, and that none of the names listed above be used
 * all source code copies, and that none of the names listed above be used
 * in advertising or publicity pertaining to distribution of the software
 * in advertising or publicity pertaining to distribution of the software
 * without specific, written prior permission.  None of these organizations
 * without specific, written prior permission.  None of these organizations
 * makes any representations about the suitability of this software for
 * makes any representations about the suitability of this software for
 * any purpose.
 * any purpose.
 */
 */
/*
/*
 *      Header file for mutex operations
 *      Header file for mutex operations
 */
 */
 
 
#ifndef CMA_MUTEX
#ifndef CMA_MUTEX
#define CMA_MUTEX
#define CMA_MUTEX
 
 
/*
/*
 *  INCLUDE FILES
 *  INCLUDE FILES
 */
 */
 
 
#include <cma.h>
#include <cma.h>
#include <cma_attr.h>
#include <cma_attr.h>
#include <cma_defs.h>
#include <cma_defs.h>
#include <cma_semaphore_defs.h>
#include <cma_semaphore_defs.h>
#include <cma_sequence.h>
#include <cma_sequence.h>
#include <cma_tcb_defs.h>
#include <cma_tcb_defs.h>
#include <cma_stack.h>
#include <cma_stack.h>
 
 
/*
/*
 * CONSTANTS AND MACROS
 * CONSTANTS AND MACROS
 */
 */
 
 
/*
/*
 * TYPEDEFS
 * TYPEDEFS
 */
 */
 
 
typedef struct CMA__T_INT_MUTEX {
typedef struct CMA__T_INT_MUTEX {
    cma__t_object       header;         /* Common header (sequence, type) */
    cma__t_object       header;         /* Common header (sequence, type) */
    cma__t_int_attr     *attributes;    /* Back link */
    cma__t_int_attr     *attributes;    /* Back link */
    cma__t_int_tcb      *owner;         /* Current owner (if any) */
    cma__t_int_tcb      *owner;         /* Current owner (if any) */
    cma_t_integer       nest_count;     /* Nesting level for recursive mutex */
    cma_t_integer       nest_count;     /* Nesting level for recursive mutex */
    cma__t_atomic_bit   *unlock;        /* Pointer used for unlock operation */
    cma__t_atomic_bit   *unlock;        /* Pointer used for unlock operation */
    cma__t_atomic_bit   lock;           /* Set if currently locked */
    cma__t_atomic_bit   lock;           /* Set if currently locked */
    struct CMA__T_INT_MUTEX *int_lock;  /* Internal protection for mutex */
    struct CMA__T_INT_MUTEX *int_lock;  /* Internal protection for mutex */
    cma__t_atomic_bit   event;          /* Clear when unlock requires action */
    cma__t_atomic_bit   event;          /* Clear when unlock requires action */
    cma__t_atomic_bit   waiters;        /* Clear when threads are waiting */
    cma__t_atomic_bit   waiters;        /* Clear when threads are waiting */
    cma__t_atomic_bit   bitbucket;      /* Fake bit to keep friendlies locked */
    cma__t_atomic_bit   bitbucket;      /* Fake bit to keep friendlies locked */
    cma_t_mutex_kind    mutex_kind;     /* Kind of mutex */
    cma_t_mutex_kind    mutex_kind;     /* Kind of mutex */
    cma__t_semaphore    semaphore;      /* Semaphore for low-level wait */
    cma__t_semaphore    semaphore;      /* Semaphore for low-level wait */
    } cma__t_int_mutex;
    } cma__t_int_mutex;
 
 


/*
/*
 *  FUNCTIONAL DESCRIPTION:
 *  FUNCTIONAL DESCRIPTION:
 *
 *
 *      Lock a mutex (internal)
 *      Lock a mutex (internal)
 *
 *
 *  FORMAL PARAMETERS:
 *  FORMAL PARAMETERS:
 *
 *
 *      mutex           Pointer to mutex object to lock
 *      mutex           Pointer to mutex object to lock
 *
 *
 *  IMPLICIT INPUTS:
 *  IMPLICIT INPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  IMPLICIT OUTPUTS:
 *  IMPLICIT OUTPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  FUNCTION VALUE:
 *  FUNCTION VALUE:
 *
 *
 *      none
 *      none
 *
 *
 *  SIDE EFFECTS:
 *  SIDE EFFECTS:
 *
 *
 *      none
 *      none
 */
 */
#ifdef NDEBUG
#ifdef NDEBUG
# define cma__int_lock(mutex) { \
# define cma__int_lock(mutex) { \
    if (cma__test_and_set (&((cma__t_int_mutex *)mutex)->lock)) { \
    if (cma__test_and_set (&((cma__t_int_mutex *)mutex)->lock)) { \
        cma_t_status    res;\
        cma_t_status    res;\
        res = cma__int_mutex_block ((cma__t_int_mutex *)mutex); \
        res = cma__int_mutex_block ((cma__t_int_mutex *)mutex); \
        if (res != cma_s_normal) cma__error (res); \
        if (res != cma_s_normal) cma__error (res); \
        } \
        } \
    }
    }
#else
#else
# define cma__int_lock(mutex) { \
# define cma__int_lock(mutex) { \
    cma__t_int_tcb *__ltcb__; \
    cma__t_int_tcb *__ltcb__; \
    __ltcb__ = cma__get_self_tcb (); \
    __ltcb__ = cma__get_self_tcb (); \
    if (cma__test_and_set (&((cma__t_int_mutex *)mutex)->lock)) { \
    if (cma__test_and_set (&((cma__t_int_mutex *)mutex)->lock)) { \
        cma_t_status    res;\
        cma_t_status    res;\
        res = cma__int_mutex_block ((cma__t_int_mutex *)mutex); \
        res = cma__int_mutex_block ((cma__t_int_mutex *)mutex); \
        if (res != cma_s_normal) cma__error (res); \
        if (res != cma_s_normal) cma__error (res); \
        } \
        } \
    ((cma__t_int_mutex *)mutex)->owner = __ltcb__; \
    ((cma__t_int_mutex *)mutex)->owner = __ltcb__; \
    }
    }
#endif
#endif


/*
/*
 *  FUNCTIONAL DESCRIPTION:
 *  FUNCTIONAL DESCRIPTION:
 *
 *
 *      Unlock a mutex (internal)
 *      Unlock a mutex (internal)
 *
 *
 *  FORMAL PARAMETERS:
 *  FORMAL PARAMETERS:
 *
 *
 *      mutex           Pointer to mutex object to unlock
 *      mutex           Pointer to mutex object to unlock
 *
 *
 *  IMPLICIT INPUTS:
 *  IMPLICIT INPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  IMPLICIT OUTPUTS:
 *  IMPLICIT OUTPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  FUNCTION VALUE:
 *  FUNCTION VALUE:
 *
 *
 *      none
 *      none
 *
 *
 *  SIDE EFFECTS:
 *  SIDE EFFECTS:
 *
 *
 *      none
 *      none
 */
 */
#ifdef NDEBUG
#ifdef NDEBUG
# define cma__int_unlock(mutex) { \
# define cma__int_unlock(mutex) { \
    cma__unset (((cma__t_int_mutex *)mutex)->unlock); \
    cma__unset (((cma__t_int_mutex *)mutex)->unlock); \
    if (!cma__test_and_set (&((cma__t_int_mutex *)mutex)->event)) { \
    if (!cma__test_and_set (&((cma__t_int_mutex *)mutex)->event)) { \
        cma_t_status    res;\
        cma_t_status    res;\
        res = cma__int_mutex_unblock ((cma__t_int_mutex *)mutex); \
        res = cma__int_mutex_unblock ((cma__t_int_mutex *)mutex); \
        if (res != cma_s_normal) cma__error (res); \
        if (res != cma_s_normal) cma__error (res); \
        } \
        } \
    }
    }
#else
#else
# define cma__int_unlock(mutex) { \
# define cma__int_unlock(mutex) { \
    cma__t_int_tcb      *__utcb__; \
    cma__t_int_tcb      *__utcb__; \
    __utcb__ = cma__get_self_tcb (); \
    __utcb__ = cma__get_self_tcb (); \
    if (((cma__t_int_mutex *)mutex)->mutex_kind == cma_c_mutex_fast) { \
    if (((cma__t_int_mutex *)mutex)->mutex_kind == cma_c_mutex_fast) { \
        cma__assert_warn ( \
        cma__assert_warn ( \
                (__utcb__ == ((cma__t_int_mutex *)mutex)->owner), \
                (__utcb__ == ((cma__t_int_mutex *)mutex)->owner), \
                "attempt to release mutx owned by another thread"); \
                "attempt to release mutx owned by another thread"); \
        ((cma__t_int_mutex *)mutex)->owner = (cma__t_int_tcb *)cma_c_null_ptr; \
        ((cma__t_int_mutex *)mutex)->owner = (cma__t_int_tcb *)cma_c_null_ptr; \
        } \
        } \
    cma__unset (((cma__t_int_mutex *)mutex)->unlock); \
    cma__unset (((cma__t_int_mutex *)mutex)->unlock); \
    if (!cma__test_and_set (&((cma__t_int_mutex *)mutex)->event)) { \
    if (!cma__test_and_set (&((cma__t_int_mutex *)mutex)->event)) { \
        cma_t_status    res;\
        cma_t_status    res;\
        res = cma__int_mutex_unblock ((cma__t_int_mutex *)mutex); \
        res = cma__int_mutex_unblock ((cma__t_int_mutex *)mutex); \
        if (res != cma_s_normal) cma__error (res); \
        if (res != cma_s_normal) cma__error (res); \
        } \
        } \
    }
    }
#endif
#endif


/*
/*
 *  FUNCTIONAL DESCRIPTION:
 *  FUNCTIONAL DESCRIPTION:
 *
 *
 *      cma__int_mutex_delete - Performs work for cma_mutex_delete
 *      cma__int_mutex_delete - Performs work for cma_mutex_delete
 *
 *
 *  FORMAL PARAMETERS:
 *  FORMAL PARAMETERS:
 *
 *
 *      cma__t_mutex        _mutex_     - Mutex to be deleted
 *      cma__t_mutex        _mutex_     - Mutex to be deleted
 *
 *
 *  IMPLICIT INPUTS:
 *  IMPLICIT INPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  IMPLICIT OUTPUTS:
 *  IMPLICIT OUTPUTS:
 *
 *
 *      none
 *      none
 *
 *
 *  FUNCTION VALUE:
 *  FUNCTION VALUE:
 *
 *
 *      none
 *      none
 *
 *
 *  SIDE EFFECTS:
 *  SIDE EFFECTS:
 *
 *
 *      none
 *      none
 */
 */
#define cma__int_mutex_delete(_mutex_) { \
#define cma__int_mutex_delete(_mutex_) { \
    cma__t_int_mutex    *_int_mutex_; \
    cma__t_int_mutex    *_int_mutex_; \
    _int_mutex_ = cma__validate_null_mutex (_mutex_); \
    _int_mutex_ = cma__validate_null_mutex (_mutex_); \
    if (_int_mutex_ == (cma__t_int_mutex *)cma_c_null_ptr) \
    if (_int_mutex_ == (cma__t_int_mutex *)cma_c_null_ptr) \
        return; \
        return; \
    if (cma__int_mutex_locked (_int_mutex_)) \
    if (cma__int_mutex_locked (_int_mutex_)) \
        cma__error (cma_s_in_use); \
        cma__error (cma_s_in_use); \
    cma__free_mutex (_int_mutex_); \
    cma__free_mutex (_int_mutex_); \
    cma__clear_handle (_mutex_); \
    cma__clear_handle (_mutex_); \
    }
    }
 
 
 
 
/*
/*
 *  GLOBAL DATA
 *  GLOBAL DATA
 */
 */
 
 
extern cma__t_sequence  cma__g_mutex_seq;
extern cma__t_sequence  cma__g_mutex_seq;
extern cma__t_int_mutex *cma__g_global_lock;
extern cma__t_int_mutex *cma__g_global_lock;
 
 
/*
/*
 * INTERNAL INTERFACES
 * INTERNAL INTERFACES
 */
 */
 
 
extern void cma__destroy_mutex  (cma__t_int_mutex *);
extern void cma__destroy_mutex  (cma__t_int_mutex *);
 
 
extern void cma__free_mutex  (cma__t_int_mutex *);
extern void cma__free_mutex  (cma__t_int_mutex *);
 
 
extern void cma__free_mutex_nolock  (cma__t_int_mutex *);
extern void cma__free_mutex_nolock  (cma__t_int_mutex *);
 
 
extern cma__t_int_mutex * cma__get_first_mutex  (cma__t_int_attr *);
extern cma__t_int_mutex * cma__get_first_mutex  (cma__t_int_attr *);
 
 
extern cma__t_int_mutex * cma__get_mutex  (cma__t_int_attr *);
extern cma__t_int_mutex * cma__get_mutex  (cma__t_int_attr *);
 
 
extern void cma__init_mutex  (void);
extern void cma__init_mutex  (void);
 
 
extern cma_t_status cma__int_mutex_block  (cma__t_int_mutex *);
extern cma_t_status cma__int_mutex_block  (cma__t_int_mutex *);
 
 
extern cma_t_boolean cma__int_mutex_locked  (cma__t_int_mutex *);
extern cma_t_boolean cma__int_mutex_locked  (cma__t_int_mutex *);
 
 
extern cma_t_boolean cma__int_try_lock  (cma__t_int_mutex *);
extern cma_t_boolean cma__int_try_lock  (cma__t_int_mutex *);
 
 
extern cma_t_status cma__int_mutex_unblock  (cma__t_int_mutex *);
extern cma_t_status cma__int_mutex_unblock  (cma__t_int_mutex *);
 
 
extern cma_t_boolean cma__mutex_locked  (cma_t_mutex);
extern cma_t_boolean cma__mutex_locked  (cma_t_mutex);
 
 
extern void cma__reinit_mutex  (cma_t_integer);
extern void cma__reinit_mutex  (cma_t_integer);
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.