stdio-lock.h
001: 
002: 
003: 
004: 
005: 
006: 
007: 
008: 
009: 
010: 
011: 
012: 
013: 
014: 
015: 
016: 
017: 
018: 
019: 
020: #ifndef _BITS_STDIO_LOCK_H
021: #define _BITS_STDIO_LOCK_H 1
022: 
023: #include <bits/libc-lock.h>
024: #include <lowlevellock.h>
025: 
026: 
027: 
028: #define _IO_lock_inexpensive    1
029: 
030: typedef struct { int lock; int cnt; void *owner; } _IO_lock_t;
031: 
032: #define _IO_lock_initializer { LLL_LOCK_INITIALIZER, 0, NULL }
033: 
034: #define _IO_lock_init(_name) \
035:   ((_name) = (_IO_lock_t) _IO_lock_initializer , 0)
036: 
037: #define _IO_lock_fini(_name) \
038:   ((void) 0)
039: 
040: #define _IO_lock_lock(_name) \
041:   do {                                                                        \
042:     void *__self = THREAD_SELF;                                               \
043:     if ((_name).owner != __self)                                              \
044:       {                                                                       \
045:         lll_lock ((_name).lock, LLL_PRIVATE);                                 \
046:         (_name).owner = __self;                                               \
047:       }                                                                       \
048:     ++(_name).cnt;                                                            \
049:   } while (0)
050: 
051: #define _IO_lock_trylock(_name) \
052:   ({                                                                          \
053:     int __result = 0;                                                         \
054:     void *__self = THREAD_SELF;                                               \
055:     if ((_name).owner != __self)                                              \
056:       {                                                                       \
057:         if (lll_trylock ((_name).lock) == 0)                                  \
058:           {                                                                   \
059:             (_name).owner = __self;                                           \
060:             (_name).cnt = 1;                                                  \
061:           }                                                                   \
062:         else                                                                  \
063:           __result = EBUSY;                                                   \
064:       }                                                                       \
065:     else                                                                      \
066:       ++(_name).cnt;                                                          \
067:     __result;                                                                 \
068:   })
069: 
070: #define _IO_lock_unlock(_name) \
071:   do {                                                                        \
072:     if (--(_name).cnt == 0)                                                   \
073:       {                                                                       \
074:         (_name).owner = NULL;                                                 \
075:         lll_unlock ((_name).lock, LLL_PRIVATE);                               \
076:       }                                                                       \
077:   } while (0)
078: 
079: 
080: 
081: #define _IO_cleanup_region_start(_fct, _fp) \
082:   __libc_cleanup_region_start (((_fp)->_flags & _IO_USER_LOCK) == 0, _fct, _fp)
083: #define _IO_cleanup_region_start_noarg(_fct) \
084:   __libc_cleanup_region_start (1, _fct, NULL)
085: #define _IO_cleanup_region_end(_doit) \
086:   __libc_cleanup_region_end (_doit)
087: 
088: #if defined _LIBC && !defined NOT_IN_libc
089: 
090: # ifdef __EXCEPTIONS
091: #  define _IO_acquire_lock(_fp) \
092:   do {                                                                        \
093:     _IO_FILE *_IO_acquire_lock_file                                           \
094:         __attribute__((cleanup (_IO_acquire_lock_fct)))                       \
095:         = (_fp);                                                              \
096:     _IO_flockfile (_IO_acquire_lock_file);
097: #  define _IO_acquire_lock_clear_flags2(_fp) \
098:   do {                                                                        \
099:     _IO_FILE *_IO_acquire_lock_file                                           \
100:         __attribute__((cleanup (_IO_acquire_lock_clear_flags2_fct)))          \
101:         = (_fp);                                                              \
102:     _IO_flockfile (_IO_acquire_lock_file);
103: # else
104: #  define _IO_acquire_lock(_fp) _IO_acquire_lock_needs_exceptions_enabled
105: #  define _IO_acquire_lock_clear_flags2(_fp) _IO_acquire_lock (_fp)
106: # endif
107: # define _IO_release_lock(_fp) ; } while (0)
108: 
109: #endif
110: 
111: #endif 
112: 
      
      
      
      
   
      
      
         
            
            © Andrew Scott 2006 -
            2025, 
            All Rights Reserved