-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Buf::Buf() | |
|
||
this->b_dev = -1; | ||
this->b_wcount = 0; | ||
this->b_addr = NULL; | ||
this->b_blkno = 0; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "BufferManager.h" | ||
#include<iostream> | ||
using namespace std; | ||
|
||
BufferManager::BufferManager() | ||
{ | ||
Initialize(); | ||
} | ||
|
||
BufferManager::~BufferManager() | ||
{ | ||
|
||
} | ||
|
||
/* 缓存控制块队列的初始化。将缓存控制块中b_addr指向相应缓冲区首地址。 */ | ||
void BufferManager::Initialize() | ||
{ | ||
// cout << "Starting initialize buffer manager..." << endl; | ||
|
||
/* 初始化自由队列和NODEV队列 */ | ||
this->bFreeList.b_forw = &(this->bFreeList); | ||
this->bFreeList.b_back = &(this->bFreeList); | ||
this->bFreeList.av_forw = &(this->bFreeList); | ||
this->bFreeList.av_back = &(this->bFreeList); | ||
|
||
Buf *buf_ptr; | ||
for (int i = 0; i < this->NBUF; i++) | ||
{ | ||
buf_ptr = &(this->m_Buf[i]); | ||
|
||
/* 缓冲区定位 */ | ||
buf_ptr->b_addr = this->Buffer[i]; | ||
// Buffer[i][0] = 'a' + i; | ||
|
||
Buf *temp = this->bFreeList.b_forw; | ||
/* 初始化自由队列 */ | ||
buf_ptr->b_forw = temp; | ||
temp->b_back = buf_ptr; | ||
this->bFreeList.b_forw = buf_ptr; | ||
buf_ptr->b_back = &(this->bFreeList); | ||
/* 初始化NODEV队列 */ | ||
buf_ptr->av_back = temp; | ||
temp->av_forw = buf_ptr; | ||
this->bFreeList.av_back = buf_ptr; | ||
buf_ptr->av_forw = &(this->bFreeList); | ||
|
||
// cout << "Insert one buffer succeed!" << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
#include <iostream> | ||
#include "UserInterface.h" | ||
#include "BufferManager.h" | ||
|
||
int main() | ||
{ | ||
BufferManager os_BufferManager; | ||
// cout << "Initialized buffer manager..." << endl; | ||
// Buf *buf_ptr = os_BufferManager.bFreeList.b_back; | ||
// while (buf_ptr != &(os_BufferManager.bFreeList)) | ||
// { | ||
// cout << char(buf_ptr->b_addr[0]) << endl; | ||
// buf_ptr = buf_ptr->b_back; | ||
// } | ||
|
||
string user_name = "root"; | ||
UserInterface UI; | ||
UI.GetCmd(user_name); | ||
// UI.GetCmd(user_name); | ||
|
||
|
||
return 0; | ||
} |