kern: move tsemaquire to userspace (given a generalized awake)
This commit is contained in:
parent
46664994d4
commit
79f8204766
|
@ -236,6 +236,7 @@
|
||||||
#define toupper jehanne_toupper
|
#define toupper jehanne_toupper
|
||||||
#define ainc jehanne_ainc
|
#define ainc jehanne_ainc
|
||||||
#define adec jehanne_adec
|
#define adec jehanne_adec
|
||||||
|
#define tsemacquire jehanne_tsemacquire
|
||||||
#define _tas jehanne__tas
|
#define _tas jehanne__tas
|
||||||
#define lock jehanne_lock
|
#define lock jehanne_lock
|
||||||
#define lockt jehanne_lockt
|
#define lockt jehanne_lockt
|
||||||
|
|
|
@ -378,6 +378,8 @@ struct Lock {
|
||||||
int32_t sem;
|
int32_t sem;
|
||||||
} Lock;
|
} Lock;
|
||||||
|
|
||||||
|
extern int jehanne_tsemacquire(int* addr, long ms);
|
||||||
|
|
||||||
extern int jehanne__tas(int*);
|
extern int jehanne__tas(int*);
|
||||||
|
|
||||||
extern void jehanne_lock(Lock*);
|
extern void jehanne_lock(Lock*);
|
||||||
|
|
|
@ -34,4 +34,5 @@ jehanne_sysfatal(const char *fmt, ...)
|
||||||
va_start(arg, fmt);
|
va_start(arg, fmt);
|
||||||
(*_sysfatal)(fmt, arg);
|
(*_sysfatal)(fmt, arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
jehanne_exits("sysfatal");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Jehanne.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Giacomo Tesio <giacomo@tesio.it>
|
||||||
|
*
|
||||||
|
* Jehanne is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 2 of the License.
|
||||||
|
*
|
||||||
|
* Jehanne is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <u.h>
|
||||||
|
#include <libc.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
jehanne_tsemacquire(int* addr, long ms)
|
||||||
|
{
|
||||||
|
long wkup;
|
||||||
|
wkup = awake(ms);
|
||||||
|
while(semacquire(addr, 1) < 0){
|
||||||
|
if(jehanne_awakened(wkup)){
|
||||||
|
/* copy canlock semantic for return values */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* interrupted; try again */
|
||||||
|
}
|
||||||
|
jehanne_forgivewkp(wkup);
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -80,6 +80,7 @@
|
||||||
"9sys/times.c",
|
"9sys/times.c",
|
||||||
"9sys/tm2sec.c",
|
"9sys/tm2sec.c",
|
||||||
"9sys/truerand.c",
|
"9sys/truerand.c",
|
||||||
|
"9sys/tsemacquire.c",
|
||||||
"9sys/wait.c",
|
"9sys/wait.c",
|
||||||
"9sys/waitpid.c",
|
"9sys/waitpid.c",
|
||||||
"9sys/werrstr.c",
|
"9sys/werrstr.c",
|
||||||
|
|
|
@ -46,22 +46,8 @@ jehanne_canlock(Lock *l)
|
||||||
int
|
int
|
||||||
jehanne_lockt(Lock *l, uint32_t ms)
|
jehanne_lockt(Lock *l, uint32_t ms)
|
||||||
{
|
{
|
||||||
int semr;
|
|
||||||
int64_t start, end;
|
|
||||||
|
|
||||||
if(jehanne_ainc(&l->key) == 1)
|
if(jehanne_ainc(&l->key) == 1)
|
||||||
return 1; /* changed from 0 -> 1: we hold lock */
|
return 1; /* changed from 0 -> 1: we hold lock */
|
||||||
/* otherwise wait in kernel */
|
/* otherwise wait in kernel */
|
||||||
semr = 0;
|
return jehanne_tsemacquire(&l->sem, ms);
|
||||||
start = jehanne_nsec() / (1000 * 1000);
|
|
||||||
end = start + ms;
|
|
||||||
while(start < end && (semr = tsemacquire(&l->sem, ms)) < 0){
|
|
||||||
/* interrupted; try again */
|
|
||||||
start = jehanne_nsec() / (1000 * 1000);
|
|
||||||
ms = end - start;
|
|
||||||
}
|
|
||||||
/* copy canlock semantic for return values */
|
|
||||||
if(semr == 1)
|
|
||||||
return 1; /* success, lock acquired */
|
|
||||||
return 0; /* timed out or interrupt at timeout */
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,17 +304,6 @@
|
||||||
"int"
|
"int"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"Args": [
|
|
||||||
"int*",
|
|
||||||
"uint64_t"
|
|
||||||
],
|
|
||||||
"Id": 25,
|
|
||||||
"Name": "tsemacquire",
|
|
||||||
"Ret": [
|
|
||||||
"int"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"Args": [
|
"Args": [
|
||||||
"const char*",
|
"const char*",
|
||||||
|
|
Loading…
Reference in New Issue