本文整理汇总了C++中Disable_Interrupts函数的典型用法代码示例。如果您正苦于以下问题:C++ Disable_Interrupts函数的具体用法?C++ Disable_Interrupts怎么用?C++ Disable_Interrupts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Disable_Interrupts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Calibrate_Delay
/*
* Calibrate the delay loop.
* This will initialize s_spinCountPerTick, which indicates
* how many iterations of the loop are executed per timer tick.
*/
static void Calibrate_Delay(void) {
Disable_Interrupts();
/* Install temporarily interrupt handler */
Install_IRQ(TIMER_IRQ, &Timer_Calibrate);
Enable_IRQ(TIMER_IRQ);
Enable_Interrupts();
/* Wait a few ticks */
while (g_numTicks < CALIBRATE_NUM_TICKS) ;
/*
* Execute the spin loop.
* The temporary interrupt handler will overwrite the
* loop counter when the next tick occurs.
*/
Spin(INT_MAX);
Disable_Interrupts();
/*
* Mask out the timer IRQ again,
* since we will be installing a real timer interrupt handler.
*/
Disable_IRQ(TIMER_IRQ);
Enable_Interrupts();
}
示例2: Switch_To_User_Context
/*
* If the given thread has a User_Context,
* switch to its memory space.
*
* Params:
* kthread - the thread that is about to execute
* state - saved processor registers describing the state when
* the thread was interrupted
*/
void Switch_To_User_Context(struct Kernel_Thread* kthread, struct Interrupt_State* state)
{
/*
* Hint: Before executing in user mode, you will need to call
* the Set_Kernel_Stack_Pointer() and Switch_To_Address_Space()
* functions.
*/
//TODO("Switch to a new user address space, if necessary");
Set_Kernel_Stack_Pointer((ulong_t)((kthread->stackPage)+PAGE_SIZE));
// ERROR: only user thread need this function
if(Interrupts_Enabled())
Disable_Interrupts();
if (kthread->userContext != 0)
{
//Print("SuC: %d ldt: %d\n", (int)(kthread->userContext),
// (int)));
//Set_Kernel_Stack_Pointer((ulong_t)(kthread->esp));
Switch_To_Address_Space(kthread->userContext);
//Print("Switch to Address Space!\n");
//Print("jump to %d\n", (int)(kthread->userContext->entryAddr));
//Dump_Interrupt_State(state);
//KASSERT(0);
}
Enable_Interrupts();
}
示例3: P
int P(int sid)
{
struct Semaphore* sema = (&s_semaphoreList)->head;
struct Mutex* mutex;
struct Condition* cond;
//find sem by sid
while (sema != 0)
{
if (sema->sid == sid)
{
mutex = &(sema->mutex); // important
cond = &(sema->cond);
Enable_Interrupts();
Mutex_Lock(mutex);
while(sema->count <= 0)
{
Cond_Wait(cond, mutex);
//Print("WAKE UP!");
}
sema->count--;
Mutex_Unlock(mutex);
Disable_Interrupts();
return 0;
}
sema = Get_Next_In_Semaphore_List(sema);
}
return -1;
}
示例4: Cond_Broadcast
/*
* Wake up all threads waiting on the given condition.
* The mutex guarding the condition should be held!
*/
void Cond_Broadcast(struct Condition* cond)
{
KASSERT(Interrupts_Enabled());
Disable_Interrupts(); /* prevent scheduling */
Wake_Up(&cond->waitQueue);
Enable_Interrupts(); /* resume scheduling */
}
示例5: Join
/*
* Wait for given thread to die.
* Interrupts must be enabled.
* Returns the thread exit code.
*/
int Join(struct Kernel_Thread* kthread)
{
int exitCode;
KASSERT(Interrupts_Enabled());
/* It is only legal for the owner to join */
KASSERT(kthread->owner == g_currentThread);
Disable_Interrupts();
/* Wait for it to die */
while (kthread->alive) {
Wait(&kthread->joinQueue);
}
/* Get thread exit code. */
exitCode = kthread->exitCode;
/* Release our reference to the thread */
Detach_Thread(kthread);
Enable_Interrupts();
return exitCode;
}
示例6: Sys_Sync
/*
* Flush filesystem buffers
* Params: none
* Returns: 0 if successful, error code (< 0) if unsuccessful
*/
static int Sys_Sync(struct Interrupt_State *state) {
int rc;
Enable_Interrupts();
rc = Sync();
Disable_Interrupts();
return rc;
}
示例7: Sys_Open
/*
* Open a file.
* Params:
* state->ebx - address of user string containing path of file to open
* state->ecx - length of path
* state->edx - file mode flags
*
* Returns: a file descriptor (>= 0) if successful,
* or an error code (< 0) if unsuccessful
*/
static int Sys_Open(struct Interrupt_State *state)
{
char path[VFS_MAX_PATH_LEN] = {'\0', };
struct File **pFile;
int fd;
int rc;
struct File** fileList = g_currentThread->userContext->fileList;
for(fd = 0; fd < USER_MAX_FILES; fd++){
if(fileList[fd] == NULL){
pFile = &fileList[fd];
break;
}
}
if(fd == USER_MAX_FILES)
{
return -1;
}
Copy_From_User(path, state->ebx, state->ecx);
Enable_Interrupts();
if((rc = Open(path, state->edx, pFile)) < 0){
fd = rc;
}
Disable_Interrupts();
return fd;
//TODO("Open system call");
}
示例8: Yield
/*
* Voluntarily give up the CPU to another thread.
* Does nothing if no other threads are ready to run.
*/
void Yield(void)
{
Disable_Interrupts();
Make_Runnable(g_currentThread);
Schedule();
Enable_Interrupts();
}
示例9: Exit
/*
* Exit the current thread.
* Calling this function initiates a context switch.
*/
void Exit(int exitCode)
{
struct Kernel_Thread* current = g_currentThread;
if (Interrupts_Enabled())
Disable_Interrupts();
/* Thread is dead */
current->exitCode = exitCode;
current->alive = false;
/* Clean up any thread-local memory */
Tlocal_Exit(g_currentThread);
/* Notify the thread's owner, if any */
Wake_Up(¤t->joinQueue);
/* Remove the thread's implicit reference to itself. */
Detach_Thread(g_currentThread);
/*
* Schedule a new thread.
* Since the old thread wasn't placed on any
* thread queue, it won't get scheduled again.
*/
Schedule();
/* Shouldn't get here */
KASSERT(false);
}
示例10: Sys_Mount
/*
* Mount a filesystem.
* Params:
* state->ebx - contains a pointer to the Mount_Syscall_Args structure
* which contains the block device name, mount prefix,
* and filesystem type
*
* Returns:
* 0 if successful, error code if unsuccessful
*/
static int Sys_Mount(struct Interrupt_State *state) {
int rc = 0;
struct VFS_Mount_Request *args = 0;
/* Allocate space for VFS_Mount_Request struct. */
if ((args =
(struct VFS_Mount_Request *)Malloc(sizeof(struct VFS_Mount_Request)))
== 0) {
rc = ENOMEM;
goto done;
}
/* Copy the mount arguments structure from user space. */
if (!Copy_From_User(args, state->ebx, sizeof(struct VFS_Mount_Request))) {
rc = EINVALID;
goto done;
}
/*
* Hint: use devname, prefix, and fstype from the args structure
* and invoke the Mount() VFS function. You will need to check
* to make sure they are correctly nul-terminated.
*/
/* TODO("Mount system call"); */
Enable_Interrupts(); // duped from schulman
// Print("eee %s %s %s\n", args->devname, args->prefix, args->fstype);
rc = Mount(args->devname, args->prefix, args->fstype);
Disable_Interrupts(); // duped from schulman
done:
if (args != 0) Free(args);
return rc;
}
示例11: Sys_OpenDirectory
/*
* Open a directory.
* Params:
* state->ebx - address of user string containing path of directory to open
* state->ecx - length of path
*
* Returns: a file descriptor (>= 0) if successful,
* or an error code (< 0) if unsuccessful
*/
static int Sys_OpenDirectory(struct Interrupt_State *state)
{
char path[VFS_MAX_PATH_LEN] = {'\0' };
struct File **pDir; /* important */
int fd;
int rc;
struct File** fileList = g_currentThread->userContext->fileList;
for(fd = 0; fd < USER_MAX_FILES; fd++){
if(fileList[fd] == NULL){
pDir = &fileList[fd];
break;
}
}
if(fd == USER_MAX_FILES)
{
return -1;
}
Copy_From_User(path, state->ebx, state->ecx);
Enable_Interrupts();
//Print("Sys_OpenDirectory : %s\n", path);
if((rc = Open_Directory(path, pDir)) < 0){ /* important */
fd = rc;
}
//Print("%d, fileList[fd] : %x\n", fd, fileList[fd]);
Disable_Interrupts();
return fd;
//TODO("Open directory system call");
}
示例12: Sys_OpenDirectory
/*
* Open a directory.
* Params:
* state->ebx - address of user string containing path of directory to open
* state->ecx - length of path
*
* Returns: a file descriptor (>= 0) if successful,
* or an error code (< 0) if unsuccessful
*/
static int Sys_OpenDirectory(struct Interrupt_State *state) {
char *path;
struct File *file;
int rc = 0;
rc = get_path_from_registers(state->ebx, state->ecx, &path);
if(rc != 0) {
return rc;
}
rc = next_descriptor();
if(rc < 0) {
return rc;
}
Enable_Interrupts(); // duped from schulman
rc = Open_Directory(path, &file);
Disable_Interrupts();
Free(path);
if(rc >= 0) {
return add_file_to_descriptor_table(file);
} else {
return rc;
}
}
示例13: Sys_ReadEntry
/*
* Read a directory entry from an open directory handle.
* Params:
* state->ebx - file descriptor of the directory
* state->ecx - user address of struct VFS_Dir_Entry to copy entry into
* Returns: 0 if successful, error code (< 0) if unsuccessful
*/
static int Sys_ReadEntry(struct Interrupt_State *state) {
int bytes_written = 0;
/* where is the file table? */
if(state->ebx > USER_MAX_FILES) {
return EINVALID;
}
if( g_currentThread->userContext->file_descriptor_table[state->ebx] ) {
void *data_buffer = Malloc(sizeof(struct VFS_Dir_Entry));
if(!data_buffer) {
return ENOMEM;
}
Enable_Interrupts();
bytes_written = Read_Entry(g_currentThread->userContext->file_descriptor_table[state->ebx], data_buffer);
Disable_Interrupts();
if(bytes_written < 0) {
Free(data_buffer);
return bytes_written;
}
if (!Copy_To_User(state->ecx, data_buffer, sizeof(struct VFS_Dir_Entry))) {
Free(data_buffer);
return EINVALID;
}
Free(data_buffer);
return bytes_written;
} else {
return ENOTFOUND;
}
}
示例14: V
int V(int sid)
{
struct Semaphore* sema = (&s_semaphoreList)->head;
struct Mutex* mutex;
struct Condition* cond;
//find sem by sid
while (sema != 0)
{
if (sema->sid == sid)
{
mutex = &(sema->mutex);
cond = &(sema->cond);
Enable_Interrupts();
Mutex_Lock(mutex);
sema->count = sema->count + 1;
//Print("wait queue : %d", cond->waitQueue);
Cond_Broadcast(cond);
Mutex_Unlock(mutex);
Disable_Interrupts();
return 0;
}
sema = Get_Next_In_Semaphore_List(sema);
}
return -1;
}
示例15: Sys_Exit
/*
* Exit system call.
* The interrupted user process is terminated.
* Params:
* state->ebx - process exit code
* Returns:
* Never returns to user mode!
*/
static int Sys_Exit(struct Interrupt_State* state)
{
Enable_Interrupts();
Detach_User_Context(g_currentThread);
Disable_Interrupts();
Exit(state->ebx);
return 0;
}