mesa3dgl.library: add required CXX flags
[AROS.git] / workbench / libs / mesa / src / aros / emul_arosc.c
blob1ae09a4a03cc1277996ddd4b5b36efd841033114
1 /*
2 Copyright 2009-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
7 #include <proto/timer.h>
9 #define DEBUG 0
10 #include <aros/debug.h>
12 #include <stdlib.h>
13 #include <unistd.h>
15 #define IMPLEMENT() bug("------IMPLEMENT(%s)\n", __func__)
17 /*
18 The purpose of this file is to provide implementation for C functions part
19 of arosnixc.library in code where one does not want to use this library.
22 struct timezone;
24 int gettimeofday (struct timeval * tv,struct timezone * tz)
26 struct MsgPort * timerport = CreateMsgPort();
27 struct timerequest * timereq = (struct timerequest *)CreateIORequest(timerport, sizeof(*timereq));
30 if (timereq)
32 if (OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)timereq, 0) == 0)
34 #define TimerBase ((struct Device *)timereq->tr_node.io_Device)
36 GetSysTime(tv);
38 #undef TimerBase
40 CloseDevice((struct IORequest *)timereq);
44 DeleteIORequest((struct IORequest *)timereq);
45 DeleteMsgPort(timerport);
47 return 0;
50 int usleep (useconds_t usec)
52 IMPLEMENT();
53 return 0;
57 This implementation of atexit is different than the definition of atexit
58 function due to how libraries work in AROS.
60 Under Linux, when an .so file is used by an application, the library's code
61 is being shared but the library's data (global, static variables) are COPIED for
62 each process. Then, an atexit call inside .so will only operate on COPY of data
63 and thus can for example free memory allocated by one process without
64 influencing other processes.
66 Under AROS, when a .library file is used by an application, library code AND
67 library data is shared. This means, an atexit call inside .library which was
68 initially coded under Linux cannot be executed when process is finishing
69 (for example at CloseLibrary) because such call will most likely free shared
70 data which will make other processes crash. The best approximation of atexit
71 in case of .library is to call the atexit functions at library expunge/exit.
73 TODO: Check atexit() usage and determine best time to call atexit registered
74 functions.
77 static struct exit_list {
78 struct exit_list *next;
79 void (*func)(void);
80 } *exit_list = NULL;
82 int atexit(void (*function)(void))
84 struct exit_list *el;
86 el = malloc(sizeof(*el));
87 if (el == NULL)
88 return -1;
90 el->next = exit_list;
91 el->func = function;
92 exit_list = el;
94 return 0;
97 void __exit_emul(void)
99 while (exit_list) {
100 struct exit_list *el = exit_list->next;
102 exit_list->func();
103 free(exit_list);
104 exit_list = el;
108 ADD2EXIT(__exit_emul, 0);