Annotation of coherent/f/etc/conf/streams/src/x86lock.c, revision 1.1

1.1     ! root        1: #define        _DDI_DKI        1
        !             2: #define        _SYSV4          1
        !             3: 
        !             4: /*
        !             5:  * Some simple tests to make sure that whatever is defined in the internal
        !             6:  * <sys/x86lock.h> header at least does vaguely what it should, even if it
        !             7:  * doesn't do it really atomically.
        !             8:  */
        !             9: 
        !            10: #include <kernel/x86lock.h>
        !            11: #include <limits.h>
        !            12: 
        !            13: 
        !            14: #if    __BORLANDC__
        !            15: 
        !            16: /*
        !            17:  * The following functions cannot safely be used in-line in Borland C++
        !            18:  * due to problems with 32-bit code generation and register pseudovariables.
        !            19:  */
        !            20: 
        !            21: #if    defined (__HUGE__) || defined (__COMPACT__) || defined (__LARGE__)
        !            22: 
        !            23: void * ATOMIC_FETCH_AND_STORE_PTR (__atomic_ptr_t lock, void * value) {
        !            24:        long            temp;
        !            25:        temp = ATOMIC_FETCH_AND_STORE_LONG (lock, (long) value);
        !            26:        return (void *) temp;
        !            27: }
        !            28: 
        !            29: #if 0
        !            30: void * ATOMIC_FETCH_PTR (__atomic_ptr_t lock) {
        !            31:        return (void *) ATOMIC_FETCH_LONG (lock);
        !            32: }
        !            33: #endif
        !            34: 
        !            35: #endif /* large data model */
        !            36: 
        !            37: #endif /* __BORLANDC__ */
        !            38: 
        !            39: #ifndef        __LOCAL__
        !            40: #error
        !            41: #endif
        !            42: 
        !            43: /*
        !            44:  * Here we exercise the atomic operations. Note that these tests have revealed
        !            45:  * many important subtleties of the way the operations and the compilers work
        !            46:  * during the development of the <sys/x86lock.h> header; in particular, the
        !            47:  * tests below reveal some important things about the use of the "volatile"
        !            48:  * keyword in highly optimizing compilers like GCC, where the compiler was
        !            49:  * able to statically (and incorrectly) predict what the result "ought" to
        !            50:  * have been.
        !            51:  *
        !            52:  * Having said that, in systems which are capable of in-line code generation
        !            53:  * it also pays to ensure that operations are not being *totally* elided due
        !            54:  * to overzealous optimization. This can really only be done by manual
        !            55:  * examination of the form of the generated code.
        !            56:  */
        !            57: 
        !            58: __LOCAL__      atomic_char_t   achar;
        !            59: __LOCAL__      atomic_uchar_t  auchar;
        !            60: __LOCAL__      atomic_short_t  ashort;
        !            61: __LOCAL__      atomic_ushort_t aushort;
        !            62: __LOCAL__      atomic_int_t    aint;
        !            63: __LOCAL__      atomic_uint_t   auint;
        !            64: __LOCAL__      atomic_long_t   along;
        !            65: __LOCAL__      atomic_ulong_t  aulong;
        !            66: __LOCAL__      atomic_ptr_t    aptr;
        !            67: 
        !            68: __EXTERN_C__
        !            69: #if    __USE_PROTO__
        !            70: int (testX86) (void)
        !            71: #else
        !            72: int
        !            73: testX86 __ARGS (())
        !            74: #endif
        !            75: {
        !            76:        char            achartemp = '1';
        !            77:        uchar_t         auchartemp = 'y';
        !            78:        short           ashorttemp = -2438;
        !            79:        ushort_t        aushorttemp = 12034;
        !            80:        int             ainttemp = -12438;
        !            81:        uint_t          auinttemp = 21349;
        !            82:        long            alongtemp = -1385866L;
        !            83:        ulong_t         aulongtemp = 124875656L;
        !            84:        _VOID         * aptrtemp = & achartemp;
        !            85: 
        !            86:        /*
        !            87:         * Set some sensible initial values.
        !            88:         */
        !            89: 
        !            90:        (void) ATOMIC_FETCH_AND_STORE_CHAR (achar, achartemp);
        !            91:        (void) ATOMIC_FETCH_AND_STORE_UCHAR (auchar, auchartemp);
        !            92:        (void) ATOMIC_FETCH_AND_STORE_SHORT (ashort, ashorttemp);
        !            93:        (void) ATOMIC_FETCH_AND_STORE_USHORT (aushort, aushorttemp);
        !            94:        (void) ATOMIC_FETCH_AND_STORE_INT (aint, ainttemp);
        !            95:        (void) ATOMIC_FETCH_AND_STORE_UINT (auint, auinttemp);
        !            96:        (void) ATOMIC_FETCH_AND_STORE_LONG (along, alongtemp);
        !            97:        (void) ATOMIC_FETCH_AND_STORE_ULONG (aulong, aulongtemp);
        !            98:        (void) ATOMIC_FETCH_AND_STORE_PTR (aptr, aptrtemp);
        !            99: 
        !           100: 
        !           101:        if (ATOMIC_FETCH_CHAR (achar) != achartemp ||
        !           102:            ATOMIC_FETCH_UCHAR (auchar) != auchartemp ||
        !           103:            ATOMIC_FETCH_SHORT (ashort) != ashorttemp ||
        !           104:            ATOMIC_FETCH_USHORT (aushort) != aushorttemp ||
        !           105:            ATOMIC_FETCH_INT (aint) != ainttemp ||
        !           106:            ATOMIC_FETCH_UINT (auint) != auinttemp ||
        !           107:            ATOMIC_FETCH_LONG (along) != alongtemp ||
        !           108:            ATOMIC_FETCH_ULONG (aulong) != aulongtemp ||
        !           109:            ATOMIC_FETCH_PTR (aptr) != aptrtemp ||
        !           110: 
        !           111:            ATOMIC_FETCH_AND_STORE_CHAR (achar, SCHAR_MAX) != achartemp ||
        !           112:            ATOMIC_FETCH_AND_STORE_UCHAR (auchar, UCHAR_MAX) != auchartemp ||
        !           113:            ATOMIC_FETCH_AND_STORE_SHORT (ashort, SHRT_MAX) != ashorttemp ||
        !           114:            ATOMIC_FETCH_AND_STORE_USHORT (aushort, USHRT_MAX) != aushorttemp ||
        !           115:            ATOMIC_FETCH_AND_STORE_INT (aint, INT_MAX) != ainttemp ||
        !           116:            ATOMIC_FETCH_AND_STORE_UINT (auint, UINT_MAX) != auinttemp ||
        !           117:            ATOMIC_FETCH_AND_STORE_LONG (along, LONG_MAX) != alongtemp ||
        !           118:            ATOMIC_FETCH_AND_STORE_ULONG (aulong, ULONG_MAX) != aulongtemp ||
        !           119:            ATOMIC_FETCH_AND_STORE_PTR (aptr, & aulongtemp) != aptrtemp ||
        !           120: 
        !           121:            ATOMIC_FETCH_CHAR (achar) != SCHAR_MAX ||
        !           122:            ATOMIC_FETCH_UCHAR (auchar) != UCHAR_MAX ||
        !           123:            ATOMIC_FETCH_SHORT (ashort) != SHRT_MAX ||
        !           124:            ATOMIC_FETCH_USHORT (aushort) != USHRT_MAX ||
        !           125:            ATOMIC_FETCH_INT (aint) != INT_MAX ||
        !           126:            ATOMIC_FETCH_UINT (auint) != UINT_MAX ||
        !           127:            ATOMIC_FETCH_LONG (along) != LONG_MAX ||
        !           128:            ATOMIC_FETCH_ULONG (aulong) != ULONG_MAX ||
        !           129:            ATOMIC_FETCH_PTR (aptr) != & aulongtemp ||
        !           130: 
        !           131:            ATOMIC_FETCH_AND_STORE_CHAR (achar, SCHAR_MIN) != SCHAR_MAX ||
        !           132:            ATOMIC_FETCH_AND_STORE_UCHAR (auchar, 0) != UCHAR_MAX ||
        !           133:            ATOMIC_FETCH_AND_STORE_SHORT (ashort, SHRT_MIN) != SHRT_MAX ||
        !           134:            ATOMIC_FETCH_AND_STORE_USHORT (aushort, 0) != USHRT_MAX ||
        !           135:            ATOMIC_FETCH_AND_STORE_INT (aint, INT_MIN) != INT_MAX ||
        !           136:            ATOMIC_FETCH_AND_STORE_UINT (auint, 0) != UINT_MAX ||
        !           137:            ATOMIC_FETCH_AND_STORE_LONG (along, LONG_MIN) != LONG_MAX ||
        !           138:            ATOMIC_FETCH_AND_STORE_ULONG (aulong, 0) != ULONG_MAX ||
        !           139:            ATOMIC_FETCH_AND_STORE_PTR (aptr, 0) != & aulongtemp ||
        !           140: 
        !           141:            ATOMIC_FETCH_CHAR (achar) != SCHAR_MIN ||
        !           142:            ATOMIC_FETCH_UCHAR (auchar) != 0 ||
        !           143:            ATOMIC_FETCH_SHORT (ashort) != SHRT_MIN ||
        !           144:            ATOMIC_FETCH_USHORT (aushort) != 0 ||
        !           145:            ATOMIC_FETCH_INT (aint) != INT_MIN ||
        !           146:            ATOMIC_FETCH_UINT (auint) != 0 ||
        !           147:            ATOMIC_FETCH_LONG (along) != LONG_MIN ||
        !           148:            ATOMIC_FETCH_ULONG (aulong) != 0 ||
        !           149:            ATOMIC_FETCH_PTR (aptr) != 0 ||
        !           150: 
        !           151:            ATOMIC_FETCH_AND_STORE_CHAR (achar, 0) != SCHAR_MIN ||
        !           152:            ATOMIC_FETCH_AND_STORE_UCHAR (auchar, 0) != 0 ||
        !           153:            ATOMIC_FETCH_AND_STORE_SHORT (ashort, 0) != SHRT_MIN ||
        !           154:            ATOMIC_FETCH_AND_STORE_USHORT (aushort, 0) != 0 ||
        !           155:            ATOMIC_FETCH_AND_STORE_INT (aint, 0) != INT_MIN ||
        !           156:            ATOMIC_FETCH_AND_STORE_UINT (auint, 0) != 0 ||
        !           157:            ATOMIC_FETCH_AND_STORE_LONG (along, 0) != LONG_MIN ||
        !           158:            ATOMIC_FETCH_AND_STORE_ULONG (aulong, 0) !=  0 ||
        !           159:            ATOMIC_FETCH_AND_STORE_PTR (aptr, 0) != 0 ||
        !           160: 
        !           161:            ATOMIC_TEST_AND_SET_UCHAR (auchar) != 0 ||
        !           162:            ATOMIC_FETCH_UCHAR (auchar) != (uchar_t) -1 ||
        !           163:            ATOMIC_TEST_AND_SET_UCHAR (auchar) != (uchar_t) -1 ||
        !           164:            (ATOMIC_CLEAR_UCHAR (auchar),
        !           165:             ATOMIC_FETCH_UCHAR (auchar)) != 0)
        !           166: 
        !           167:                return -1;
        !           168: 
        !           169:        return 0;
        !           170: }
        !           171: 
        !           172: 
        !           173: #ifdef TEST
        !           174: #include <stdio.h>
        !           175: 
        !           176: int main (void) {
        !           177:        printf (testX86 () ? "failed\n" : "passed\n");
        !           178:        return 0;
        !           179: }
        !           180: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.