Compare commits
4 Commits
user_threa
...
master
Author | SHA1 | Date | |
---|---|---|---|
778999c8f4 | |||
d6ab0da231 | |||
|
dea0eba83d | ||
86a0138d9c |
@ -232,17 +232,18 @@ int threadOnJieffiesTick()
|
|||||||
disable_IRQs(flags);
|
disable_IRQs(flags);
|
||||||
list_foreach(currentThread, nextThread, idx)
|
list_foreach(currentThread, nextThread, idx)
|
||||||
{
|
{
|
||||||
if (nextThread->state == SLEEPING && nextThread->jiffiesSleeping) {
|
if (nextThread->state == SLEEPING) {
|
||||||
nextThread->jiffiesSleeping--;
|
if (nextThread->jiffiesSleeping)
|
||||||
if (!nextThread->jiffiesSleeping) {
|
nextThread->jiffiesSleeping--;
|
||||||
|
if (!nextThread->jiffiesSleeping)
|
||||||
nextThread->state = READY;
|
nextThread->state = READY;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list_foreach_named(threadWithTimeout, nextThread, idx, timePrev, timeNext)
|
list_foreach_named(threadWithTimeout, nextThread, idx, timePrev, timeNext)
|
||||||
{
|
{
|
||||||
if (nextThread->state == WAITING && nextThread->jiffiesSleeping) {
|
if (nextThread->state == WAITING) {
|
||||||
nextThread->jiffiesSleeping--;
|
if (nextThread->jiffiesSleeping)
|
||||||
|
nextThread->jiffiesSleeping--;
|
||||||
if (!nextThread->jiffiesSleeping) {
|
if (!nextThread->jiffiesSleeping) {
|
||||||
nextThread->sleepHaveTimeouted = 1;
|
nextThread->sleepHaveTimeouted = 1;
|
||||||
list_delete_named(threadWithTimeout, nextThread, timePrev, timeNext);
|
list_delete_named(threadWithTimeout, nextThread, timePrev, timeNext);
|
||||||
@ -332,8 +333,6 @@ int threadUsleep(unsigned long usec)
|
|||||||
current->state = SLEEPING;
|
current->state = SLEEPING;
|
||||||
current->sleepHaveTimeouted = 0;
|
current->sleepHaveTimeouted = 0;
|
||||||
current->jiffiesSleeping = usecs_to_jiffies(usec);
|
current->jiffiesSleeping = usecs_to_jiffies(usec);
|
||||||
if (!current->jiffiesSleeping) // sleep at least 1 jiffies
|
|
||||||
current->jiffiesSleeping = 1;
|
|
||||||
next = threadSelectNext();
|
next = threadSelectNext();
|
||||||
|
|
||||||
assert(next != current);
|
assert(next != current);
|
||||||
|
@ -1,14 +1,41 @@
|
|||||||
#include "zero.h"
|
#include "zero.h"
|
||||||
|
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
|
#include "errno.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "klibc.h"
|
#include "klibc.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "paging.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
struct zeroMappedPage {
|
||||||
|
uaddr_t mappedAddr;
|
||||||
|
paddr_t phyAddr;
|
||||||
|
|
||||||
|
struct zeroMappedPage *prev, *next;
|
||||||
|
};
|
||||||
|
|
||||||
struct zeroMappedEntry {
|
struct zeroMappedEntry {
|
||||||
int refCnt;
|
int refCnt;
|
||||||
|
|
||||||
|
struct zeroMappedPage *listMapped;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int insertMappedPage(struct zeroMappedEntry *entry, uaddr_t vAddr, paddr_t pAddr){
|
||||||
|
struct zeroMappedPage *info = (struct zeroMappedPage *)zalloc(sizeof(struct zeroMappedPage));
|
||||||
|
|
||||||
|
if(!info)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
info->mappedAddr = vAddr;
|
||||||
|
info->phyAddr = pAddr;
|
||||||
|
|
||||||
|
list_add_tail(entry->listMapped, info);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int zeroOpen(struct uAddrVirtualReg *vreg)
|
static int zeroOpen(struct uAddrVirtualReg *vreg)
|
||||||
{
|
{
|
||||||
struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
|
struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
|
||||||
@ -21,6 +48,11 @@ static int zeroClose(struct uAddrVirtualReg *vreg)
|
|||||||
struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
|
struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
|
||||||
ent->refCnt--;
|
ent->refCnt--;
|
||||||
if (ent->refCnt == 0) {
|
if (ent->refCnt == 0) {
|
||||||
|
struct zeroMappedPage *pageInfo;
|
||||||
|
list_collapse(ent->listMapped, pageInfo){
|
||||||
|
pageUnmap(pageInfo->mappedAddr);
|
||||||
|
free(pageInfo);
|
||||||
|
}
|
||||||
free(vreg->res->customData);
|
free(vreg->res->customData);
|
||||||
free(vreg->res);
|
free(vreg->res);
|
||||||
}
|
}
|
||||||
@ -29,17 +61,26 @@ static int zeroClose(struct uAddrVirtualReg *vreg)
|
|||||||
|
|
||||||
static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right)
|
static int zeroNoPage(struct uAddrVirtualReg *vreg, uaddr_t addr, int right)
|
||||||
{
|
{
|
||||||
(void)vreg;
|
int ret = 0;
|
||||||
|
paddr_t ppage = allocPhyPage(1);
|
||||||
|
uaddr_t mappedAddr = ALIGN_DOWN(addr, PAGE_SIZE);
|
||||||
|
ret = pageMap(mappedAddr, ppage, right | PAGING_MEM_USER);
|
||||||
|
|
||||||
int ret = 0;
|
struct zeroMappedEntry *ent = (struct zeroMappedEntry *)vreg->res->customData;
|
||||||
paddr_t ppage = allocPhyPage(1);
|
|
||||||
ret = pageMap(ALIGN_DOWN(addr, PAGE_SIZE), ppage, right | PAGING_MEM_USER) ;
|
|
||||||
|
|
||||||
unrefPhyPage(ppage);
|
unrefPhyPage(ppage);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
memset((void *)ALIGN_DOWN(addr, PAGE_SIZE), 0, PAGE_SIZE);
|
|
||||||
|
ret = insertMappedPage(ent, mappedAddr, ppage);
|
||||||
|
if (ret) {
|
||||||
|
pageUnmap(mappedAddr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset((void *)mappedAddr, 0, PAGE_SIZE);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +106,8 @@ int zeroMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights
|
|||||||
struct zeroMappedEntry *cust =
|
struct zeroMappedEntry *cust =
|
||||||
(struct zeroMappedEntry *)zalloc(sizeof(struct zeroMappedEntry));
|
(struct zeroMappedEntry *)zalloc(sizeof(struct zeroMappedEntry));
|
||||||
|
|
||||||
|
list_init(cust->listMapped);
|
||||||
|
|
||||||
res->allowedRight = PAGING_MEM_READ | PAGING_MEM_WRITE | PAGING_MEM_EXEC | PAGING_MEM_USER;
|
res->allowedRight = PAGING_MEM_READ | PAGING_MEM_WRITE | PAGING_MEM_EXEC | PAGING_MEM_USER;
|
||||||
res->ops = &zeroOps;
|
res->ops = &zeroOps;
|
||||||
res->customData = cust;
|
res->customData = cust;
|
||||||
|
@ -306,9 +306,8 @@ void sleepThread(void *arg)
|
|||||||
}
|
}
|
||||||
unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies);
|
unsigned long ellapsedTime = jiffies_to_msecs(jiffies - initialJiffies);
|
||||||
assertmsg(ellapsedTime >= 500 && ellapsedTime < 510, "ellapsedTime %lu\n", ellapsedTime);
|
assertmsg(ellapsedTime >= 500 && ellapsedTime < 510, "ellapsedTime %lu\n", ellapsedTime);
|
||||||
threadMsleep(0);
|
threadMsleep(ULONG_MAX);
|
||||||
printf("I should never be showed\n");
|
assert(0);
|
||||||
assert(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mutex mutexTest;
|
struct mutex mutexTest;
|
||||||
|
Loading…
Reference in New Issue
Block a user