Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


stdio-lock.h
001: /* Thread package specific definitions of stream lock type.  NPTL version.
002:    Copyright (C) 2000, 2001, 2002, 2003, 2007 Free Software Foundation, Inc.
003:    This file is part of the GNU C Library.
004: 
005:    The GNU C Library is free software; you can redistribute it and/or
006:    modify it under the terms of the GNU Lesser General Public
007:    License as published by the Free Software Foundation; either
008:    version 2.1 of the License, or (at your option) any later version.
009: 
010:    The GNU C Library is distributed in the hope that it will be useful,
011:    but WITHOUT ANY WARRANTY; without even the implied warranty of
012:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:    Lesser General Public License for more details.
014: 
015:    You should have received a copy of the GNU Lesser General Public
016:    License along with the GNU C Library; if not, write to the Free
017:    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
018:    02111-1307 USA.  */
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: /* The locking here is very inexpensive, even for inlining.  */
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 /* bits/stdio-lock.h */
112: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/