forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbe7b284
committed
Make the different Unix-y semaphore implementations ABI-compatible.
Previously, the "sem" field of PGPROC varied in size depending on whichkernel semaphore API we were using. That was okay as long as there wasonly one likely choice per platform, but in the wake of commitecb0d20,that assumption seems rather shaky. It doesn't seem out of the questionanymore that an extension compiled against one API choice might be loadedinto a postmaster built with another choice. Moreover, this prevents anypossibility of selecting the semaphore API at postmaster startup, whichmight be something we want to do in future.Hence, change PGPROC.sem to be PGSemaphore (i.e. a pointer) for all Unixsemaphore APIs, and turn the pointed-to data into an opaque struct whosecontents are only known within the responsible modules.For the SysV and unnamed-POSIX APIs, the pointed-to data has to beallocated elsewhere in shared memory, which takes a little bit ofrejiggering of the InitShmemAllocation code sequence. (I invented aShmemAllocUnlocked() function to make that a little cleaner than it usedto be. That function is not meant for any uses other than the ones ithas now, but it beats having InitShmemAllocation() know explicitly aboutallocation of space for semaphores and spinlocks.) This change means anextra indirection to access the semaphore data, but since we only touchthat when blocking or awakening a process, there shouldn't be anymeaningful performance penalty. Moreover, at least for the unnamed-POSIXcase on Linux, the sem_t type is quite a bit wider than a pointer, so thisreduces sizeof(PGPROC) which seems like a good thing.For the named-POSIX API, there's effectively no change: the PGPROC.semfield was and still is a pointer to something returned by sem_open() inthe postmaster's memory space. Document and check the pre-existinglimitation that this case can't work in EXEC_BACKEND mode.It did not seem worth unifying the Windows semaphore ABI with the Unixcases, since there's no likelihood of needing ABI compatibility much lessruntime switching across those cases. However, we can simplify the Windowscode a bit if we define PGSemaphore as being directly a HANDLE, rather thanpointer to HANDLE, so let's do that while we're here. (This also ends upbeing no change in what's physically stored in PGPROC.sem. We're justmoving the HANDLE fetch from callees to callers.)It would take a bunch of additional code shuffling to get to the point ofactually choosing a semaphore API at postmaster start, but the effectsof that would now be localized in the port/XXX_sema.c files, so it seemslike fit material for a separate patch. The need for it is unproven asyet, anyhow, whereas the ABI risk to extensions seems real enough.Discussion:https://postgr.es/m/4029.1481413370@sss.pgh.pa.us1 parent06e1848 commitbe7b284
File tree
14 files changed
+268
-123
lines changed- src
- backend
- port
- postmaster
- storage
- ipc
- lmgr
- include/storage
14 files changed
+268
-123
lines changedLines changed: 81 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6 | 6 |
| |
7 | 7 |
| |
8 | 8 |
| |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 |
| |
10 | 18 |
| |
11 | 19 |
| |
| |||
18 | 26 |
| |
19 | 27 |
| |
20 | 28 |
| |
| 29 | + | |
21 | 30 |
| |
22 | 31 |
| |
23 | 32 |
| |
24 | 33 |
| |
25 | 34 |
| |
26 | 35 |
| |
| 36 | + | |
27 | 37 |
| |
28 | 38 |
| |
29 |
| - | |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
35 | 42 |
| |
36 | 43 |
| |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
37 | 51 |
| |
38 | 52 |
| |
39 | 53 |
| |
| 54 | + | |
40 | 55 |
| |
| 56 | + | |
| 57 | + | |
| 58 | + | |
41 | 59 |
| |
42 |
| - | |
| 60 | + | |
43 | 61 |
| |
44 | 62 |
| |
45 | 63 |
| |
| |||
133 | 151 |
| |
134 | 152 |
| |
135 | 153 |
| |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
136 | 169 |
| |
137 | 170 |
| |
138 | 171 |
| |
| |||
147 | 180 |
| |
148 | 181 |
| |
149 | 182 |
| |
150 |
| - | |
151 |
| - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
152 | 191 |
| |
153 | 192 |
| |
154 | 193 |
| |
155 | 194 |
| |
| 195 | + | |
156 | 196 |
| |
157 | 197 |
| |
158 | 198 |
| |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
159 | 210 |
| |
160 | 211 |
| |
161 | 212 |
| |
| |||
173 | 224 |
| |
174 | 225 |
| |
175 | 226 |
| |
| 227 | + | |
176 | 228 |
| |
177 | 229 |
| |
178 | 230 |
| |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
179 | 237 |
| |
180 | 238 |
| |
181 | 239 |
| |
182 | 240 |
| |
183 | 241 |
| |
184 |
| - | |
| 242 | + | |
185 | 243 |
| |
186 |
| - | |
187 |
| - | |
| 244 | + | |
| 245 | + | |
188 | 246 |
| |
| 247 | + | |
189 | 248 |
| |
190 | 249 |
| |
191 | 250 |
| |
| |||
195 | 254 |
| |
196 | 255 |
| |
197 | 256 |
| |
198 |
| - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
199 | 261 |
| |
200 |
| - | |
201 |
| - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
202 | 265 |
| |
203 | 266 |
| |
204 |
| - | |
205 |
| - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
206 | 270 |
| |
207 | 271 |
| |
208 | 272 |
| |
|
Lines changed: 46 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
| 30 | + | |
30 | 31 |
| |
31 | 32 |
| |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
32 | 39 |
| |
33 | 40 |
| |
34 | 41 |
| |
| |||
54 | 61 |
| |
55 | 62 |
| |
56 | 63 |
| |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 |
| |
58 | 68 |
| |
59 | 69 |
| |
| |||
273 | 283 |
| |
274 | 284 |
| |
275 | 285 |
| |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
276 | 295 |
| |
277 | 296 |
| |
278 | 297 |
| |
| |||
287 | 306 |
| |
288 | 307 |
| |
289 | 308 |
| |
290 |
| - | |
291 |
| - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
292 | 315 |
| |
293 | 316 |
| |
294 | 317 |
| |
295 | 318 |
| |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
296 | 329 |
| |
297 | 330 |
| |
298 | 331 |
| |
| |||
323 | 356 |
| |
324 | 357 |
| |
325 | 358 |
| |
326 |
| - | |
| 359 | + | |
327 | 360 |
| |
328 |
| - | |
329 |
| - | |
| 361 | + | |
| 362 | + | |
330 | 363 |
| |
| 364 | + | |
| 365 | + | |
331 | 366 |
| |
332 | 367 |
| |
333 | 368 |
| |
| |||
340 | 375 |
| |
341 | 376 |
| |
342 | 377 |
| |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
343 | 382 |
| |
344 | 383 |
| |
345 | 384 |
| |
346 | 385 |
| |
347 | 386 |
| |
| 387 | + | |
| 388 | + | |
348 | 389 |
| |
349 | 390 |
| |
350 | 391 |
| |
|
Lines changed: 27 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
26 | 37 |
| |
27 | 38 |
| |
28 | 39 |
| |
| |||
62 | 73 |
| |
63 | 74 |
| |
64 | 75 |
| |
65 |
| - | |
| 76 | + | |
66 | 77 |
| |
67 |
| - | |
68 |
| - | |
| 78 | + | |
| 79 | + | |
69 | 80 |
| |
70 | 81 |
| |
71 | 82 |
| |
| |||
86 | 97 |
| |
87 | 98 |
| |
88 | 99 |
| |
89 |
| - | |
90 | 100 |
| |
91 | 101 |
| |
92 | 102 |
| |
93 | 103 |
| |
94 |
| - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
95 | 108 |
| |
96 | 109 |
| |
97 | 110 |
| |
| |||
106 | 119 |
| |
107 | 120 |
| |
108 | 121 |
| |
109 |
| - | |
| 122 | + | |
| 123 | + | |
110 | 124 |
| |
111 | 125 |
| |
112 | 126 |
| |
| |||
127 | 141 |
| |
128 | 142 |
| |
129 | 143 |
| |
130 |
| - | |
| 144 | + | |
131 | 145 |
| |
132 | 146 |
| |
133 | 147 |
| |
| |||
182 | 196 |
| |
183 | 197 |
| |
184 | 198 |
| |
185 |
| - | |
| 199 | + | |
186 | 200 |
| |
187 |
| - | |
| 201 | + | |
| 202 | + | |
188 | 203 |
| |
189 | 204 |
| |
190 | 205 |
| |
| |||
197 | 212 |
| |
198 | 213 |
| |
199 | 214 |
| |
200 |
| - | |
| 215 | + | |
201 | 216 |
| |
202 | 217 |
| |
203 | 218 |
| |
| |||
213 | 228 |
| |
214 | 229 |
| |
215 | 230 |
| |
216 |
| - | |
| 231 | + | |
| 232 | + | |
217 | 233 |
| |
218 | 234 |
| |
219 | 235 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
484 | 484 |
| |
485 | 485 |
| |
486 | 486 |
| |
487 |
| - | |
| 487 | + | |
488 | 488 |
| |
489 | 489 |
| |
490 | 490 |
| |
|
0 commit comments
Comments
(0)