Added prioritized threads.
authorMilind Bhandarkar <milind@cs.uiuc.edu>
Fri, 28 Apr 2000 20:54:50 +0000 (20:54 +0000)
committerMilind Bhandarkar <milind@cs.uiuc.edu>
Fri, 28 Apr 2000 20:54:50 +0000 (20:54 +0000)
src/conv-core/convcore.c
src/conv-core/converse.h
src/conv-core/threads.c

index 0f8668cde5e71042c0c39571c58e6062edfa3fd2..ce0150511ef27e83ccbed3865c349cbd39d16e77 100644 (file)
@@ -947,7 +947,7 @@ static CthThread CthSuspendNormalThread()
   return CpvAccess(CthSchedulingThread);
 }
 
-static void CthEnqueueSchedulingThread(CthThread t);
+static void CthEnqueueSchedulingThread(CthThread t, int, int, int*);
 static CthThread CthSuspendSchedulingThread();
 
 static CthThread CthSuspendSchedulingThread()
@@ -989,7 +989,7 @@ static void CthResumeSchedulingThread(CthThread t)
   CthThread me = CthSelf();
   CmiGrabBuffer((void**)&t);
   if (me == CpvAccess(CthMainThread)) {
-    CthEnqueueSchedulingThread(me);
+    CthEnqueueSchedulingThread(me,CQS_QUEUEING_FIFO, 0, 0);
   } else {
     CthSetNext(me, CpvAccess(CthSleepingStandins));
     CpvAccess(CthSleepingStandins) = me;
@@ -998,16 +998,16 @@ static void CthResumeSchedulingThread(CthThread t)
   CthResume(t);
 }
 
-static void CthEnqueueNormalThread(CthThread t)
+static void CthEnqueueNormalThread(CthThread t, int s, int pb, int *prio)
 {
   CmiSetHandler(t, CpvAccess(CthResumeNormalThreadIdx));
-  CsdEnqueueFifo(t);
+  CsdEnqueueGeneral(t, s, pb, prio);
 }
 
-static void CthEnqueueSchedulingThread(CthThread t)
+static void CthEnqueueSchedulingThread(CthThread t, int s, int pb, int *prio)
 {
   CmiSetHandler(t, CpvAccess(CthResumeSchedulingThreadIdx));
-  CsdEnqueueFifo(t);
+  CsdEnqueueGeneral(t, s, pb, prio);
 }
 
 void CthSetStrategyDefault(CthThread t)
index df404672774c774fa42ae4d7d6e9aa7e882e40ce..1c1fd119d1fa96fb0b25d4cc505ce296c20f4889 100644 (file)
@@ -767,6 +767,7 @@ void   CmiDeliverSpecificMsg(int handler);
 typedef struct CthThreadStruct *CthThread;
 
 typedef void        (*CthVoidFn)();
+typedef void        (*CthAwkFn)(CthThread,int,int,int*);
 typedef CthThread   (*CthThFn)();
 
 int        CthImplemented(void);
@@ -781,9 +782,11 @@ int        CthIsSuspendable(CthThread);
 
 void       CthSuspend(void);
 void       CthAwaken(CthThread);
-void       CthSetStrategy(CthThread, CthVoidFn, CthThFn);
+void       CthAwakenPrio(CthThread, int, int, int *);
+void       CthSetStrategy(CthThread, CthAwkFn, CthThFn);
 void       CthSetStrategyDefault(CthThread);
 void       CthYield(void);
+void       CthYieldPrio(int,int,int*);
 
 void       CthSetNext(CthThread t, CthThread next);
 CthThread  CthGetNext(CthThread t);
index ab91131c1b946aa4f97936eb1ceca55634336e9d..2387b3816f9399998a08ea497065c5d0db08a645 100644 (file)
@@ -71,7 +71,7 @@
  *     scheduler's awaken-function to awaken thread t.  This probably causes
  *     the thread t to be inserted in the ready-pool.
  *
- * void CthSetStrategy(CthThread t, CthVoidFn awakenfn, CthThFn choosefn)
+ * void CthSetStrategy(CthThread t, CthAwkFn awakenfn, CthThFn choosefn)
  *
  *     This specifies the scheduling functions to be used for thread 't'.
  *     The scheduling functions must have the following prototypes:
@@ -128,7 +128,7 @@ typedef struct CthProcInfo *CthProcInfo;
 typedef struct CthThreadStruct
 {
   char cmicore[CmiMsgHeaderSizeBytes];
-  CthVoidFn  awakenfn;
+  CthAwkFn  awakenfn;
   CthThFn    choosefn;
   CthVoidFn  startfn;    /* function that thread will execute */
   void      *startarg;   /* argument that start function will be passed */
@@ -387,7 +387,15 @@ CthThread th;
 {
   if (th->awakenfn == 0) CthNoStrategy();
   if (th->insched) CmiAbort("CthAwaken: thread already awake.\n");
-  th->awakenfn(th);
+  th->awakenfn(th, CQS_QUEUEING_FIFO, 0, 0);
+  th->insched = 1;
+}
+
+void CthAwakenPrio(CthThread th, int s, int pb, int *prio)
+{
+  if (th->awakenfn == 0) CthNoStrategy();
+  if (th->insched) CmiAbort("CthAwaken: thread already awake.\n");
+  th->awakenfn(th, s, pb, prio);
   th->insched = 1;
 }
 
@@ -397,6 +405,12 @@ void CthYield()
   CthSuspend();
 }
 
+void CthYieldPrio(int s, int pb, int *prio)
+{
+  CthAwakenPrio(CthCpvAccess(CthProc)->current, s, pb, prio);
+  CthSuspend();
+}
+
 int CthRegister(size)
 int size;
 {
@@ -469,7 +483,7 @@ typedef void *(qt_userf_t)(void *pu);
 struct CthThreadStruct
 {
   char cmicore[CmiMsgHeaderSizeBytes];
-  CthVoidFn  awakenfn;
+  CthAwkFn  awakenfn;
   CthThFn    choosefn;
   int        autoyield_enable;
   int        autoyield_blocks;
@@ -658,7 +672,7 @@ void CthAwaken(CthThread th)
   if(CpvAccess(traceOn))
     traceAwaken();
 #endif
-  th->awakenfn(th);
+  th->awakenfn(th, CQS_QUEUEING_FIFO, 0, 0);
 }
 
 void CthYield()
@@ -667,6 +681,23 @@ void CthYield()
   CthSuspend();
 }
 
+void CthAwakenPrio(CthThread th, int s, int pb, int *prio)
+{
+  if (th->awakenfn == 0) CthNoStrategy();
+  CpvAccess(curThread) = th;
+#ifndef CMK_OPTIMIZE
+  if(CpvAccess(traceOn))
+    traceAwaken();
+#endif
+  th->awakenfn(th, s, pb, prio);
+}
+
+void CthYieldPrio(int s, int pb, int *prio)
+{
+  CthAwakenPrio(CthCpvAccess(CthCurrent), s, pb, prio);
+  CthSuspend();
+}
+
 int CthRegister(int size)
 {
   int result;
@@ -743,7 +774,7 @@ CthThread CthUnpackThread(void *buffer)
 struct CthThreadStruct
 {
   char cmicore[CmiMsgHeaderSizeBytes];
-  CthVoidFn  awakenfn;
+  CthAwkFn  awakenfn;
   CthThFn    choosefn;
   int        autoyield_enable;
   int        autoyield_blocks;
@@ -930,7 +961,7 @@ CthThread th;
   if(CpvAccess(traceOn))
     traceAwaken();
 #endif
-  th->awakenfn(th);
+  th->awakenfn(th, CQS_QUEUEING_FIFO, 0, 0);
 }
 
 void CthYield()
@@ -939,6 +970,23 @@ void CthYield()
   CthSuspend();
 }
 
+void CthAwakenPrio(CthThread th, int s, int pb, int *prio)
+{
+  if (th->awakenfn == 0) CthNoStrategy();
+  CpvAccess(curThread) = th;
+#ifndef CMK_OPTIMIZE
+  if(CpvAccess(traceOn))
+    traceAwaken();
+#endif
+  th->awakenfn(th, s, pb, prio);
+}
+
+void CthYieldPrio(int s, int pb, int *prio)
+{
+  CthAwakenPrio(CthCpvAccess(CthCurrent), s, pb, prio);
+  CthSuspend();
+}
+
 int CthRegister(size)
 int size;
 {
@@ -990,7 +1038,7 @@ static void CthNoStrategy(void)
 
 int CthImplemented() { return 1; } 
 
-void CthSetStrategy(CthThread t, CthVoidFn awkfn, CthThFn chsfn)
+void CthSetStrategy(CthThread t, CthAwkFn awkfn, CthThFn chsfn)
 {
   t->awakenfn = awkfn;
   t->choosefn = chsfn;