home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / get_file.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  2.4 KB  |  123 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.20.45.35;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @get/release exclusive access to a struct file
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @add new sleep parameter
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  *
  48.  *  $Id: get_file.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  49.  *
  50.  *  $Log: get_file.c,v $
  51.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  52.  *  Initial revision
  53.  *
  54.  */
  55.  
  56. #define KERNEL
  57. #include "ixemul.h"
  58.  
  59. #ifdef DEBUG
  60. #define DP(a) kprintf a
  61. #else
  62. #define DP(a)
  63. #endif
  64.  
  65. int
  66. __get_file (struct file *f)
  67. {
  68.   int res = 0;
  69.  
  70.   Forbid ();
  71.   for (;;)
  72.     {
  73.       if (!(f->f_sync_flags & FSFF_LOCKED))
  74.         {
  75.           f->f_sync_flags |= FSFF_LOCKED;
  76.           /* got it ! */
  77.           break;
  78.     }
  79.       f->f_sync_flags |= FSFF_WANTLOCK;
  80. DP(("__get_file: TYPE=%ld, name=%s going to sleep\n",
  81.    f->f_type, f->f_type == DTYPE_FILE ? f->f_name : "`na'"));
  82.       if (ix_sleep (& f->f_sync_flags, "get_file") < 0)    /* error in sleep, might be INTR */
  83.         {
  84. DP(("__get_file interrupted\n"));
  85.       res = -1;
  86.           break;
  87.         }
  88.       /* have to always recheck whether we really got the lock */
  89.     }
  90.   Permit ();      
  91.   return res;
  92. }
  93.  
  94.  
  95. void
  96. __release_file (struct file *f)
  97. {
  98.   Forbid ();
  99.   if (f->f_sync_flags & FSFF_WANTLOCK)
  100.     ix_wakeup (& f->f_sync_flags);
  101.     
  102.   f->f_sync_flags &= ~(FSFF_WANTLOCK|FSFF_LOCKED);
  103.   Permit ();
  104. }
  105. @
  106.  
  107.  
  108. 1.1
  109. log
  110. @Initial revision
  111. @
  112. text
  113. @d19 1
  114. a19 1
  115.  *  $Id$
  116. d21 4
  117. a24 1
  118.  *  $Log$
  119. d53 1
  120. a53 1
  121.       if (ix_sleep (& f->f_sync_flags) < 0)    /* error in sleep, might be INTR */
  122. @
  123.