add tsemacquire syscall for go
This commit is contained in:
parent
780d393e4b
commit
49ac0b93d3
4 changed files with 68 additions and 0 deletions
|
@ -670,6 +670,7 @@ extern int semacquire(long*, int);
|
||||||
extern long semrelease(long*, long);
|
extern long semrelease(long*, long);
|
||||||
extern int sleep(long);
|
extern int sleep(long);
|
||||||
extern int stat(char*, uchar*, int);
|
extern int stat(char*, uchar*, int);
|
||||||
|
extern int tsemacquire(long*, ulong);
|
||||||
extern Waitmsg* wait(void);
|
extern Waitmsg* wait(void);
|
||||||
extern int waitpid(void);
|
extern int waitpid(void);
|
||||||
extern long write(int, void*, long);
|
extern long write(int, void*, long);
|
||||||
|
|
|
@ -1034,6 +1034,50 @@ semacquire(Segment *s, long *addr, int block)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Acquire semaphore or time-out */
|
||||||
|
static int
|
||||||
|
tsemacquire(Segment *s, long *addr, ulong ms)
|
||||||
|
{
|
||||||
|
int acquired, timedout;
|
||||||
|
ulong t, elms;
|
||||||
|
Sema phore;
|
||||||
|
|
||||||
|
if(canacquire(addr))
|
||||||
|
return 1;
|
||||||
|
if(ms == 0)
|
||||||
|
return 0;
|
||||||
|
acquired = timedout = 0;
|
||||||
|
semqueue(s, addr, &phore);
|
||||||
|
for(;;){
|
||||||
|
phore.waiting = 1;
|
||||||
|
coherence();
|
||||||
|
if(canacquire(addr)){
|
||||||
|
acquired = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(waserror())
|
||||||
|
break;
|
||||||
|
t = m->ticks;
|
||||||
|
tsleep(&phore, semawoke, &phore, ms);
|
||||||
|
elms = TK2MS(m->ticks - t);
|
||||||
|
poperror();
|
||||||
|
if(elms >= ms){
|
||||||
|
timedout = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ms -= elms;
|
||||||
|
}
|
||||||
|
semdequeue(s, &phore);
|
||||||
|
coherence(); /* not strictly necessary due to lock in semdequeue */
|
||||||
|
if(!phore.waiting)
|
||||||
|
semwakeup(s, addr, 1);
|
||||||
|
if(timedout)
|
||||||
|
return 0;
|
||||||
|
if(!acquired)
|
||||||
|
nexterror();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
syssemacquire(ulong *arg)
|
syssemacquire(ulong *arg)
|
||||||
{
|
{
|
||||||
|
@ -1053,6 +1097,25 @@ syssemacquire(ulong *arg)
|
||||||
return semacquire(s, addr, block);
|
return semacquire(s, addr, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
systsemacquire(ulong *arg)
|
||||||
|
{
|
||||||
|
long *addr;
|
||||||
|
ulong ms;
|
||||||
|
Segment *s;
|
||||||
|
|
||||||
|
validaddr(arg[0], sizeof(long), 1);
|
||||||
|
evenaddr(arg[0]);
|
||||||
|
addr = (long*)arg[0];
|
||||||
|
ms = arg[1];
|
||||||
|
|
||||||
|
if((s = seg(up, (ulong)addr, 0)) == nil)
|
||||||
|
error(Ebadarg);
|
||||||
|
if(*addr < 0)
|
||||||
|
error(Ebadarg);
|
||||||
|
return tsemacquire(s, addr, ms);
|
||||||
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
syssemrelease(ulong *arg)
|
syssemrelease(ulong *arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,7 @@ Syscall sysmount;
|
||||||
Syscall sysawait;
|
Syscall sysawait;
|
||||||
Syscall syspread;
|
Syscall syspread;
|
||||||
Syscall syspwrite;
|
Syscall syspwrite;
|
||||||
|
Syscall systsemacquire;
|
||||||
Syscall sysdeath;
|
Syscall sysdeath;
|
||||||
|
|
||||||
Syscall *systab[]={
|
Syscall *systab[]={
|
||||||
|
@ -105,6 +106,7 @@ Syscall *systab[]={
|
||||||
[AWAIT] sysawait,
|
[AWAIT] sysawait,
|
||||||
[PREAD] syspread,
|
[PREAD] syspread,
|
||||||
[PWRITE] syspwrite,
|
[PWRITE] syspwrite,
|
||||||
|
[TSEMACQUIRE] systsemacquire,
|
||||||
};
|
};
|
||||||
|
|
||||||
char *sysctab[]={
|
char *sysctab[]={
|
||||||
|
@ -158,6 +160,7 @@ char *sysctab[]={
|
||||||
[AWAIT] "Await",
|
[AWAIT] "Await",
|
||||||
[PREAD] "Pread",
|
[PREAD] "Pread",
|
||||||
[PWRITE] "Pwrite",
|
[PWRITE] "Pwrite",
|
||||||
|
[TSEMACQUIRE] "Tsemacquire",
|
||||||
};
|
};
|
||||||
|
|
||||||
int nsyscall = (sizeof systab/sizeof systab[0]);
|
int nsyscall = (sizeof systab/sizeof systab[0]);
|
||||||
|
|
|
@ -48,3 +48,4 @@
|
||||||
#define AWAIT 47
|
#define AWAIT 47
|
||||||
#define PREAD 50
|
#define PREAD 50
|
||||||
#define PWRITE 51
|
#define PWRITE 51
|
||||||
|
#define TSEMACQUIRE 52
|
||||||
|
|
Loading…
Reference in a new issue