1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 ** Written by Kiem-Phong Vo.
30 #define STKMTXLOCK(f1,f2) \
31 { if(f1) SFMTXLOCK(f1); \
32 if(f2) SFMTXLOCK(f2); \
34 #define STKMTXRETURN(f1,f2,rv) \
35 { if(f1) SFMTXUNLOCK(f1); \
36 if(f2) SFMTXUNLOCK(f2); \
41 Sfio_t
* sfstack(Sfio_t
* f1
, Sfio_t
* f2
)
43 Sfio_t
* sfstack(f1
,f2
)
44 Sfio_t
* f1
; /* base of stack */
45 Sfio_t
* f2
; /* top of stack */
55 if(f1
&& (f1
->mode
&SF_RDWR
) != f1
->mode
&& _sfmode(f1
,0,0) < 0)
56 STKMTXRETURN(f1
,f2
, NIL(Sfio_t
*));
57 if(f2
&& (f2
->mode
&SF_RDWR
) != f2
->mode
&& _sfmode(f2
,0,0) < 0)
58 STKMTXRETURN(f1
,f2
, NIL(Sfio_t
*));
60 STKMTXRETURN(f1
,f2
, f2
);
62 /* give access to other internal functions */
66 { if(!(f2
= f1
->push
))
67 STKMTXRETURN(f1
,f2
, NIL(Sfio_t
*));
72 STKMTXRETURN(f1
,f2
, NIL(Sfio_t
*));
73 if(f1
->pool
&& f1
->pool
!= &_Sfpool
&& f1
->pool
!= f2
->pool
&&
74 f1
== f1
->pool
->sf
[0])
75 { /* get something else to pool front since f1 will be locked */
76 for(n
= 1; n
< f1
->pool
->n_sf
; ++n
)
77 { if(SFFROZEN(f1
->pool
->sf
[n
]) )
79 (*_Sfpmove
)(f1
->pool
->sf
[n
],0);
85 if(f2
->pool
&& f2
->pool
!= &_Sfpool
&& f2
!= f2
->pool
->sf
[0])
91 /* but the reserved buffer and mutex must remain the same */
92 rsrv
= f1
->rsrv
; f1
->rsrv
= f2
->rsrv
; f2
->rsrv
= rsrv
;
93 mtx
= f1
->mutex
; f1
->mutex
= f2
->mutex
; f2
->mutex
= mtx
;
99 { /* freeze the pushed stream */
105 { /* unfreeze the just exposed stream */
106 f1
->mode
&= ~SF_PUSH
;
107 f2
->push
= NIL(Sfio_t
*);
114 STKMTXRETURN(f1
,f2
, rf
);