]>
Commit | Line | Data |
---|---|---|
fe8ab488 A |
1 | /* |
2 | * Copyright (c) 2012-2013 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _BANK_BANK_INTERNAL_H_ | |
30 | #define _BANK_BANK_INTERNAL_H_ | |
31 | ||
32 | #include <stdint.h> | |
33 | #include <mach/mach_types.h> | |
34 | ||
35 | #ifdef MACH_KERNEL_PRIVATE | |
36 | ||
37 | #include <kern/thread.h> | |
38 | #include <kern/locks.h> | |
39 | #include <kern/queue.h> | |
40 | #include <ipc/ipc_voucher.h> | |
41 | #include <bank/bank_types.h> | |
42 | ||
43 | /* Default value for Voucher Attribute Manager for BANK */ | |
44 | #define BANK_DEFAULT_VALUE NULL | |
45 | typedef mach_voucher_attr_value_handle_t bank_handle_t; | |
46 | ||
47 | #define BANK_TASK 0 | |
48 | #define BANK_ACCOUNT 1 | |
49 | ||
50 | struct bank_element { | |
51 | int be_type; /* Type of element */ | |
52 | int be_refs; /* Ref count */ | |
53 | int be_made; /* Made refs for voucher, Actual ref is also taken for each Made ref */ | |
54 | int32_t be_pid; /* Customer task's pid. */ | |
55 | #if DEVELOPMENT || DEBUG | |
56 | task_t be_task; /* Customer task, do not use it since ref is not taken on task */ | |
57 | #endif | |
58 | }; | |
59 | ||
60 | typedef struct bank_element * bank_element_t; | |
61 | #define BANK_ELEMENT_NULL ((bank_element_t) 0) | |
62 | ||
63 | struct bank_task { | |
64 | struct bank_element bt_elem; /* Bank element */ | |
65 | ledger_t bt_creditcard; /* Ledger of the customer task */ | |
66 | queue_head_t bt_accounts_to_pay; /* List of accounts worked for me and need to pay */ | |
67 | queue_head_t bt_accounts_to_charge; /* List of accounts I did work and need to charge */ | |
68 | decl_lck_mtx_data(, bt_acc_to_pay_lock) /* Lock to protect accounts to pay list */ | |
69 | decl_lck_mtx_data(, bt_acc_to_charge_lock) /* Lock to protect accounts to charge list */ | |
70 | #if DEVELOPMENT || DEBUG | |
71 | queue_chain_t bt_global_elt; /* Element on the global bank task chain */ | |
72 | #endif | |
73 | }; | |
74 | ||
75 | #define bt_type bt_elem.be_type | |
76 | #define bt_refs bt_elem.be_refs | |
77 | #define bt_made bt_elem.be_made | |
78 | #define bt_pid bt_elem.be_pid | |
79 | ||
80 | #if DEVELOPMENT || DEBUG | |
81 | #define bt_task bt_elem.be_task | |
82 | #endif | |
83 | ||
84 | typedef struct bank_task * bank_task_t; | |
85 | #define BANK_TASK_NULL ((bank_task_t) 0) | |
86 | ||
87 | #define bank_task_reference(elem) \ | |
88 | (OSAddAtomic(1, &(elem)->bt_refs)) | |
89 | ||
90 | #define bank_task_release(elem) \ | |
91 | (OSAddAtomic(-1, &(elem)->bt_refs)) | |
92 | ||
93 | #define bank_task_release_num(elem, num) \ | |
94 | (OSAddAtomic(-(num), &(elem)->bt_refs)) | |
95 | ||
96 | #define bank_task_made_reference(elem) \ | |
97 | (OSAddAtomic(1, &(elem)->bt_made)) | |
98 | ||
99 | #define bank_task_made_release(elem) \ | |
100 | (OSAddAtomic(-1, &(elem)->bt_made)) | |
101 | ||
102 | #define bank_task_made_release_num(elem, num) \ | |
103 | (OSAddAtomic(-(num), &(elem)->bt_made)) | |
104 | ||
105 | ||
106 | struct bank_account { | |
107 | struct bank_element ba_elem; /* Bank element */ | |
108 | ledger_t ba_bill; /* Temporary ledger i.e. chit */ | |
109 | bank_task_t ba_merchant; /* Task who worked for me, who will charge me on behalf of */ | |
110 | bank_task_t ba_holder; /* Credit Card task holder */ | |
111 | queue_chain_t ba_next_acc_to_pay; /* Next account I need to pay to */ | |
112 | queue_chain_t ba_next_acc_to_charge; /* Next account I need to charge to */ | |
113 | #if DEVELOPMENT || DEBUG | |
114 | queue_chain_t ba_global_elt; /* Element on the global account chain */ | |
115 | #endif | |
116 | }; | |
117 | ||
118 | #define ba_type ba_elem.be_type | |
119 | #define ba_refs ba_elem.be_refs | |
120 | #define ba_made ba_elem.be_made | |
121 | #define ba_pid ba_elem.be_pid | |
122 | ||
123 | #if DEVELOPMENT || DEBUG | |
124 | #define ba_task ba_elem.be_task | |
125 | #endif | |
126 | ||
127 | typedef struct bank_account * bank_account_t; | |
128 | #define BANK_ACCOUNT_NULL ((bank_account_t) 0) | |
129 | ||
130 | #define bank_account_reference(elem) \ | |
131 | (OSAddAtomic(1, &(elem)->ba_refs)) | |
132 | ||
133 | #define bank_account_release(elem) \ | |
134 | (OSAddAtomic(-1, &(elem)->ba_refs)) | |
135 | ||
136 | #define bank_account_release_num(elem, num) \ | |
137 | (OSAddAtomic(-(num), &(elem)->ba_refs)) | |
138 | ||
139 | #define bank_account_made_reference(elem) \ | |
140 | (OSAddAtomic(1, &(elem)->ba_made)) | |
141 | ||
142 | #define bank_account_made_release(elem) \ | |
143 | (OSAddAtomic(-1, &(elem)->ba_made)) | |
144 | ||
145 | #define bank_account_made_release_num(elem, num) \ | |
146 | (OSAddAtomic(-(num), &(elem)->ba_made)) | |
147 | ||
148 | struct _bank_ledger_indices { | |
149 | int cpu_time; | |
150 | }; | |
151 | ||
152 | extern struct _bank_ledger_indices bank_ledgers; | |
153 | ||
154 | extern void bank_init(void); | |
155 | extern void bank_task_destroy(bank_task_t); | |
156 | extern uint64_t bank_billed_time(bank_task_t bank_task); | |
157 | extern uint64_t bank_serviced_time(bank_task_t bank_task); | |
158 | extern ledger_t bank_get_voucher_ledger(ipc_voucher_t voucher); | |
159 | extern void bank_swap_thread_bank_ledger(thread_t thread, ledger_t ledger); | |
160 | ||
161 | #endif /* MACH_KERNEL_PRIVATE */ | |
162 | #endif /* _BANK_BANK_INTERNAL_H_ */ |