6
** Written by Kiem-Phong Vo.
9
#define STKMTXLOCK(f1,f2) \
10
{ if(f1) SFMTXLOCK(f1); \
11
if(f2) SFMTXLOCK(f2); \
13
#define STKMTXRETURN(f1,f2,rv) \
14
{ if(f1) SFMTXUNLOCK(f1); \
15
if(f2) SFMTXUNLOCK(f2); \
20
Sfio_t* sfstack(Sfio_t* f1, Sfio_t* f2)
22
Sfio_t* sfstack(f1,f2)
23
Sfio_t* f1; /* base of stack */
24
Sfio_t* f2; /* top of stack */
34
if(f1 && (f1->mode&SF_RDWR) != f1->mode && _sfmode(f1,0,0) < 0)
35
STKMTXRETURN(f1,f2, NIL(Sfio_t*));
36
if(f2 && (f2->mode&SF_RDWR) != f2->mode && _sfmode(f2,0,0) < 0)
37
STKMTXRETURN(f1,f2, NIL(Sfio_t*));
39
STKMTXRETURN(f1,f2, f2);
41
/* give access to other internal functions */
45
{ if(!(f2 = f1->push))
46
STKMTXRETURN(f1,f2, NIL(Sfio_t*));
51
STKMTXRETURN(f1,f2, NIL(Sfio_t*));
52
if(f1->pool && f1->pool != &_Sfpool && f1->pool != f2->pool &&
53
f1 == f1->pool->sf[0])
54
{ /* get something else to pool front since f1 will be locked */
55
for(n = 1; n < f1->pool->n_sf; ++n)
56
{ if(SFFROZEN(f1->pool->sf[n]) )
58
(*_Sfpmove)(f1->pool->sf[n],0);
64
if(f2->pool && f2->pool != &_Sfpool && f2 != f2->pool->sf[0])
70
/* but the reserved buffer and mutex must remain the same */
71
rsrv = f1->rsrv; f1->rsrv = f2->rsrv; f2->rsrv = rsrv;
72
mtx = f1->mutex; f1->mutex = f2->mutex; f2->mutex = mtx;
78
{ /* freeze the pushed stream */
84
{ /* unfreeze the just exposed stream */
86
f2->push = NIL(Sfio_t*);
93
STKMTXRETURN(f1,f2, rf);