sfstack.c revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/***********************************************************************
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* This software is part of the ast package *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* Copyright (c) 1985-2009 AT&T Intellectual Property *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* and is licensed under the *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* Common Public License, Version 1.0 *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* by AT&T Intellectual Property *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* A copy of the License is available at *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* http://www.opensource.org/licenses/cpl1.0.txt *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* Information and Software Systems Research *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov* AT&T Research *
5dbfd19ad5fcc2b779f40f80fa05c1bd28fd0b4eTheo Schlossnagle* Florham Park NJ *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov* Glenn Fowler <gsf@research.att.com> *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe* David Korn <dgk@research.att.com> *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov* Phong Vo <kpv@research.att.com> *
a9478106a12424322498e53cf7cd75bd8a4d6004Yuri Pankov***********************************************************************/
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe** Written by Kiem-Phong Vo.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if(f1 && (f1->mode&SF_RDWR) != f1->mode && _sfmode(f1,0,0) < 0)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if(f2 && (f2->mode&SF_RDWR) != f2->mode && _sfmode(f2,0,0) < 0)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* give access to other internal functions */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if(f1->pool && f1->pool != &_Sfpool && f1->pool != f2->pool &&
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe { /* get something else to pool front since f1 will be locked */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if(f2->pool && f2->pool != &_Sfpool && f2 != f2->pool->sf[0])
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* swap streams */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* but the reserved buffer and mutex must remain the same */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe rsrv = f1->rsrv; f1->rsrv = f2->rsrv; f2->rsrv = rsrv;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mtx = f1->mutex; f1->mutex = f2->mutex; f2->mutex = mtx;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe { /* freeze the pushed stream */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe { /* unfreeze the just exposed stream */