forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbd5132d
committed
Introduce atomic read/write functions with full barrier semantics.
Writing correct code using atomic variables is often difficult dueto the memory barrier semantics (or lack thereof) of the underlyingoperations. This commit introduces atomic read/write functionswith full barrier semantics to ease this cognitive load. Forexample, some spinlocks protect a single value, and these newfunctions make it easy to convert the value to an atomic variable(thus eliminating the need for the spinlock) without modifying thebarrier semantics previously provided by the spinlock. Since thesefunctions may be less performant than the other atomic reads andwrites, they are not suitable for every use-case. However, using asingle atomic operation with full barrier semantics may be moreperformant in cases where a separate explicit barrier wouldotherwise be required.The base implementations for these new functions are atomicexchanges (for writes) and atomic fetch/adds with 0 (for reads).These implementations can be overwritten with better architecture-specific versions as they are discovered.This commit leaves converting existing code to use these newfunctions as a future exercise.Reviewed-by: Andres Freund, Yong Li, Jeff DavisDiscussion:https://postgr.es/m/20231110205128.GB1315705%40nathanxps131 parent5f2e179 commitbd5132d
2 files changed
+94
-0
lines changedLines changed: 58 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
237 | 237 |
| |
238 | 238 |
| |
239 | 239 |
| |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
240 | 260 |
| |
241 | 261 |
| |
242 | 262 |
| |
| |||
274 | 294 |
| |
275 | 295 |
| |
276 | 296 |
| |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
277 | 317 |
| |
278 | 318 |
| |
279 | 319 |
| |
| |||
427 | 467 |
| |
428 | 468 |
| |
429 | 469 |
| |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
430 | 479 |
| |
431 | 480 |
| |
432 | 481 |
| |
| |||
436 | 485 |
| |
437 | 486 |
| |
438 | 487 |
| |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
439 | 497 |
| |
440 | 498 |
| |
441 | 499 |
| |
|
Lines changed: 36 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
243 | 243 |
| |
244 | 244 |
| |
245 | 245 |
| |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
246 | 264 |
| |
247 | 265 |
| |
248 | 266 |
| |
| |||
399 | 417 |
| |
400 | 418 |
| |
401 | 419 |
| |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + |
0 commit comments
Comments
(0)