3 * Copyright (c) 2002-2012 Apple Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation files
7 * (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
20 * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Except as contained in this notice, the name(s) of the above
26 * copyright holders shall not be used in advertising or otherwise to
27 * promote the sale, use or other dealings in this Software without
28 * prior written authorization.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
40 #define CELL_NEW(f, d) X_PFX(list_prepend) ((x_list *)(f), (d))
41 #define CELL_FREE(c) X_PFX(list_free_1) (c)
42 #define CELL_FUN(c) ((x_hook_function *)((c)->next))
43 #define CELL_DATA(c) ((c)->data)
46 X_PFX(hook_add
) (x_list
* lst
, x_hook_function
* fun
, void *data
) {
47 return X_PFX(list_prepend
) (lst
, CELL_NEW(fun
, data
));
51 X_PFX(hook_remove
) (x_list
* lst
, x_hook_function
* fun
, void *data
) {
53 x_list
*to_delete
= NULL
;
55 for (node
= lst
; node
!= NULL
; node
= node
->next
) {
57 if (CELL_FUN(cell
) == fun
&& CELL_DATA(cell
) == data
)
58 to_delete
= X_PFX(list_prepend
) (to_delete
, cell
);
61 for (node
= to_delete
; node
!= NULL
; node
= node
->next
) {
63 lst
= X_PFX(list_remove
) (lst
, cell
);
67 X_PFX(list_free
) (to_delete
);
72 X_PFX(hook_run
) (x_list
* lst
, void *arg
) {
78 for (node
= lst
; node
!= NULL
; node
= node
->next
) {
79 x_list
*cell
= node
->data
;
81 x_hook_function
*fun
= CELL_FUN(cell
);
82 void *data
= CELL_DATA(cell
);
89 X_PFX(hook_free
) (x_list
* lst
) {
92 for (node
= lst
; node
!= NULL
; node
= node
->next
) {
93 CELL_FREE(node
->data
);
96 X_PFX(list_free
) (lst
);