本文整理汇总了C++中FIFO类的典型用法代码示例。如果您正苦于以下问题:C++ FIFO类的具体用法?C++ FIFO怎么用?C++ FIFO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FIFO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
FIFO stack;
DataItem* arr[20] = {0};
for(int i = 0; i < 20; i++)
stack.push(arr[i] = new DataItem(i));
for(int i = 0; i < 25; i++)
cout << stack.pop() << endl;
for(int i = 0; i < 20; i++)
delete arr[i];
return 0;
}
示例2: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Planificadores de procesos" << endl;
int cantidad = 0;
cout << "Ingrese la cantidad de procesos: " << endl;
cin >> cantidad;
queue<Proceso *> trabajos = AEsquema<AProceso>::tareas(cantidad);
cout << "Procesos: " << endl;
for (int i = 0; i < cantidad; i++)
{
Proceso *parte = trabajos.front();
cout << "Id: " << parte->getId() << ", Llegada: " << parte->getLlegada() << ", Rafaga: " << parte->getRafaga() << endl;
trabajos.pop();
trabajos.push(parte);
}
//Copiar con su respectivo planificador
cout << "FIFO" << endl;
FIFO *esquema = new FIFO(trabajos, cantidad);
esquema->iniciar();
cout << "" << endl;
esquema->desplegarLista();
cout << "" << endl;
// Aplica el SJF
cout << "SJF" << endl;
SJF *esquemaSJF = new SJF(trabajos, cantidad);
esquemaSJF->iniciar();
cout << "" << endl;
esquemaSJF->desplegarLista();
cout << "" << endl;
system("pause");
return 0;
}
示例3: return
raft::kstatus
Schedule::quitHandler( FIFO &fifo,
raft::kernel *kernel,
const raft::signal signal,
void *data )
{
/**
* NOTE: This should be the only action needed
* currently, however that may change in the futre
* with more features and systems added.
*/
fifo.invalidate();
return( raft::stop );
}
示例4: exit
//------------------------------------------------------------------------------
BigNumber operator+ (BigNumber x1, BigNumber x2) {
int carry=0;
int result;
BigNumber temp;
FIFO fifo;
if (x1.Count()<x2.Count()) {
temp=x1;
x1=x2;
x2=temp;
}
//temp.DeleteList(); //????????????????????????????????
TNode *temp_x1=x1.last;
TNode *temp_x2=x2.last;
TNode *temp_result=temp.last;//???????????????????????
for (int i=0;i<x2.Count();i++) { //Ѕлок протестирован
result=temp_x1->data+temp_x2->data+carry;
carry=(int)(result/1000);
fifo.Push(result%1000);
temp_x1=temp_x1->prev;
temp_x2=temp_x2->prev;
}
if ( (x2.Count()==x1.Count() ) && (carry!=0) )
fifo.Push(carry);
else {
for (int i=x2.Count();i<x1.Count();i++) {
result=temp_x1->data+carry;
carry=(int)(result/1000);
fifo.Push(result%1000);
temp_x1=temp_x1->prev;
}
if (carry!=0)
fifo.Push(carry);
}
int count=fifo.Count();
for (int i=0;i<count;i++) {
if (!fifo.Pop(result)) {
cout <<"Error\n";
exit(-1);
}
temp.AddBefore(temp.root,result);
}
return temp;
}
示例5: main
int main() {
FIFO f;
struct kunde k;
k.name = "name";
k.art = "art";
f.einfuegen(k);
k.name = "name2";
k.art = "art2";
f.einfuegen(k);
f.verarbeiten();
k.name = "name3";
k.art = "art3";
f.einfuegen(k);
f.verarbeiten();
}
示例6: threadProcess
void threadProcess(
std::string iFileDir,
std::string oFileDir,
FIFO<int>& module_list,
int threadID)
{
while(1)
{
// get next module for process or exit if done.
int module_number;
try {
module_number = module_list.pop();
std:: stringstream report;
report << "Stating module " << module_number;
thread_report(report.str(),threadID);
}catch(std::string i) {
thread_report("Terminating",threadID);
return;
}
std::array<FIFO<std::string>,12> asicData; //stores the data from the asic asicData[asicID][SPP]
FIFO<std::string> side1, side2;
for(int i(0); i < 12; i++)
{
std::stringstream filename;
filename << iFileDir << "/timesync" << module_number*12 + i << ".txt";
std::ifstream iFile(filename.str());
std::string tempIn;
while(iFile >> tempIn)
{
if (atoi(tempIn.c_str()) == 0) continue;
asicData[i].store(tempIn);
}
}
bool complete = false;
bool next_bcid = true;
int bcid = 0;
while(!complete)
{
for (int i(0); i < 12; i++)
if(!asicData[i].is_empty()){
if(get_bcid(asicData[i].peek()) == bcid){
if (i < 3 || i >= 9)
side1.store(asicData[i].pop());
else
side2.store(asicData[i].pop());
next_bcid = false;
}
}
complete = true;
for (auto& asic : asicData) if (!asic.is_empty()) complete = false;
if (next_bcid) if (++bcid >= 512) bcid = 0;
next_bcid = true;
}
std::stringstream outFileName1;
outFileName1 << oFileDir << "/module_" << module_number << "_";
std::stringstream outFileName2;
outFileName2 << outFileName1.str(); //shits and giggles
outFileName1 << 1 << ".txt";
outFileName2 << 2 << ".txt";
std::ofstream oFile1(outFileName1.str());
std::ofstream oFile2(outFileName2.str());
thread_report("Writing to file",threadID);
while(!side1.is_empty())
oFile1 << side1.pop() << '\n';
while(!side2.is_empty())
oFile2 << side2.pop() << '\n';
}
}
示例7: main
int main() {
ifstream printdata("printdata.txt"); //make a stream
List<job> printQueue;//this queue is going to be used for FIFO processing
//create a whole bunch of dummy variables to put in the list
int eyeD, tstamp, numP;
char auth;
job temp;
while (printdata >> eyeD) {
//read in data
temp.id = eyeD;
printdata >> tstamp;
temp.timestamp = tstamp;
printdata >> auth;
temp.user = auth;
printdata >> numP;
temp.pages = numP;
printQueue.push_back(temp); // callthe lists pushback method to add it to the back of the FIFO queue.
}
//create a dummy front job
job frontJob;
frontJob = printQueue.pop_front(); //get the first element in the fifo queue.
int clock = frontJob.timestamp;
//begin FIFO processing
FIFO<job> feefo; //create a fifo list type
feefo.push(frontJob); //place it at the beginning of the queue
int stoptime = 0;
zachresults << "Processing and calculating FIFO queue." << endl;
job printing; //printing will hold the current job that is printing
//initialize all of our stats
int minwait = 0, maxwait = 0, totalwait = 0, jobsprocessed = 0;
double avgwait;
bool busyPrinter = false; // the printer isn't busy, so tell the truth, you goon
do {
if (!busyPrinter) { //if the printer isn't busy, begin printing the next job in the fifo queue
printing = feefo.pop(clock);
zachresults << "Starting print id " << printing.id << " at " << clock << endl;
stoptime = clock + printing.length();
zachresults << "This job will end at " << stoptime << endl;
zachresults << "This job waited " << printing.waittime << " seconds." << endl;
if (printing.id != 165896) { //don't collect wait time stats on the first print job. it doesn't wait.
if(minwait == 0) {
minwait = printing.waittime;
maxwait = printing.waittime;
jobsprocessed++;
totalwait += printing.waittime;
avgwait = totalwait / jobsprocessed;
}
else {
totalwait += printing.waittime;
avgwait = totalwait / jobsprocessed;
}
if (printing.waittime < minwait) {
minwait = printing.waittime;
}
if (printing.waittime > maxwait) {
maxwait = printing.waittime;
}
}
busyPrinter = true; //the printer is now busy
}
if (!printQueue.is_empty()) { //as long as we're still pulling jobs off the queue as they arrive, run this block of code
frontJob = printQueue.pop_front(); //get the next job and put it in our frontjob variable
while (busyPrinter && clock < frontJob.timestamp) { //while the printr is busy and the next job hasn't arrived yet, increment the clock
clock++;
if (clock == frontJob.timestamp) { //add a job to the queue once our clock hits its timestamp
feefo.push(frontJob);
zachresults << "Job " << frontJob.id << " arrived at " << clock << endl;
}
if (stoptime == clock) { //the print job is done once this stoptime is satisfied
busyPrinter = false;
}
}
}
else {
while (busyPrinter) {//run this once all of the jobs from printdata.txt are in our queue
clock++;
if (stoptime == clock) {
busyPrinter = false;
}
}
}
} while (!feefo.isempty()); //bail once all of our jobs are done
zachresults << "The minimum wait time was " << minwait << " seconds." << endl;
zachresults << "The maximum wait time was " << maxwait << " seconds." << endl;
zachresults << "The average wait time was " << avgwait << " seconds" << endl;
zachresults << "The total wait time was " << totalwait << " seconds." << endl;
//tidy everything up before we move on to SJF
printdata.close();
feefo.clear();
printQueue.clear();
//.........这里部分代码省略.........
示例8: main
int main(int argc, char** argv) {
//ҳ������˳���
int arr[__LENGTH__];
srand((unsigned int)time(NULL));
for(auto& i : arr) {
//���ҳ��
i = rand() % 100;
}
//ҳ���
int frame_id;
//�������ʹ���û��㷨
LRU LRUManager;
//ȱҳ�жϼ���
unsigned int missing_page_lru = 0;
//ҳ���û�����
unsigned int page_algorithm_lru = 0;
//ģ������
cout << "******************** LRU ********************" << endl;
for(auto i : arr) {
cout << "����ҳ�ţ�" << i << "\t";
switch(LRUManager.requireFrame(i, frame_id)) {
case No:
cout << "ҳ�����У�ҳ��ţ�";
break;
case MissingPage:
missing_page_lru++;
cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
break;
case MissingPageAndReplace:
missing_page_lru++;
page_algorithm_lru++;
cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
break;
}
cout << frame_id << endl;
}
cout << "#################### LRU ####################" << endl;
//�Ƚ��ȳ��û��㷨
FIFO FIFOManager;
//ȱҳ�жϼ���
unsigned int missing_page_fifo = 0;
//ҳ���û�����
unsigned int page_algorithm_fifo = 0;
//ģ������
cout << "******************** FIFO ********************" << endl;
for(auto i : arr) {
cout << "����ҳ�ţ�" << i << "\t";
switch(FIFOManager.requireFrame(i, frame_id)) {
case No:
cout << "ҳ�����У�ҳ��ţ�";
break;
case MissingPage:
missing_page_fifo++;
cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
break;
case MissingPageAndReplace:
missing_page_fifo++;
page_algorithm_fifo++;
cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
break;
}
cout << frame_id << endl;
}
cout << "#################### FIFO ####################" << endl;
//������û��㷨
LFU LFUManager;
//ȱҳ�жϼ���
unsigned int missing_page_lfu = 0;
//ҳ���û�����
unsigned int page_algorithm_lfu = 0;
//ģ������
cout << "******************** LFU ********************" << endl;
for(auto i : arr) {
cout << "����ҳ�ţ�" << i << "\t";
switch(LFUManager.requireFrame(i, frame_id)) {
case No:
cout << "ҳ�����У�ҳ��ţ�";
break;
case MissingPage:
missing_page_lfu++;
cout << "ҳ��δ���У�����ҳ����ҳ��ţ�";
break;
case MissingPageAndReplace:
missing_page_lfu++;
page_algorithm_lfu++;
cout << "ҳ��δ���У�ҳ������������ҳ�沢�滻ҳ��ţ�";
break;
}
cout << frame_id << endl;
}
cout << "#################### LFU ####################" << endl;
//ʱ���û��㷨
CLOCK CLOCKManager;
//ȱҳ�жϼ���
unsigned int missing_page_clock = 0;
//ҳ���û�����
unsigned int page_algorithm_clock = 0;
//ģ������
cout << "******************** CLOCK ********************" << endl;
for(auto i : arr) {
//.........这里部分代码省略.........
示例9: get
bool SerialPort::get(uint8_t* byte)
{
if (m_rxfifo.IsEmpty())
return false;
*byte = m_rxfifo.Get() & 0xFF;
return true;
}
示例10: push
bool push(const void* const buf, const size_t len) {
chMtxLock(&mutex_write);
const auto result = fifo.in_r(buf, len);
chMtxUnlock();
const bool success = (result == len);
if( success ) {
signal();
}
return success;
}
示例11: get_line_
std::string get_line_()
{
std::string line;
if(fifo_.empty()) {
return line;
}
while(!fifo_.empty()) {
auto ch = fifo_.front();
fifo_.pop();
if(ch == '\n') {
line = line_;
line_.clear();
break;
} else if(ch == '\r') {
} else {
line_ += ch;
}
}
return line;
}
示例12: threadLoop
void SerialPort::threadLoop()
{
const int fd = m_fd;
const int max_fd = fd+1;
m_running = true;
m_rxErrors[1] = 0;
while (true) {
fd_set rfds;
FD_ZERO( &rfds);
FD_SET(fd, &rfds);
struct timeval timeout;
timeout.tv_sec = kReadTimeoutMs/1000;
timeout.tv_usec = (kReadTimeoutMs%1000)*1000;
int n = select(max_fd, &rfds, 0, 0, &timeout);
// int fdset = FD_ISSET(fd, &rfds);
// printf( "fdset %i, n %i, errno %i\n", fdset, n, errno );
if ( m_open ){
if ((n > 0) && FD_ISSET(fd, &rfds)) {
// printf("poll input\n");
int nr = 0;
// while (true) {
if ( m_open ){
int n2 = read(fd, m_rxbuffer, kBufferSize);
// printf("read %d, errno %i, errbadf %i, %i, %i\n", n2, errno, EBADF, EAGAIN, EIO);
if (n2 > 0) {
// write data to ringbuffer
for (int i=0; i < n2; ++i) {
if (!m_rxfifo.Put(m_rxbuffer[i])) {
m_rxErrors[1]++;
break;
}
}
nr += n2;
} else if ((n2 == 0) && (n == 1) ) { // added by nescivi, to check for disconnected device. In this case the read is 0 all the time and otherwise eats up the CPU
// printf( "done\n" );
goto done;
} else if ((n2 == 0) || ((n2 == -1) && (errno == EAGAIN))) {
// printf( "break\n");
break;
} else {
#ifndef NDEBUG
printf("SerialPort HUP\n");
#endif
goto done;
}
}
//}
if (!m_running) {
// close and cleanup
goto done;
}
if (nr > 0) {
dataAvailable();
}
} else if (n == -1) {
goto done;
}
}
if (!m_running) {
// close and cleanup
goto done;
}
}
done:
// doneAction();
if ( m_open ){
tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &m_oldtermio);
close(fd);
};
m_open = false;
m_running = false;
if ( m_dodone )
doneAction();
#ifndef NDEBUG
printf("SerialPort closed\n");
#endif
}
示例13: len
size_t len() const {
return fifo.len();
}
示例14: pop
Message* pop(std::array<uint8_t, Message::MAX_SIZE>& buf) {
Message* const p = reinterpret_cast<Message*>(buf.data());
return fifo.out_r(buf.data(), buf.size()) ? p : nullptr;
}
示例15: skip
bool skip() {
return fifo.skip();
}