* _vm_map_lock_upgrade: [ internal use only ] * * Tries to upgrade a read (shared) lock on the specified map to a write * (exclusive) lock. Returns the value "0" if the upgrade succeeds and a * non-zero value if the upgrade fails. If the upgrade fails, the map is * returned without a read or write lock held. * * Requires that the map be read locked. */
| 766 | * Requires that the map be read locked. |
| 767 | */ |
| 768 | int |
| 769 | _vm_map_lock_upgrade(vm_map_t map, const char *file, int line) |
| 770 | { |
| 771 | unsigned int last_timestamp; |
| 772 | |
| 773 | if (map->system_map) { |
| 774 | mtx_assert_(&map->system_mtx, MA_OWNED, file, line); |
| 775 | } else { |
| 776 | if (!sx_try_upgrade_(&map->lock, file, line)) { |
| 777 | last_timestamp = map->timestamp; |
| 778 | sx_sunlock_(&map->lock, file, line); |
| 779 | vm_map_process_deferred(); |
| 780 | /* |
| 781 | * If the map's timestamp does not change while the |
| 782 | * map is unlocked, then the upgrade succeeds. |
| 783 | */ |
| 784 | sx_xlock_(&map->lock, file, line); |
| 785 | if (last_timestamp != map->timestamp) { |
| 786 | sx_xunlock_(&map->lock, file, line); |
| 787 | return (1); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | map->timestamp++; |
| 792 | return (0); |
| 793 | } |
| 794 | |
| 795 | void |
| 796 | _vm_map_lock_downgrade(vm_map_t map, const char *file, int line) |
nothing calls this directly
no test coverage detected