⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applyarray.cpp

📁 模拟Linux文件系统 在任一OS下
💻 CPP
字号:
#include"disk.h"
#include <winbase.h>
#define _WIN32_WINNT 0x0400
#if(_WIN32_WINNT >= 0x0400)
WINBASEAPI
DWORD
WINAPI
SignalObjectAndWait(
HANDLE hObjectToSignal,
HANDLE hObjectToWaitOn,
DWORD dwMilliseconds,
BOOL bAlertable
);
#endif /* _WIN32_WINNT >= 0x0400 */  



CRITICAL_SECTION thereisapplication;
CRITICAL_SECTION thereisspace;
CRITICAL_SECTION   getLock;
CRITICAL_SECTION   putLock;
CRITICAL_SECTION   ArrayLock;
applyarray::applyarray(){
	beg=end=0;
}
void applyarray::able_get(){
	EnterCriticalSection (&getLock);
	if(beg==end)
		SignalObjectAndWait(&getLock,
                            &thereisapplication,
                            INFINITE, 
                            FALSE);
	LeaveCriticalSection (&getLock);
}
void applyarray::get()
{
	EnterCriticalSection (&ArrayLock);
	if(beg=end){
		cout<<"the thread of the keservicedispatchfunction is wrong"<<endl;
		return;
	}
	int k=array[beg];
	beg=(beg+1)%applyarraysize;
	LeaveCriticalSection (&ArrayLock);
	EnterCriticalSection (&putLock);
	if((end+2)%applyarraysize==beg)
		SetEvent(&thereisspace);
	LeaveCriticalSection (&putLock);
}
void applyarray::able_put(){
	EnterCriticalSection (&putLock);
	if((end+1)%applyarraysize==beg)
		::SignalObjectAndWait(&getLock,
                            &thereisspace,
                            INFINITE, 
                            FALSE);
	LeaveCriticalSection (&putLock);
}
void applyarray::put(int i)
{
	EnterCriticalSection (&ArrayLock);
	if((end+1)%applyarraysize==beg){
		cout<<"the thread of the user is wrong"<<endl;
		return;
	}
	array[end]=i;
	end=(end+1)%applyarraysize;
	LeaveCriticalSection (&ArrayLock);
	EnterCriticalSection (&getLock);
	if((beg+1)%applyarraysize==end)
		SetEvent(&thereisapplication);
	LeaveCriticalSection (&getLock);	
}
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -