1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      Some definitions for internal use by the Unix library code.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 #ifndef AINTUNIX_H
19 #define AINTUNIX_H
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef ALLEGRO_HAVE_LIBPTHREAD
26    /* Synchronization routines using POSIX threads */
27    AL_FUNC(void *, _unix_create_mutex, (void));
28    AL_FUNC(void, _unix_destroy_mutex, (void *handle));
29    AL_FUNC(void, _unix_lock_mutex, (void *handle));
30    AL_FUNC(void, _unix_unlock_mutex, (void *handle));
31 #else
32    /* Asynchronous event processing with SIGALRM */
33    AL_FUNC(void, _sigalrm_request_abort, (void));
34    AL_FUNCPTR(void, _sigalrm_timer_interrupt_handler, (unsigned long interval));
35 #endif
36 
37    /* Macros to enable and disable interrupts */
38    #define DISABLE() _unix_bg_man->disable_interrupts()
39    #define ENABLE()  _unix_bg_man->enable_interrupts()
40 
41 
42    /* Helper for locating config files */
43    AL_FUNC(int, _unix_find_resource, (char *dest, AL_CONST char *resource, int size));
44 
45 
46    /* Generic system driver entry for finding the executable */
47    AL_FUNC(void, _unix_get_executable_name, (char *output, int size));
48 
49 
50    /* Helper for setting os_type */
51    AL_FUNC(void, _unix_read_os_type, (void));
52 
53 
54    /* Helper for yield CPU */
55    AL_FUNC(void, _unix_yield_timeslice, (void));
56 
57 
58    /* Unix rest function */
59    AL_FUNC(void, _unix_rest, (unsigned int, AL_METHOD(void, callback, (void))));
60 
61 
62    /* Module support */
63    AL_FUNC(void, _unix_load_modules, (int system_driver_id));
64    AL_FUNC(void, _unix_unload_modules, (void));
65 
66 
67    /* Dynamic driver lists, for modules */
68    AL_VAR(_DRIVER_INFO *, _unix_gfx_driver_list);
69    AL_VAR(_DRIVER_INFO *, _unix_digi_driver_list);
70    AL_VAR(_DRIVER_INFO *, _unix_midi_driver_list);
71    AL_FUNC(void, _unix_driver_lists_init, (void));
72    AL_FUNC(void, _unix_driver_lists_shutdown, (void));
73    AL_FUNC(void, _unix_register_gfx_driver, (int id, GFX_DRIVER *driver, int autodetect, int priority));
74    AL_FUNC(void, _unix_register_digi_driver, (int id, DIGI_DRIVER *driver, int autodetect, int priority));
75    AL_FUNC(void, _unix_register_midi_driver, (int id, MIDI_DRIVER *driver, int autodetect, int priority));
76 
77    /* Get size of a memory page in bytes */
78    AL_FUNC(size_t, _unix_get_page_size, (void));
79 
80 
81 #ifdef ALLEGRO_WITH_XWINDOWS
82    AL_FUNCPTR(void, _xwin_keyboard_interrupt, (int pressed, int code));
83    AL_FUNCPTR(void, _xwin_keyboard_focused, (int focused, int state));
84    AL_FUNCPTR(void, _xwin_mouse_interrupt, (int x, int y, int z, int w, int buttons));
85    AL_FUNCPTR(void, _xwin_timer_interrupt, (unsigned long interval));
86 
87    AL_ARRAY(_DRIVER_INFO, _xwin_gfx_driver_list);
88    AL_ARRAY(_DRIVER_INFO, _xwin_keyboard_driver_list);
89    AL_ARRAY(_DRIVER_INFO, _xwin_mouse_driver_list);
90    AL_ARRAY(_DRIVER_INFO, _xwin_timer_driver_list);
91 
92    AL_FUNC(void, _xwin_handle_input, (void));
93    AL_FUNC(void, _xwin_private_handle_input, (void));
94 
95 #ifndef ALLEGRO_MULTITHREADED
96 
97    AL_VAR(int, _xwin_missed_input);
98 
99    #define XLOCK()                              \
100       do {                                      \
101          _xwin.lock_count++;                    \
102       } while (0)
103 
104    #define XUNLOCK()                            \
105       do {                                      \
106          if (_xwin.lock_count == 1) {           \
107             while(_xwin_missed_input) {         \
108                if (_xwin_input_handler)         \
109                   _xwin_input_handler();        \
110                else                             \
111                   _xwin_private_handle_input(); \
112                --_xwin_missed_input;            \
113             }                                   \
114          }                                      \
115          _xwin.lock_count--;                    \
116       } while (0)
117 
118 #else
119 
120    #define XLOCK()                              \
121       do {                                      \
122          if (_xwin.mutex)                       \
123             _unix_lock_mutex (_xwin.mutex);     \
124          _xwin.lock_count++;                    \
125       } while (0)
126 
127    #define XUNLOCK()                            \
128       do {                                      \
129          if (_xwin.mutex)                       \
130             _unix_unlock_mutex (_xwin.mutex);   \
131          _xwin.lock_count--;                    \
132       } while (0)
133 
134 #endif
135 
136 #endif
137 
138 
139 #ifdef ALLEGRO_WITH_OSSDIGI
140    /* So the setup program can read what we detected */
141    AL_VAR(int, _oss_fragsize);
142    AL_VAR(int, _oss_numfrags);
143 #endif
144 
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 
151 #ifdef ALLEGRO_LINUX
152    #include "aintlnx.h"
153 #endif
154 
155 
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159 
160 /* Typedef for background functions, called frequently in the background.
161  * `threaded' is nonzero if the function is being called from a thread.
162  */
163 typedef void (*bg_func) (int threaded);
164 
165 /* Background function manager -- responsible for calling background
166  * functions.  `int' methods return -1 on failure, 0 on success. */
167 struct bg_manager
168 {
169    int multi_threaded;
170    int (*init) (void);
171    void (*exit) (void);
172    int (*register_func) (bg_func f);
173    int (*unregister_func) (bg_func f);
174    void (*enable_interrupts) (void);
175    void (*disable_interrupts) (void);
176    int (*interrupts_disabled) (void);
177 };
178 
179 extern struct bg_manager _bg_man_pthreads;
180 extern struct bg_manager _bg_man_sigalrm;
181 
182 extern struct bg_manager *_unix_bg_man;
183 
184 extern _DRIVER_INFO _linux_joystick_driver_list[]; /* also in aintlnx.h */
185 
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif /* ifndef AINTUNIX_H */
192