add awaitfor and waitfor
This commit is contained in:
parent
955a2ca78d
commit
0341761074
3 changed files with 30 additions and 10 deletions
|
|
@ -693,6 +693,7 @@ extern void abort(void);
|
||||||
/* extern int access(char*, int); */
|
/* extern int access(char*, int); */
|
||||||
extern long p9alarm(ulong);
|
extern long p9alarm(ulong);
|
||||||
extern int await(char*, int);
|
extern int await(char*, int);
|
||||||
|
extern int awaitfor(int, char*, int);
|
||||||
extern int awaitnohang(char*, int);
|
extern int awaitnohang(char*, int);
|
||||||
/* extern int bind(char*, char*, int); give up */
|
/* extern int bind(char*, char*, int); give up */
|
||||||
/* extern int brk(void*); <unistd.h> */
|
/* extern int brk(void*); <unistd.h> */
|
||||||
|
|
@ -746,6 +747,7 @@ extern int segfree(void*, ulong);
|
||||||
extern int p9sleep(long);
|
extern int p9sleep(long);
|
||||||
/* extern int stat(char*, uchar*, int); give up */
|
/* extern int stat(char*, uchar*, int); give up */
|
||||||
extern Waitmsg* p9wait(void);
|
extern Waitmsg* p9wait(void);
|
||||||
|
extern Waitmsg* p9waitfor(int);
|
||||||
extern Waitmsg* waitnohang(void);
|
extern Waitmsg* waitnohang(void);
|
||||||
extern int p9waitpid(void);
|
extern int p9waitpid(void);
|
||||||
/* <unistd.h>
|
/* <unistd.h>
|
||||||
|
|
@ -770,6 +772,7 @@ extern ulong rendezvous(ulong, ulong);
|
||||||
#undef open
|
#undef open
|
||||||
#define open p9open
|
#define open p9open
|
||||||
#define pipe p9pipe
|
#define pipe p9pipe
|
||||||
|
#define waitfor p9waitfor
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern Dir* dirstat(char*);
|
extern Dir* dirstat(char*);
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ _p9strsig(char *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_await(char *str, int n, int opt)
|
_await(int pid4, char *str, int n, int opt)
|
||||||
{
|
{
|
||||||
int pid, status, cd;
|
int pid, status, cd;
|
||||||
struct rusage ru;
|
struct rusage ru;
|
||||||
|
|
@ -82,7 +82,7 @@ _await(char *str, int n, int opt)
|
||||||
ulong u, s;
|
ulong u, s;
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
pid = wait3(&status, opt, &ru);
|
pid = wait4(pid4, &status, opt, &ru);
|
||||||
if(pid <= 0)
|
if(pid <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000);
|
u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000);
|
||||||
|
|
@ -108,12 +108,18 @@ _await(char *str, int n, int opt)
|
||||||
int
|
int
|
||||||
await(char *str, int n)
|
await(char *str, int n)
|
||||||
{
|
{
|
||||||
return _await(str, n, 0);
|
return _await(-1, str, n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
awaitnohang(char *str, int n)
|
awaitnohang(char *str, int n)
|
||||||
{
|
{
|
||||||
return _await(str, n, WNOHANG);
|
return _await(-1, str, n, WNOHANG);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
awaitfor(int pid, char *str, int n)
|
||||||
|
{
|
||||||
|
return _await(pid, str, n, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,12 @@
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
static Waitmsg*
|
static Waitmsg*
|
||||||
_wait(int nohang)
|
_wait(int n, char *buf)
|
||||||
{
|
{
|
||||||
int n, l;
|
int l;
|
||||||
char buf[512], *fld[5];
|
char *fld[5];
|
||||||
Waitmsg *w;
|
Waitmsg *w;
|
||||||
|
|
||||||
n = (nohang ? awaitnohang : await)(buf, sizeof buf-1);
|
|
||||||
if(n <= 0)
|
if(n <= 0)
|
||||||
return nil;
|
return nil;
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
|
|
@ -32,12 +31,24 @@ _wait(int nohang)
|
||||||
Waitmsg*
|
Waitmsg*
|
||||||
wait(void)
|
wait(void)
|
||||||
{
|
{
|
||||||
return _wait(0);
|
char buf[256];
|
||||||
|
|
||||||
|
return _wait(await(buf, sizeof buf-1), buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Waitmsg*
|
Waitmsg*
|
||||||
waitnohang(void)
|
waitnohang(void)
|
||||||
{
|
{
|
||||||
return _wait(1);
|
char buf[256];
|
||||||
|
|
||||||
|
return _wait(awaitnohang(buf, sizeof buf-1), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
Waitmsg*
|
||||||
|
waitfor(int pid)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
|
||||||
|
return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue