bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / misc / netware / libprews.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <netware.h>
17 #include <library.h>
18 #include <nks/synch.h>
19 #include "novsock2.h"
20
21 #include "apr_pools.h"
22 #include "apr_private.h"
23
24
25 /* library-private data...*/
26 int          gLibId = -1;
27 void         *gLibHandle = (void *) NULL;
28 NXMutex_t    *gLibLock = (NXMutex_t *) NULL;
29
30 /* internal library function prototypes...*/
31 int DisposeLibraryData(void *);
32
33 int _NonAppStart
34 (
35     void        *NLMHandle,
36     void        *errorScreen,
37     const char  *cmdLine,
38     const char  *loadDirPath,
39     size_t      uninitializedDataLength,
40     void        *NLMFileHandle,
41     int         (*readRoutineP)( int conn, void *fileHandle, size_t offset,
42                     size_t nbytes, size_t *bytesRead, void *buffer ),
43     size_t      customDataOffset,
44     size_t      customDataSize,
45     int         messageCount,
46     const char  **messages
47 )
48 {
49     WSADATA wsaData;
50     apr_status_t status;
51
52     NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
53
54 #pragma unused(cmdLine)
55 #pragma unused(loadDirPath)
56 #pragma unused(uninitializedDataLength)
57 #pragma unused(NLMFileHandle)
58 #pragma unused(readRoutineP)
59 #pragma unused(customDataOffset)
60 #pragma unused(customDataSize)
61 #pragma unused(messageCount)
62 #pragma unused(messages)
63
64     
65     gLibId = register_library(DisposeLibraryData);
66
67     if (gLibId < -1)
68     {
69         OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
70         return -1;
71     }
72
73     gLibHandle = NLMHandle;
74
75     gLibLock = NXMutexAlloc(0, 0, &liblock);
76
77     if (!gLibLock)
78     {
79         OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
80         return -1;
81     }
82
83     apr_netware_setup_time();
84
85     if ((status = apr_pool_initialize()) != APR_SUCCESS)
86         return status;
87
88     return WSAStartup((WORD) MAKEWORD(2, 0), &wsaData);
89 }
90
91 void _NonAppStop( void )
92 {
93     apr_pool_terminate();
94
95     WSACleanup();
96
97     unregister_library(gLibId);
98     NXMutexFree(gLibLock);
99 }
100
101 int  _NonAppCheckUnload( void )
102 {
103     return 0;
104 }
105
106 int register_NLM(void *NLMHandle)
107 {
108     APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
109
110     NXLock(gLibLock);
111     if (!app_data) {
112         app_data = (APP_DATA*)library_malloc(gLibHandle, sizeof(APP_DATA));
113
114         if (app_data) {
115             memset (app_data, 0, sizeof(APP_DATA));
116             set_app_data(gLibId, app_data);
117             app_data->gs_nlmhandle = NLMHandle;
118         }
119     }
120
121     if (app_data && (!app_data->initialized)) {
122         app_data->initialized = 1;
123         NXUnlock(gLibLock);
124         return 0;
125     }
126
127     NXUnlock(gLibLock);
128     return 1;
129 }
130
131 int unregister_NLM(void *NLMHandle)
132 {
133     APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
134
135     NXLock(gLibLock);
136     if (app_data) {
137         app_data->initialized = 0;
138         NXUnlock(gLibLock);
139         return 0;
140     }
141     NXUnlock(gLibLock);
142     return 1;
143 }
144
145 int DisposeLibraryData(void *data)
146 {
147     if (data)
148     {
149         library_free(data);
150     }
151
152     return 0;
153 }
154
155 int setGlobalPool(void *data)
156 {
157     APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
158
159     NXLock(gLibLock);
160
161     if (app_data && !app_data->gPool) {
162         app_data->gPool = data;
163     }
164
165     NXUnlock(gLibLock);
166     return 1;
167 }
168
169 void* getGlobalPool()
170 {
171     APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
172
173     if (app_data) {
174         return app_data->gPool;
175     }
176
177     return NULL;
178 }
179