update codes

This commit is contained in:
chyyuu
2012-09-14 21:36:57 +08:00
parent c417874aa8
commit 92c553113b
32 changed files with 506 additions and 1809 deletions

View File

@@ -27,7 +27,7 @@ fd_array_init(struct file *fd_array) {
int fd;
struct file *file = fd_array;
for (fd = 0; fd < FILES_STRUCT_NENTRY; fd ++, file ++) {
atomic_set(&(file->open_count), 0);
file->open_count = 0;
file->status = FD_NONE, file->fd = fd;
}
}

View File

@@ -20,7 +20,7 @@ struct file {
int fd;
off_t pos;
struct inode *node;
atomic_t open_count;
int open_count;
};
void fd_array_init(struct file *fd_array);
@@ -43,17 +43,19 @@ int file_mkfifo(const char *name, uint32_t open_flags);
static inline int
fopen_count(struct file *file) {
return atomic_read(&(file->open_count));
return file->open_count;
}
static inline int
fopen_count_inc(struct file *file) {
return atomic_add_return(&(file->open_count), 1);
file->open_count += 1;
return file->open_count;
}
static inline int
fopen_count_dec(struct file *file) {
return atomic_sub_return(&(file->open_count), 1);
file->open_count -= 1;
return file->open_count;
}
#endif /* !__KERN_FS_FILE_H__ */

View File

@@ -38,7 +38,7 @@ files_create(void) {
if ((filesp = kmalloc(sizeof(struct files_struct) + FILES_STRUCT_BUFSIZE)) != NULL) {
filesp->pwd = NULL;
filesp->fd_array = (void *)(filesp + 1);
atomic_set(&(filesp->files_count), 0);
filesp->files_count = 0;
sem_init(&(filesp->files_sem), 1);
fd_array_init(filesp->fd_array);
}

View File

@@ -25,7 +25,7 @@ struct file;
struct files_struct {
struct inode *pwd; // inode of present working directory
struct file *fd_array; // opened files array
atomic_t files_count; // the number of opened files
int files_count; // the number of opened files
semaphore_t files_sem; // lock protect sem
};
@@ -42,17 +42,19 @@ int dup_files(struct files_struct *to, struct files_struct *from);
static inline int
files_count(struct files_struct *filesp) {
return atomic_read(&(filesp->files_count));
return filesp->files_count;
}
static inline int
files_count_inc(struct files_struct *filesp) {
return atomic_add_return(&(filesp->files_count), 1);
filesp->files_count += 1;
return filesp->files_count;
}
static inline int
files_count_dec(struct files_struct *filesp) {
return atomic_sub_return(&(filesp->files_count), 1);
filesp->files_count -= 1;
return filesp->files_count;
}
#endif /* !__KERN_FS_FS_H__ */

View File

@@ -26,8 +26,8 @@ __alloc_inode(int type) {
* */
void
inode_init(struct inode *node, const struct inode_ops *ops, struct fs *fs) {
atomic_set(&(node->ref_count), 0);
atomic_set(&(node->open_count), 0);
node->ref_count = 0;
node->open_count = 0;
node->in_ops = ops, node->in_fs = fs;
vop_ref_inc(node);
}
@@ -49,7 +49,8 @@ inode_kill(struct inode *node) {
* */
int
inode_ref_inc(struct inode *node) {
return atomic_add_return(&(node->ref_count), 1);
node->ref_count += 1;
return node->ref_count;
}
/* *
@@ -61,7 +62,9 @@ int
inode_ref_dec(struct inode *node) {
assert(inode_ref_count(node) > 0);
int ref_count, ret;
if ((ref_count = atomic_sub_return(&(node->ref_count), 1)) == 0) {
node->ref_count-= 1;
ref_count = node->ref_count;
if (ref_count == 0) {
if ((ret = vop_reclaim(node)) != 0 && ret != -E_BUSY) {
cprintf("vfs: warning: vop_reclaim: %e.\n", ret);
}
@@ -75,7 +78,8 @@ inode_ref_dec(struct inode *node) {
* */
int
inode_open_inc(struct inode *node) {
return atomic_add_return(&(node->open_count), 1);
node->open_count += 1;
return node->open_count;
}
/* *
@@ -87,7 +91,9 @@ int
inode_open_dec(struct inode *node) {
assert(inode_open_count(node) > 0);
int open_count, ret;
if ((open_count = atomic_sub_return(&(node->open_count), 1)) == 0) {
node->open_count -= 1;
open_count = node->open_count;
if (open_count == 0) {
if ((ret = vop_close(node)) != 0) {
cprintf("vfs: warning: vop_close: %e.\n", ret);
}

View File

@@ -35,8 +35,8 @@ struct inode {
inode_type_device_info = 0x1234,
inode_type_sfs_inode_info,
} in_type;
atomic_t ref_count;
atomic_t open_count;
int ref_count;
int open_count;
struct fs *in_fs;
const struct inode_ops *in_ops;
};
@@ -236,12 +236,12 @@ void inode_check(struct inode *node, const char *opstr);
static inline int
inode_ref_count(struct inode *node) {
return atomic_read(&(node->ref_count));
return node->ref_count;
}
static inline int
inode_open_count(struct inode *node) {
return atomic_read(&(node->open_count));
return node->open_count;
}
#endif /* !__KERN_FS_VFS_INODE_H__ */

View File

@@ -127,7 +127,7 @@ struct e820map {
* that convert Page to other data types, such as phyical address.
* */
struct Page {
atomic_t ref; // page frame's reference counter
int ref; // page frame's reference counter
uint32_t flags; // array of flags that describe the status of the page frame
unsigned int property; // used in buddy system, stores the order (the X in 2^X) of the continuous memory block
int zone_num; // used in buddy system, the No. of zone which the page belongs to

View File

@@ -121,22 +121,24 @@ pde2page(pde_t pde) {
static inline int
page_ref(struct Page *page) {
return atomic_read(&(page->ref));
return page->ref;
}
static inline void
set_page_ref(struct Page *page, int val) {
atomic_set(&(page->ref), val);
page->ref = val;
}
static inline int
page_ref_inc(struct Page *page) {
return atomic_add_return(&(page->ref), 1);
page->ref += 1;
return page->ref;
}
static inline int
page_ref_dec(struct Page *page) {
return atomic_sub_return(&(page->ref), 1);
page->ref -= 1;
return page->ref;
}
extern char bootstack[], bootstacktop[];

View File

@@ -35,7 +35,7 @@ struct mm_struct {
pde_t *pgdir; // the PDT of these vma
int map_count; // the count of these vma
void *sm_priv; // the private data for swap manager
atomic_t mm_count; // the number ofprocess which shared the mm
int mm_count; // the number ofprocess which shared the mm
semaphore_t mm_sem; // mutex for using dup_mmap fun to duplicat the mm
int locked_by; // the lock owner process's pid
@@ -69,22 +69,24 @@ bool copy_string(struct mm_struct *mm, char *dst, const char *src, size_t maxn);
static inline int
mm_count(struct mm_struct *mm) {
return atomic_read(&(mm->mm_count));
return mm->mm_count;
}
static inline void
set_mm_count(struct mm_struct *mm, int val) {
atomic_set(&(mm->mm_count), val);
mm->mm_count = val;
}
static inline int
mm_count_inc(struct mm_struct *mm) {
return atomic_add_return(&(mm->mm_count), 1);
mm->mm_count += 1;
return mm->mm_count;
}
static inline int
mm_count_dec(struct mm_struct *mm) {
return atomic_sub_return(&(mm->mm_count), 1);
mm->mm_count -= 1;
return mm->mm_count;
}
static inline void