📄 shared.c
字号:
/* shared.c */#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"int com[5];voidmain_loop(ULONG l1, ULONG l2, ULONG l3, ULONG l4){ char me[5]; ULONG rc, mode; int loop_count, tmp; if (rc = t_getreg(0, 0, (ULONG *) me)) /* Get my name */ fail(rc, "t_getreg()"); me[5] = '\0'; for (loop_count = 0; loop_count < LOOP_MAX; loop_count++) { /* Try but DO NOT BLOCK on the semaphore. We want to SHOW the user when we can't get it. */ if (ERR_NOSEM == (rc = sm_p(smid, SM_NOWAIT, 0))) { /* Semaphore not available--tell the user */ bprintf("(%s)", me); /* And then wait for it. */ if (0 != (rc = sm_p(smid, SM_WAIT, 0))) fail(rc, "%s sm_p(%08x) failed", me, smid); } else if (0 != rc) fail(rc, "%s main_loop sm_p(0x%08x)", me, smid); /* Regardless, we have the semaphore now */ bprintf("%s updating: ", me); com[0]++; if (com[0] & 1) { com[1] = com[2]; com[2] = com[3]; com[3]++; } else { com[1]++; com[2]++; } tm_wkafter(1+ (rand() % 10)); /* Delay briefly */ if (com[0] % 5) com[3] = 0; com[4] = com[0] + com[1] + com[2] + com[3]; bprintf(" done\n"); if (0 != (rc = sm_v(smid))) fail(rc, "main_loop: %s sm_v(0x%08x)", me, smid); tm_wkafter(9 + (rand() % 10)); /* Delay between uses */ } /* Disable task preemption */ if (rc = t_mode(T_NOPREEMPT, T_NOPREEMPT, & mode)) fail(rc, "main_loop: %s t_mode #1", me); running--; /* Re-establish task mode */ if (rc = t_mode(T_NOPREEMPT, mode, & mode)) fail(rc, "main_loop: %s t_mode #2", me); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -