source: trunk/libs/newlib/src/newlib/libc/sys/linux/linuxthreads/lockfile.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.4 KB
Line 
1/* lockfile - Handle locking and unlocking of stream.
2   Copyright (C) 1996, 1998, 2000 Free Software Foundation, Inc.
3   This file is part of the GNU C Library.
4
5   The GNU C Library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   The GNU C Library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Library General Public License for more details.
14
15   You should have received a copy of the GNU Library General Public
16   License along with the GNU C Library; see the file COPYING.LIB.  If not,
17   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18   Boston, MA 02111-1307, USA.  */
19
20#include <sys/lock.h>
21#include <stdio.h>
22#include <pthread.h>
23#include "internals.h"
24
25#ifdef USE_IN_LIBIO
26#include "../libio/libioP.h"
27#endif
28
29#ifndef SHARED
30/* We need a hook to force this file to be linked in when static
31   libpthread is used.  */
32const int __pthread_provide_lockfile = 0;
33#endif
34
35void
36__flockfile (FILE *stream)
37{
38  __lock_acquire_recursive (*(_LOCK_RECURSIVE_T *)&stream->_lock);
39}
40#undef _IO_flockfile
41strong_alias (__flockfile, _IO_flockfile)
42weak_alias (__flockfile, flockfile);
43
44
45void
46__funlockfile (FILE *stream)
47{
48  __lock_release_recursive (*(_LOCK_RECURSIVE_T *)&stream->_lock);
49}
50#undef _IO_funlockfile
51strong_alias (__funlockfile, _IO_funlockfile)
52weak_alias (__funlockfile, funlockfile);
53
54
55int
56__ftrylockfile (FILE *stream)
57{
58  return __lock_try_acquire_recursive (*(_LOCK_RECURSIVE_T *)&stream->_lock);
59}
60strong_alias (__ftrylockfile, _IO_ftrylockfile)
61weak_alias (__ftrylockfile, ftrylockfile);
62
63void
64__flockfilelist(void)
65{
66#ifdef USE_IN_LIBIO
67  _IO_list_lock();
68#endif
69}
70
71void
72__funlockfilelist(void)
73{
74#ifdef USE_IN_LIBIO
75  _IO_list_unlock();
76#endif
77}
78
79void
80__fresetlockfiles (void)
81{
82#ifdef USE_IN_LIBIO
83  _IO_ITER i;
84
85  pthread_mutexattr_t attr;
86
87  __pthread_mutexattr_init (&attr);
88  __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
89
90  for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
91    __pthread_mutex_init (_IO_iter_file(i)->_lock, &attr);
92
93  __pthread_mutexattr_destroy (&attr);
94
95  _IO_list_resetlock();
96#endif
97}
Note: See TracBrowser for help on using the repository browser.