00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include<system_data_cells.h>
00012 #include<ipl.h>
00013 #include<internals.h>
00014 #include<pridef.h>
00015 #include<wqhdef.h>
00016 #include<linux/sched.h>
00017 #include<ipldef.h>
00018 #include <sch_routines.h>
00019 #include <linux/spinlock.h>
00020 #include <mtxdef.h>
00021 #include <asm/bitops.h>
00022 #include <statedef.h>
00023 #include <queue.h>
00024 #include <sch_routines.h>
00025
00026 #define ioc_gq_mutex ioc_spin
00027 static struct _mtx ioc_spin = { 65535 };
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 void mutexwait(struct _pcb * p, struct _mtx * m) {
00038
00039 p->pcb_l_efwm = m;
00040
00041 p->pcb_w_state = SCH$C_MWAIT;
00042
00043 insque(p,sch_aq_wqhdr[SCH$C_MWAIT].wqh$l_wqfl);
00044 int ipl=getipl();
00045
00046 sch_waitl(p, &sch$aq_wqhdr[SCH$C_MWAIT]);
00047 setipl(ipl);
00048 }
00049
00050
00051
00052
00053
00054
00055 void sch_lockw(struct _mtx * m) {
00056 struct _pcb * p = ctl_gl_pcb;
00057 again:
00058 {}
00059
00060 int ipl = vmslock(&SPIN_SCHED, IPL__SCHED);
00061
00062 if (test_and_set_bit(16, m)) {
00063
00064 mutexwait(p, m);
00065 goto again;
00066 } else {
00067
00068 if (m->mtx_w_owncnt==65535 ) {
00069
00070 m->mtx_w_owncnt++;
00071 p->pcb_w_mtxcnt++;
00072
00073 if (p->pcb_w_mtxcnt==1) {
00074
00075
00076 p->pcb_b_prisav = p->pcb$b_pri;
00077 p->pcb_b_pribsav = p->pcb$b_prib;
00078
00079 if (16>=p->pcb_b_pri) {
00080 p->pcb_b_prib = 15;
00081 sch_change_cur_priority(p, 15);
00082 }
00083 }
00084 } else {
00085
00086 mutexwait(p, m);
00087 goto again;
00088 }
00089 }
00090
00091 ipl = IPL__ASTDEL;
00092 vmsunlock(&SPIN_SCHED, ipl);
00093 }
00094
00095
00096
00097
00098
00099
00100 void sch_lockr(struct _mtx * m) {
00101 struct _pcb * p = ctl_gl_pcb;
00102 again:
00103 {}
00104
00105 int ipl = vmslock(&SPIN_SCHED, IPL__SCHED);
00106
00107 if (test_bit(16, m)) {
00108
00109 mutexwait(p, m);
00110 goto again;
00111 } else {
00112
00113
00114 if (m->mtx_w_owncnt==65535 ) {
00115
00116 m->mtx_w_owncnt++;
00117 p->pcb_w_mtxcnt++;
00118
00119 if (p->pcb_w_mtxcnt==1) {
00120
00121
00122 p->pcb_b_prisav = p->pcb$b_pri;
00123 p->pcb_b_pribsav = p->pcb$b_prib;
00124
00125 if (16>=p->pcb_b_pri) {
00126 p->pcb_b_prib = 15;
00127 sch_change_cur_priority(p, 15);
00128 }
00129 }
00130 } else {
00131 mutexwait(p, m);
00132 goto again;
00133 }
00134 }
00135
00136 ipl = IPL__ASTDEL;
00137 vmsunlock(&SPIN_SCHED, ipl);
00138 }
00139
00140 void sch_iolockw(void) {
00141
00142 sch_lockw(&ioc$gq_mutex);
00143 }
00144
00145
00146
00147
00148
00149
00150 void sch_unlock(struct _mtx * m) {
00151 struct _pcb * p = ctl_gl_pcb;
00152
00153 int ipl = vmslock(&SPIN_SCHED, IPL__SCHED);
00154
00155 p->pcb_w_mtxcnt--;
00156
00157
00158 if (p->pcb_w_mtxcnt==0) {
00159 p->pcb_b_prib = p->pcb$b_pribsav;
00160 sch_change_cur_priority(p, p->pcb$b_pri);
00161 }
00162
00163 m->mtx_w_owncnt--;
00164 if (m->mtx_w_owncnt==65535 ) {
00165
00166
00167 if (test_and_clear_bit(16, m)) {
00168
00169 int rsn = m;
00170
00171 struct _wqh * wq=sch_gq_mwait;
00172 struct _pcb * p=wq->wqh_l_wqfl;
00173 struct _pcb * next;
00174
00175 for (; p!=wq; p=next) {
00176 next = p->pcb_l_sqfl;
00177
00178 if (p->pcb_l_efwm==rsn) {
00179
00180
00181 wq->wqh_l_wqcnt--;
00182
00183 sch_chse(p,PRI$_RESAVL);
00184 }
00185 }
00186 }
00187 }
00188
00189 out:
00190
00191 vmsunlock(&SPIN_SCHED, ipl);
00192 }
00193
00194 void sch_unlockw(struct _mtx * m) {
00195 sch_unlock(m);
00196 }
00197
00198 void sch_iounlockw(void) {
00199
00200 sch_unlockw(&ioc$gq_mutex);
00201 }
00202
00203 void sch_iounlock(void) {
00204
00205 sch_unlockw(&ioc$gq_mutex);
00206 }
00207
00208
00209
00210
00211
00212 void sch_std_ravail(int rsn) {
00213 int retval=test_and_clear_bit(rsn,&sch_gl_resmask);
00214 if (retval==0)
00215 return;
00216 int savipl=vmslock(&SPIN_SCHED,IPL__MAILBOX);
00217 struct _wqh * wq=sch_gq_mwait;
00218 struct _pcb * p=wq->wqh_l_wqfl;
00219 for (;p!=wq;p=p->pcb_l_sqfl) {
00220 if (p->pcb_l_efwm==rsn) {
00221 wq->wqh_l_wqcnt--;
00222 sch_chse(p,PRI$_RESAVL);
00223 }
00224 }
00225 vmsunlock(&SPIN_SCHED,savipl);
00226 }
00227
00228 void sch_rwait(int rsn) {
00229 test_and_set_bit(rsn,&sch_gl_resmask);
00230 return mutexwait(ctl_gl_pcb, rsn);
00231 }
00232