Changeset 1661 for trunk/src/emx/include


Ignore:
Timestamp:
Nov 22, 2004, 2:46:26 AM (21 years ago)
Author:
bird
Message:

Extended fmutex interface.

Location:
trunk/src/emx/include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1660 r1661  
    207207
    208208#define STREAM_LOCK(f) \
    209   (_fmutex_request(&(f)->__u.__fsem, _FMR_IGNINT) != 0 \
    210    ? abort () : (void)0)
     209  ((f)->__uVersion != _FILE_STDIO_VERSION ? __stream_abort (f, "version error") \
     210   : _fmutex_request(&(f)->__u.__fsem, _FMR_IGNINT) != 0 \
     211   ? __stream_abort (f, "fmutex request") : 0)
    211212
    212213#define STREAM_UNLOCK(f) \
    213   (_fmutex_release(&(f)->__u.__fsem) != 0 ? abort() : (void)0)
     214  (_fmutex_release(&(f)->__u.__fsem) != 0 ? __stream_abort (f, "fmutex release") : (void)0)
    214215
    215216#define STREAM_LOCK_NOWAIT(f) \
    216   (_fmutex_request(&(f)->__u.__fsem, _FMR_NOWAIT) == 0)
    217 
    218 #define STREAM_UNLOCKED(f) _fmutex_available(&(f)->__u.__fsem)
     217  (((f)->__uVersion == _FILE_STDIO_VERSION || __stream_abort (f, "version error")) && _fmutex_request(&(f)->__u.__fsem, _FMR_NOWAIT) == 0)
     218
     219#define STREAM_UNLOCKED(f) ((f)->__uVersion == _FILE_STDIO_VERSION && _fmutex_available(&(f)->__u.__fsem))
     220
     221int __stream_abort(struct _FILE *f, const char *pszMsg);
    219222
    220223#endif /* defined (_SYS_FMUTEX_H) */
  • trunk/src/emx/include/os2emx.h

    • Property cvs2svn:cvs-rev changed from 1.24 to 1.25
    r1660 r1661  
    1330813308#define FS_SAVE()       __asm__ __volatile__ ("movl %%fs, %%eax; movl %%eax,%0;" : : "m" (__fs__) : "%eax" )
    1330913309#define FS_SAVE_LOAD()  __asm__ __volatile__ ("movl %%fs, %%eax; movl %%eax,%0; movl $DosTIB, %%eax; movl %%eax, %%fs" : : "m" (__fs__) : "%eax" )
     13310#define FS_VAR_SAVE_LOAD() FS_VAR(); FS_SAVE_LOAD()
    1331013311#define FS_RESTORE()    __asm__ __volatile__ ("movl %0, %%eax; movl %%eax,%%fs;" : : "m" (__fs__) : "%eax" )
    1331113312#else
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r1660 r1661  
    178178#define _FILE_T
    179179#define _FILE_MEMBERS_HAVE_UNDERSCORE
    180 struct _file2;
     180#define _FILE_STDIO_VERSION     (0x06000000 | sizeof(struct _FILE))
    181181typedef struct _FILE
    182182{
     183    unsigned __uVersion;
    183184    char * _ptr;
    184185    char * _buffer;
     
    201202        _fmutex   __fsem;
    202203#endif
    203         char      __rsem_ersatz[8];
     204        char      __rsem_ersatz[12];
    204205    } __u;
    205     /** Pointer to the stream vector which thie FILE belongs to.
     206    /** Pointer to the stream vector which this FILE belongs to.
    206207     * This member is the first which should not be zeroed by _newstream()! */
    207208    void    *__pSV;
  • trunk/src/emx/include/sys/fmutex.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1660 r1661  
    66
    77#ifndef _SYS_FMUTEX_H
    8 #define _SYS_FMUTEX_H
     8    #define _SYS_FMUTEX_H
    99
    10 #include <stdlib.h> /* need abort */
     10    #include <sys/cdefs.h>
     11    #include <stdlib.h> /* need abort */
     12    #include <InnoTekLIBC/FastInfoBlocks.h>
    1113
    12 #if defined (__cplusplus)
    13 extern "C" {
    14 #endif
     14__BEGIN_DECLS
    1515
    1616/* Constants for _fmutex.fs.  See _fmutex_available() for ordering. */
    1717
    18 #define _FMS_UNINIT       0
    19 #define _FMS_AVAILABLE    1
    20 #define _FMS_OWNED_SIMPLE 2
    21 #define _FMS_OWNED_HARD   3
     18    #define _FMS_UNINIT       0
     19    #define _FMS_AVAILABLE    1
     20    #define _FMS_OWNED_SIMPLE 2
     21    #define _FMS_OWNED_HARD   3
    2222
    2323/* Constants for _fmutex_create() */
    2424
    25 #define _FMC_SHARED     0x01
     25    #define _FMC_SHARED         0x01
     26    #define _FMC_MUST_COMPLETE  0x02
     27    #define _FMC_DUMMY          0x04    /* internal */
    2628
    2729/* Constants for _fmutex_request() */
    2830
    29 #define _FMR_IGNINT     0x01
    30 #define _FMR_NOWAIT     0x02
     31    #define _FMR_IGNINT     0x01
     32    #define _FMR_NOWAIT     0x02
    3133
    3234/* We cannot use __attribute__ ((__packed__)) because G++ does not
    3335   support this. */
    3436
    35 #pragma pack(1)
     37    #pragma pack(1)
    3638typedef struct
    3739{
    3840    /** Handle to event semaphore. */
    39     unsigned long hev;
     41    unsigned long           hev;
    4042    /** Semaphore status. */
    41     __volatile__ signed char fs;
     43    volatile signed char    fs;
    4244    /** Semaphore create flags. (_FMC_SHARED) */
    43     unsigned char flags;
    44     /** padding the struct to 8 bytes. */
    45     unsigned char padding[2];
     45    unsigned char           flags;
     46    /** padding the struct to 16 bytes. */
     47    unsigned char           padding[2];
     48    /** The (pid << 16) | tid of the owner. */
     49    volatile unsigned       Owner;
     50    /** Descriptive name of the mutex. */
     51    const char             *pszDesc;
    4652} _fmutex;
    47 #pragma pack()
     53    #pragma pack()
     54
    4855
    4956
    5057unsigned __fmutex_request_internal (_fmutex *, unsigned, signed char);
    51 unsigned __fmutex_create_internal (_fmutex *, unsigned);
     58unsigned __fmutex_request_internal_must_complete (_fmutex *, unsigned);
    5259unsigned __fmutex_release_internal (_fmutex *);
     60unsigned __fmutex_release_internal_must_complete (_fmutex *);
    5361
    5462
    5563static __inline__ unsigned _fmutex_request (_fmutex *sem, unsigned flags)
    5664{
    57   signed char fs;
    58 
    59   fs = __cxchg (&sem->fs, _FMS_OWNED_SIMPLE);
    60   if (fs == _FMS_AVAILABLE)
    61     return 0;
    62   else
    63     return __fmutex_request_internal (sem, flags, fs);
     65    if (!(sem->flags & _FMC_MUST_COMPLETE))
     66    {
     67        signed char fs = __cxchg (&sem->fs, _FMS_OWNED_SIMPLE);
     68        if (fs == _FMS_AVAILABLE)
     69        {
     70            __atomic_xchg(&sem->Owner, fibGetTidPid());
     71            return 0;
     72        }
     73        else
     74            return __fmutex_request_internal (sem, flags, fs);
     75    }
     76    else
     77        return __fmutex_request_internal_must_complete (sem, flags);
    6478}
    6579
     
    6781static __inline__ unsigned _fmutex_release (_fmutex *sem)
    6882{
    69   signed char fs;
    70 
    71   fs = __cxchg (&sem->fs, _FMS_AVAILABLE);
    72   if (fs == _FMS_OWNED_HARD)
    73     return __fmutex_release_internal (sem);
    74   else
    75     return 0;
     83    if (!(sem->flags & _FMC_MUST_COMPLETE))
     84    {
     85        signed char fs;
     86        __atomic_xchg(&sem->Owner, 0);
     87        fs = __cxchg(&sem->fs, _FMS_AVAILABLE);
     88        if (fs != _FMS_OWNED_HARD)
     89            return 0;
     90        else
     91            return __fmutex_release_internal (sem);
     92    }
     93    else
     94        return __fmutex_release_internal_must_complete (sem);
    7695}
    77 
    7896
    7997static __inline__ int _fmutex_available (_fmutex *sem)
    8098{
    81   return sem->fs <= _FMS_AVAILABLE;
     99    return sem->fs <= _FMS_AVAILABLE;
    82100}
    83101
    84102
    85103unsigned _fmutex_create (_fmutex *, unsigned);
     104unsigned _fmutex_create2 (_fmutex *sem, unsigned, const char *);
    86105unsigned _fmutex_open (_fmutex *);
    87106unsigned _fmutex_close (_fmutex *);
    88107void _fmutex_dummy (_fmutex *);
    89108
    90 void _fmutex_checked_close (_fmutex *);
    91 void _fmutex_checked_create (_fmutex *, unsigned);
    92 void _fmutex_checked_open (_fmutex *);
     109void _fmutex_checked_close(_fmutex *);
     110void _fmutex_checked_create(_fmutex *, unsigned);
     111void _fmutex_checked_create2(_fmutex *, unsigned, const char *);
     112void _fmutex_checked_open(_fmutex *);
     113void _fmutex_abort(_fmutex *, const char *);
    93114
    94115static __inline__ void _fmutex_checked_release (_fmutex * sem)
    95116{
    96   if (_fmutex_release (sem) != 0)
    97     abort ();
     117    if (sem->Owner != fibGetTidPid())
     118        _fmutex_abort(sem, "release not owner");
     119    if (_fmutex_release (sem) != 0)
     120        _fmutex_abort(sem, "release");
    98121}
    99122
    100123static __inline__ void _fmutex_checked_request (_fmutex * sem, unsigned flags)
    101124{
    102   if (_fmutex_request (sem, flags) != 0)
    103     abort ();
     125    if (_fmutex_request (sem, flags) != 0)
     126        _fmutex_abort(sem, "request");
    104127}
    105128
    106 #if defined (__cplusplus)
    107 }
    108 #endif
     129__END_DECLS
    109130
    110131#endif /* not _SYS_FMUTEX_H */
     132
Note: See TracChangeset for help on using the changeset viewer.