Debian Codegraph @

sysport/sysport.c

raw symbols SCIP
1 #cxx . . $ `<file>/sysport/sysport.c`/include <stdlib.h>
2 #include <stdio.h>
3 #include <errno.h>
4 #include "sysport.h"cxx . . $ `<file>/sysport/sysport.h`/
5
6 /**** CLOCK *************************************************************************/
7
8 #if defined(USECLOCK)
9
10 #include <time.h>
11 extern myclock_t myclock(void) {return (myclock_t)clock();}
12 extern myclock_t ticks_per_sec (void) {return CLOCKS_PER_SEC;}
13
14 #elif defined(USEWINCLOCK)
15
16 #define WIN32_LEAN_AND_MEAN
17 #include <windows.h>
18 extern myclock_t myclock(void) {return (myclock_t)GetTickCount();}
19 extern myclock_t ticks_per_sec (void) {return 1000;}
20
21
22 #elif defined(USELINCLOCKcxx . . $ `sysport/sysport.h:59:10`!)
23
24 #include <sys/time.h>
25 extern myclock_tcxx . . $ myclock_t# myclockcxx . . $ myclock(da6335ded91d79c2).(void)
26 {
27 struct timevalcxx . . $ timeval# tv;
28 gettimeofdaycxx . . $ gettimeofday(ee8865a94200b3d6).(&tv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
29 return (myclock_tcxx . . $ myclock_t#)tv.tv_seccxx . . $ timeval#tv_sec. * 1000 + (myclock_tcxx . . $ myclock_t#)tv.tv_useccxx . . $ timeval#tv_usec./1000;
30 }
31 extern myclock_tcxx . . $ myclock_t# ticks_per_seccxx . . $ ticks_per_sec(da6335ded91d79c2). (void) {return 1000;}
32
33 #else
34
35 #error No Clock specified in compilation
36
37 #endif
38
39 /**** PATH NAMES *************************************************************************/
40
41 #if defined(GCCLINUXcxx . . $ `sysport/sysport.h:31:11`!)
42 extern int isfoldersepcxx . . $ isfoldersep(7864480464b09eea). (int x) { return x == '/';}
43 #elif defined(MVSC)
44 extern int isfoldersep (int x) { return x == '\\' || x == ':';}
45 #else
46 extern int isfoldersep (int x) { return x == '/' || x == '\\' || x == ':';}
47 #endif
48
49 /**** Maximum Files Open *****************************************************************/
50
51 #if defined(GCCLINUXcxx . . $ `sysport/sysport.h:31:11`!)
52 #include <sys/resource.h>
53 #if 0
54 struct rlimit {
55 rlim_t rlim_cur; /* Soft limit */
56 rlim_t rlim_max; /* Hard limit (ceiling for rlim_cur) */
57 };
58 #endif
59 extern int mysys_fopen_maxcxx . . $ mysys_fopen_max(b126dc7c1de90089). (void)
60 {
61 int ok;
62 struct rlimitcxx . . $ rlimit# rl;
63 ok = 0 == getrlimitcxx . . $ getrlimit(6c0ccb4b8dc2eb78).(RLIMIT_NOFILEcxx . . $ `<external>/1890803886155400780/resource.h:63:9`!, &rl);
64 if (ok)
65 return (int)rl.rlim_curcxx . . $ rlimit#rlim_cur.;
66 else
67 return FOPEN_MAXcxx . . $ `<external>/232824719582829767/stdio.h:143:9`!;
68 }
69 #elif defined(MVSC)
70 extern int mysys_fopen_max (void) { return FOPEN_MAX;}
71 #else
72 extern int mysys_fopen_max (void) { return FOPEN_MAX;}
73 #endif
74
75
76 #if defined(MULTI_THREADED_INTERFACEcxx . . $ `sysport/sysport.h:60:10`!)
77 /**** THREADS ****************************************************************************/
78
79 /*
80 |
81 | POSIX
82 |
83 \*-------------------------*/
84 #if defined (POSIX_THREADScxx . . $ `sysport/sysport.h:62:10`!)
85
86 #include <pthread.h>
87
88 extern int /* boolean */
89 mythread_createcxx . . $ mythread_create(fac9e0f9131e5f68). (/*@out@*/ mythread_tcxx . . $ mythread_t# *thread, routine_tcxx . . $ routine_t# start_routine, void *arg, /*@out@*/ int *ret_error)
90 {
91 const pthread_attr_tcxx . . $ pthread_attr_t# *attr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; /* default attributes */
92 int ret;
93 ret = pthread_createcxx . . $ pthread_create(2141a84bcac899e5). (thread, attr, start_routine, arg);
94 *ret_error = ret;
95 return 0 == ret;
96 }
97
98 extern int /* boolean */
99 mythread_joincxx . . $ mythread_join(15f694ef3c96d230). (mythread_tcxx . . $ mythread_t# thread)
100 {
101 void *p; /* value return from pthread_exit, not used */
102 int ret = pthread_joincxx . . $ pthread_join(269902cf949f12c5). (thread, &p);
103 return 0 == ret;
104 }
105
106 extern void
107 mythread_exitcxx . . $ mythread_exit(49f6e7a06ebc5aa8). (void)
108 {
109 pthread_exitcxx . . $ pthread_exit(b8a01b603c304b90). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
110 }
111
112
113 extern const char *
114 mythread_create_errorcxx . . $ mythread_create_error(f7ae7e56280f18ae). (int err)
115 {
116 const char *s;
117 switch (err) {
118 case 0 : s = "Success"; break;
119 case EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!: s = "EAGAIN" ; break;
120 case EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!: s = "EINVAL" ; break;
121 case EPERMcxx . . $ `<external>/8987895939074593727/errno-base.h:5:9`! : s = "EPERM" ; break;
122 default : s = "Unknown error"; break;
123 }
124 return s;
125 }
126
127 extern void mythread_mutex_initcxx . . $ mythread_mutex_init(4f83bfebf4bb9c8b). (mythread_mutex_tcxx . . $ mythread_mutex_t# *m) { pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa). (m,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);}
128 extern void mythread_mutex_destroycxx . . $ mythread_mutex_destroy(4f83bfebf4bb9c8b). (mythread_mutex_tcxx . . $ mythread_mutex_t# *m) { pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9).(m) ;}
129 extern void mythread_mutex_lockcxx . . $ mythread_mutex_lock(4f83bfebf4bb9c8b). (mythread_mutex_tcxx . . $ mythread_mutex_t# *m) { pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9). (m) ;}
130 extern void mythread_mutex_unlockcxx . . $ mythread_mutex_unlock(4f83bfebf4bb9c8b). (mythread_mutex_tcxx . . $ mythread_mutex_t# *m) { pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9). (m) ;}
131
132 #ifdef SPINLOCKS
133 extern void mythread_spinx_init (mythread_spinx_t *m) { pthread_spin_init (m,0);} /**/
134 extern void mythread_spinx_destroy (mythread_spinx_t *m) { pthread_spin_destroy(m) ;} /**/
135 extern void mythread_spinx_lock (mythread_spinx_t *m) { pthread_spin_lock (m) ;} /**/
136 extern void mythread_spinx_unlock (mythread_spinx_t *m) { pthread_spin_unlock (m) ;} /**/
137 #else
138 extern void mythread_spinx_initcxx . . $ mythread_spinx_init(4f83bfebf4bb9c8b). (mythread_spinx_tcxx . . $ mythread_spinx_t# *m) { pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa). (m,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);} /**/
139 extern void mythread_spinx_destroycxx . . $ mythread_spinx_destroy(4f83bfebf4bb9c8b). (mythread_spinx_tcxx . . $ mythread_spinx_t# *m) { pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9).(m) ;} /**/
140 extern void mythread_spinx_lockcxx . . $ mythread_spinx_lock(4f83bfebf4bb9c8b). (mythread_spinx_tcxx . . $ mythread_spinx_t# *m) { pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9). (m) ;} /**/
141 extern void mythread_spinx_unlockcxx . . $ mythread_spinx_unlock(4f83bfebf4bb9c8b). (mythread_spinx_tcxx . . $ mythread_spinx_t# *m) { pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9). (m) ;} /**/
142 #endif
143
144 /* semaphores */
145 extern int /* boolean */
146 mysem_initcxx . . $ mysem_init(b34cd7d0155a4ca6). (mysem_tcxx . . $ mysem_t# *sem, unsigned int value)
147 { return -1 != sem_initcxx . . $ sem_init(43542eaff42295b0). (sem, 0 /*not shared with processes*/, value);}
148
149 extern int /* boolean */
150 mysem_waitcxx . . $ mysem_wait(2e1de0073772a87a). (mysem_tcxx . . $ mysem_t# *sem)
151 { return 0 == sem_waitcxx . . $ sem_wait(2e1de0073772a87a). (sem);}
152
153 extern int /* boolean */
154 mysem_postcxx . . $ mysem_post(2e1de0073772a87a). (mysem_tcxx . . $ mysem_t# *sem)
155 { return 0 == sem_postcxx . . $ sem_post(2e1de0073772a87a). (sem);}
156
157 extern int /* boolean */
158 mysem_destroycxx . . $ mysem_destroy(2e1de0073772a87a). (mysem_tcxx . . $ mysem_t# *sem)
159 { return 0 == sem_destroycxx . . $ sem_destroy(2e1de0073772a87a). (sem);}
160
161 /*
162 |
163 | NT_THREADS
164 |
165 \*-------------------------*/
166 #elif defined(NT_THREADS)
167
168 #define WIN32_LEAN_AND_MEAN
169 #include <windows.h>
170 #include <process.h>
171
172 extern int /* boolean */
173 mythread_create (/*@out@*/ mythread_t *thread, routine_t start_routine, void *arg, /*@out@*/ int *ret_error)
174 {
175 static unsigned int thread_id;
176 mythread_t t;
177 int /* boolean */ is_ok;
178
179 t = (mythread_t) _beginthreadex (NULL, 0, start_routine, arg, 0, &thread_id );
180 is_ok = (t != 0);
181 *thread = t;
182 *ret_error = is_ok? 0: errno;
183 return is_ok;
184 }
185
186 extern int /* boolean */
187 mythread_join (mythread_t thread)
188 {
189 unsigned long int ret;
190 ret = WaitForSingleObject (thread, INFINITE);
191 CloseHandle(thread);
192 return ret != WAIT_FAILED;
193 }
194
195 extern void
196 mythread_exit (void)
197 {
198 return;
199 }
200
201 extern const char *
202 mythread_create_error (int err)
203 {
204 const char *s;
205 switch (err) {
206 case 0 : s = "Success"; break;
207 case EAGAIN: s = "EAGAIN" ; break;
208 case EINVAL: s = "EINVAL" ; break;
209 case EPERM : s = "EPERM" ; break;
210 default : s = "Unknown error"; break;
211 }
212 return s;
213 }
214
215 extern void mythread_mutex_init (mythread_mutex_t *m) { *m = CreateMutex(0, FALSE, 0) ;}
216 extern void mythread_mutex_destroy (mythread_mutex_t *m) { CloseHandle(*m) ;}
217 extern void mythread_mutex_lock (mythread_mutex_t *m) { WaitForSingleObject(*m, INFINITE) ;}
218 extern void mythread_mutex_unlock (mythread_mutex_t *m) { ReleaseMutex(*m) ;}
219
220 extern void mythread_spinx_init (mythread_spinx_t *m) { InitializeCriticalSection(m) ;} /**/
221 extern void mythread_spinx_destroy (mythread_spinx_t *m) { DeleteCriticalSection(m) ;} /**/
222 extern void mythread_spinx_lock (mythread_spinx_t *m) { EnterCriticalSection (m) ;} /**/
223 extern void mythread_spinx_unlock (mythread_spinx_t *m) { LeaveCriticalSection (m) ;} /**/
224
225 /* semaphores */
226 extern int /* boolean */
227 mysem_init (mysem_t *sem, unsigned int value)
228 {
229 mysem_t h =
230 CreateSemaphore(
231 NULL, /* cannot be inherited */
232 (LONG)value,/* Initial Count */
233 256, /* Maximum Count */
234 NULL /* Name --> NULL, not shared among threads */
235 );
236
237 if (h != NULL) *sem = h;
238
239 return h != NULL;
240 }
241
242 extern int /* boolean */
243 mysem_wait (mysem_t *sem)
244 {
245 HANDLE h = *sem;
246 return WAIT_FAILED != WaitForSingleObject (h, INFINITE);
247 }
248
249 extern int /* boolean */
250 mysem_post (mysem_t *sem)
251 {
252 HANDLE h = *sem;
253 return 0 != ReleaseSemaphore(h, 1, NULL);
254 }
255
256 extern int /* boolean */
257 mysem_destroy (mysem_t *sem)
258 {
259 return 0 != CloseHandle( *sem);
260 }
261
262 /**** THREADS ****************************************************************************/
263 #else
264 #error Definition of threads not present
265 #endif
266
267 /* MULTI_THREADED_INTERFACE */
268 #endif
269
270
271
272
273
274