Back to index

glibc  2.9
lockfile.c
Go to the documentation of this file.
00001 /* lockfile - Handle locking and unlocking of stream.
00002    Copyright (C) 1996, 1998, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #include <bits/libc-lock.h>
00021 #include <stdio.h>
00022 #include <pthread.h>
00023 #include "internals.h"
00024 #include "../libio/libioP.h"
00025 
00026 void
00027 __flockfile (FILE *stream)
00028 {
00029   __pthread_mutex_lock (stream->_lock);
00030 }
00031 #undef _IO_flockfile
00032 strong_alias (__flockfile, _IO_flockfile)
00033 weak_alias (__flockfile, flockfile);
00034 
00035 
00036 void
00037 __funlockfile (FILE *stream)
00038 {
00039   __pthread_mutex_unlock (stream->_lock);
00040 }
00041 #undef _IO_funlockfile
00042 strong_alias (__funlockfile, _IO_funlockfile)
00043 weak_alias (__funlockfile, funlockfile);
00044 
00045 
00046 int
00047 __ftrylockfile (FILE *stream)
00048 {
00049   return __pthread_mutex_trylock (stream->_lock);
00050 }
00051 strong_alias (__ftrylockfile, _IO_ftrylockfile)
00052 weak_alias (__ftrylockfile, ftrylockfile);
00053 
00054 void
00055 __flockfilelist(void)
00056 {
00057   _IO_list_lock();
00058 }
00059 
00060 void
00061 __funlockfilelist(void)
00062 {
00063   _IO_list_unlock();
00064 }
00065 
00066 void
00067 __fresetlockfiles (void)
00068 {
00069   _IO_ITER i;
00070 
00071   pthread_mutexattr_t attr;
00072 
00073   __pthread_mutexattr_init (&attr);
00074   __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
00075 
00076   for (i = _IO_iter_begin(); i != _IO_iter_end(); i = _IO_iter_next(i))
00077     __pthread_mutex_init (_IO_iter_file(i)->_lock, &attr);
00078 
00079   __pthread_mutexattr_destroy (&attr);
00080 
00081   _IO_list_resetlock();
00082 }