Blob


1 #include "threadimpl.h"
3 long
4 iocall(Ioproc *io, long (*op)(va_list*), ...)
5 {
6 int ret, inted;
7 Ioproc *msg;
9 if(send(io->c, &io) == -1){
10 werrstr("interrupted");
11 return -1;
12 }
13 assert(!io->inuse);
14 io->inuse = 1;
15 io->op = op;
16 va_start(io->arg, op);
17 msg = io;
18 inted = 0;
19 while(send(io->creply, &msg) == -1){
20 msg = nil;
21 inted = 1;
22 }
23 if(inted){
24 werrstr("interrupted");
25 return -1;
26 }
28 /*
29 * If we get interrupted, we have stick around so that
30 * the IO proc has someone to talk to. Send it an interrupt
31 * and try again.
32 */
33 inted = 0;
34 while(recv(io->creply, nil) == -1){
35 inted = 1;
36 iointerrupt(io);
37 }
38 USED(inted);
39 va_end(io->arg);
40 ret = io->ret;
41 if(ret < 0)
42 errstr(io->err, sizeof io->err);
43 io->inuse = 0;
45 /* release resources */
46 while(send(io->creply, &io) == -1)
47 ;
48 return ret;
49 }