Remove AFS_PARISC_LINUX24_ENV references
[openafs.git] / src / lwp / lwp_nt.c
index b9282ef..b7ee4e9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  * required lib is kernel32.lib, header is winbase.h
  */
 
+#include <afsconfig.h>
 #include <afs/param.h>
+
+#include <roken.h>
+
 #ifdef AFS_NT40_ENV
-#include <stdio.h>
-#include <stdlib.h>
+#include <afs/opr.h>
 #include <afs/afsutil.h>
 #include "lwp.h"
 
@@ -40,7 +43,7 @@ char lwp_debug = 0;
 #ifdef DEBUG
 #define Debug(level, msg)\
         if (lwp_debug && lwp_debug >= level) {\
-            printf("***LWP (0x%x): ", lwp_cpptr);\
+            printf("***LWP (0x%p): ", lwp_cpptr);\
             printf msg;\
             putchar('\n');\
         }
@@ -52,7 +55,6 @@ char lwp_debug = 0;
 
 /* Forward declarations */
 static void Dispatcher(void);
-static void Exit_LWP(void);
 static void Abort_LWP(char *msg);
 static VOID WINAPI Enter_LWP(PVOID fiberData);
 static void Initialize_PCB(PROCESS pcb, int priority, int stacksize,
@@ -91,16 +93,37 @@ struct QUEUE {
 /* Iterator macro */
 #define for_all_elts(var, q, body)\
        {\
-           register PROCESS var, _NEXT_;\
-           register int _I_;\
+           PROCESS var, _NEXT_;\
+           int _I_;\
            for (_I_=q.count, var = q.head; _I_>0; _I_--, var=_NEXT_) {\
                _NEXT_ = var -> next;\
                body\
            }\
        }
 
+#ifdef AFS_WIN95_ENV
+
+LPVOID ConvertThreadToFiber(PROCESS x)
+{
+       return NULL;
+}
+LPVOID CreateFiber(DWORD x ,LPVOID y,PROCESS z)
+{
+       return NULL;
+}
+
+VOID SwitchToFiber(LPVOID p)
+{
+}
+
+VOID DeleteFiber(LPVOID p)
+{
+}
+#endif
+
 
 int lwp_MinStackSize = 0;
+
 /* LWP_InitializeProcessSupport - setup base support for fibers.
  *
  * Arguments:
@@ -110,12 +133,13 @@ int lwp_MinStackSize = 0;
  *     pid - return this process
  *     value:
  *     LWP_SUCCESS (else aborts)
- *     
+ *
  */
+
 int LWP_InitializeProcessSupport(int priority, PROCESS *pid)
 {
     PROCESS pcb;
-    register int i;
+    int i;
     char* value;
 
     Debug(0, ("Entered LWP_InitializeProcessSupport"))
@@ -123,15 +147,15 @@ int LWP_InitializeProcessSupport(int priority, PROCESS *pid)
 
     if (priority >= MAX_PRIORITIES) return LWP_EBADPRI;
 
-    pcb = (PROCESS)malloc(sizeof(*pcb));
+    pcb = malloc(sizeof(*pcb));
     if (pcb == NULL)
        Abort_LWP("Insufficient Storage to Initialize LWP PCB");
     (void) memset((void*)pcb, 0, sizeof(*pcb));
     pcb->fiber = ConvertThreadToFiber(pcb);
-    if (pcb == NULL) 
+    if (pcb == NULL)
        Abort_LWP("Cannot convert main thread to LWP fiber");
 
-    lwp_init = (struct lwp_ctl *) malloc(sizeof(struct lwp_ctl));
+    lwp_init = malloc(sizeof(struct lwp_ctl));
     if (lwp_init == NULL)
        Abort_LWP("Insufficient Storage to Initialize LWP CTL");
     (void) memset((void*)lwp_init, 0, sizeof(struct lwp_ctl));
@@ -149,18 +173,18 @@ int LWP_InitializeProcessSupport(int priority, PROCESS *pid)
 
 
     Initialize_PCB(pcb, priority, 0, NULL, NULL,
-               "Main Process [created by LWP]");   
+               "Main Process [created by LWP]");
 
     lwp_cpptr = pcb;
-    Debug(10, ("Init: Insert 0x%x into runnable at priority %d\n", pcb, priority))
+    Debug(10, ("Init: Insert 0x%p into runnable at priority %d\n", pcb, priority))
     insert(pcb, &runnable[priority]);
 
     if ( ( value = getenv("AFS_LWP_STACK_SIZE")) == NULL )
-       lwp_MinStackSize = AFS_LWP_MINSTACKSIZE;        
+       lwp_MinStackSize = AFS_LWP_MINSTACKSIZE;
     else
        lwp_MinStackSize = (AFS_LWP_MINSTACKSIZE>atoi(value)?
                                AFS_LWP_MINSTACKSIZE : atoi(value));
-   
+
     *pid = pcb;
 
     return LWP_SUCCESS;
@@ -170,7 +194,7 @@ int LWP_InitializeProcessSupport(int priority, PROCESS *pid)
  *
  * Arguments:
  *     funP - start function
- *     stacksize - size of 
+ *     stacksize - size of
  *     priority - LWP priority
  *     argP - initial parameter for start function
  *     name - name of LWP
@@ -186,10 +210,10 @@ int LWP_CreateProcess(int (*funP)(), int stacksize, int priority, void *argP,
                      char *name, PROCESS *pid)
 {
     PROCESS pcb;
-    
+
     purge_dead_pcbs();
 
-    pcb = (PROCESS)malloc(sizeof(*pcb));
+    pcb = malloc(sizeof(*pcb));
     if (pcb == NULL)
        return LWP_ENOMEM;
     (void) memset((void*)pcb, 0, sizeof(*pcb));
@@ -207,13 +231,13 @@ int LWP_CreateProcess(int (*funP)(), int stacksize, int priority, void *argP,
 
     pcb->fiber = CreateFiber(stacksize, Enter_LWP, pcb);
     if (pcb->fiber == NULL) {
-       free((void*)pcb);
+       free(pcb);
        return LWP_EINIT;
     }
-    Debug(0, ("Create: pcb=0x%x, funP=0x%x, argP=0x%x\n", pcb, funP, argP))
+    Debug(0, ("Create: pcb=0x%p, funP=0x%p, argP=0x%p\n", pcb, funP, argP))
     /* Fiber is now created, so fill in PCB */
     Initialize_PCB(pcb, priority, stacksize, funP, argP, name);
-    Debug(10, ("Create: Insert 0x%x into runnable at priority %d\n", pcb, priority))
+    Debug(10, ("Create: Insert 0x%p into runnable at priority %d\n", pcb, priority))
     insert(pcb, &runnable[priority]);
 
     LWPANCHOR.processcnt++;
@@ -232,7 +256,7 @@ int LWP_DestroyProcess(PROCESS pid)
     if (!lwp_init)
        return LWP_EINIT;
 
-    
+
     if (lwp_cpptr != pid) {
        Dispose_of_Dead_PCB(pid);
     } else {
@@ -258,7 +282,7 @@ int LWP_QSignal(PROCESS pid)
 {
     if (pid->status == QWAITING) {
        pid->status = READY;
-       Debug(10, ("QSignal: Insert 0x%x into runnable at priority %d\n", pid, pid->priority))
+       Debug(10, ("QSignal: Insert 0x%p into runnable at priority %d\n", pid, pid->priority))
        insert(pid, &runnable[pid->priority]);
        return LWP_SUCCESS;
     }
@@ -299,7 +323,7 @@ int LWP_DispatchProcess(void)               /* explicit voluntary preemption */
 static void Dump_Processes(void)
 {
     if (lwp_init) {
-       register int i;
+       int i;
        for (i=0; i<MAX_PRIORITIES; i++)
            for_all_elts(x, runnable[i], {
                printf("[Priority %d]\n", i);
@@ -329,7 +353,7 @@ static int Internal_Signal(char *event)
     int rc = LWP_ENOWAIT;
     int i;
 
-    Debug(0, ("Entered Internal_Signal [event id 0x%x]", event))
+    Debug(0, ("Entered Internal_Signal [event id 0x%p]", event))
     if (!lwp_init) return LWP_EINIT;
     if (event == NULL) return LWP_EBADEVENT;
     for_all_elts(temp, blocked, {
@@ -338,7 +362,7 @@ static int Internal_Signal(char *event)
                if (temp -> eventlist[i] == event) {
                    temp -> eventlist[i] = NULL;
                    rc = LWP_SUCCESS;
-                   Debug(0, ("Signal satisfied for PCB 0x%x", temp))
+                   Debug(0, ("Signal satisfied for PCB 0x%p", temp))
                    if (--temp->waitcnt == 0) {
                        temp -> status = READY;
                        temp -> wakevent = i+1;
@@ -367,7 +391,7 @@ int LWP_INTERNALSIGNAL(void *event, int yield)
 
 int LWP_TerminateProcessSupport()      /* terminate all LWP support */
 {
-    register int i;
+    int i;
 
     Debug(0, ("Entered Terminate_Process_Support"))
     if (lwp_init == NULL) return LWP_EINIT;
@@ -409,8 +433,8 @@ int LWP_MwaitProcess(int wcount, void **evlist)
     if (ecount > lwp_cpptr->eventlistsize) {
 
        void **save_eventlist = lwp_cpptr->eventlist;
-       lwp_cpptr->eventlist = (char **)realloc(lwp_cpptr->eventlist,
-                                               ecount*sizeof(char *));
+       lwp_cpptr->eventlist = realloc(lwp_cpptr->eventlist,
+                                      ecount*sizeof(char *));
        if (lwp_cpptr->eventlist == NULL) {
            lwp_cpptr->eventlist = save_eventlist;
            Dispatcher();
@@ -461,25 +485,25 @@ static void Initialize_PCB(PROCESS pcb, int priority, int stacksize,
     pcb->funP = funP;
     pcb->argP = argP;
     pcb->status = READY;
-    pcb->eventlist = (void**)malloc(EVINITSIZE*sizeof(void*));
+    pcb->eventlist = malloc(EVINITSIZE*sizeof(void*));
     pcb->eventlistsize =  pcb->eventlist ? EVINITSIZE : 0;
     pcb->eventcnt = 0;
     pcb->wakevent = 0;
     pcb->waitcnt = 0;
     pcb->next = pcb->prev = (PROCESS)NULL;
-    pcb->iomgrRequest = (struct IoRequest*)NULL;
+    pcb->iomgrRequest = NULL;
     pcb->index = lwp_nextindex ++;
 }
 
 
-VOID WINAPI Enter_LWP(PVOID fiberData)
+static VOID WINAPI Enter_LWP(PVOID fiberData)
 {
     PROCESS pcb = (PROCESS)fiberData;
 
 /* next lines are new..... */
     lwp_cpptr = pcb;
 
-    Debug(2, ("Enter_LWP: pcb=0x%x, funP=0x%x, argP=0x%x\n", pcb, pcb->funP, pcb->argP))
+    Debug(2, ("Enter_LWP: pcb=0x%p, funP=0x%p, argP=0x%p\n", pcb, pcb->funP, pcb->argP))
 
     (*pcb->funP)(pcb->argP);
 
@@ -495,7 +519,7 @@ static void Abort_LWP(char *msg)
     printf("***LWP: Abort --- dumping PCBs ...\n");
     Dump_Processes();
 #endif
-    Exit_LWP();
+    opr_abort();
 }
 
 #ifdef DEBUG
@@ -503,10 +527,10 @@ static void Dump_One_Process(PROCESS pid)
 {
     int i;
 
-    printf("***LWP: Process Control Block at 0x%x\n", pid);
+    printf("***LWP: Process Control Block at 0x%p\n", pid);
     printf("***LWP: Name: %s\n", pid->name);
     if (pid->funP != NULL)
-       printf("***LWP: Initial entry point: 0x%x\n", pid->funP);
+       printf("***LWP: Initial entry point: 0x%p\n", pid->funP);
     switch (pid->status) {
        case READY:     printf("READY");     break;
        case WAITING:   printf("WAITING");   break;
@@ -514,7 +538,7 @@ static void Dump_One_Process(PROCESS pid)
        default:        printf("unknown");
     }
     putchar('\n');
-    printf("***LWP: Priority: %d \tInitial parameter: 0x%x\n",
+    printf("***LWP: Priority: %d \tInitial parameter: 0x%p\n",
            pid->priority, pid->argP);
     if (pid->stacksize != 0) {
        printf("***LWP:  Stacksize: %d\n", pid->stacksize);
@@ -523,7 +547,7 @@ static void Dump_One_Process(PROCESS pid)
        printf("***LWP: Number of events outstanding: %d\n", pid->waitcnt);
        printf("***LWP: Event id list:");
        for (i=0;i<pid->eventcnt;i++)
-           printf(" 0x%x", pid->eventlist[i]);
+           printf(" 0x%p", pid->eventlist[i]);
        putchar('\n');
     }
     if (pid->wakevent>0)
@@ -541,7 +565,7 @@ int LWP_TraceProcesses = 0;
 
 static void Dispatcher(void)
 {
-    register int i;
+    int i;
 #ifdef DEBUG
     static int dispatch_count = 0;
 
@@ -574,7 +598,7 @@ static void Dispatcher(void)
 
 #ifdef DEBUG
     if (LWP_TraceProcesses > 0)
-       printf("Dispatch %d [PCB at 0x%x] \"%s\"\n", ++dispatch_count,
+       printf("Dispatch %d [PCB at 0x%p] \"%s\"\n", ++dispatch_count,
               runnable[i].head, runnable[i].head->name);
 #endif
 
@@ -582,17 +606,6 @@ static void Dispatcher(void)
     SwitchToFiber(lwp_cpptr->fiber);
 }
 
-void lwp_abort(void)
-{
-    afs_NTAbort();
-}
-
-static void Exit_LWP(void)
-{
-
-    lwp_abort();
-}
-
 static void Delete_PCB(PROCESS pid)
 {
     Debug(4, ("Entered Delete_PCB"))
@@ -602,14 +615,15 @@ static void Delete_PCB(PROCESS pid)
     LWPANCHOR.processcnt--;
 }
 
+
 static void Free_PCB(PROCESS pid)
 {
     Debug(4, ("Entered Free_PCB"))
     if (pid->fiber != NULL) {
        DeleteFiber(pid->fiber);
     }
-    if (pid->eventlist != NULL)  free((void*)pid->eventlist);
-    free((void*)pid);
+    if (pid->eventlist != NULL)  free(pid->eventlist);
+    free(pid);
 }
 
 static void Dispose_of_Dead_PCB(PROCESS cur)