sx.9 (c5e7e03a143ca33bf523994e766d62892780abcf) | sx.9 (d55229b72ecc97075f1afcd976f8e0c1cd0d662b) |
---|---|
1.\" 2.\" Copyright (C) 2001 Jason Evans <jasone@FreeBSD.org>. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice(s), this list of conditions and the following disclaimer as --- 25 unchanged lines hidden (view full) --- 34.Nm sx_init , 35.Nm sx_destroy , 36.Nm sx_slock , 37.Nm sx_xlock , 38.Nm sx_try_slock , 39.Nm sx_try_xlock , 40.Nm sx_sunlock , 41.Nm sx_xunlock | 1.\" 2.\" Copyright (C) 2001 Jason Evans <jasone@FreeBSD.org>. All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice(s), this list of conditions and the following disclaimer as --- 25 unchanged lines hidden (view full) --- 34.Nm sx_init , 35.Nm sx_destroy , 36.Nm sx_slock , 37.Nm sx_xlock , 38.Nm sx_try_slock , 39.Nm sx_try_xlock , 40.Nm sx_sunlock , 41.Nm sx_xunlock |
42.Nm sx_try_upgrade 43.Nm sx_downgrade |
|
42.Nd kernel shared/exclusive lock 43.Sh SYNOPSIS 44.Fd #include <sys/types.h> 45.Fd #include <sys/lock.h> 46.Fd #include <sys/mutex.h> 47.Fd #include <sys/sx.h> 48.Ft void 49.Fn sx_init "struct sx *sx" "const char *description" --- 6 unchanged lines hidden (view full) --- 56.Ft int 57.Fn sx_try_slock "struct sx *sx" 58.Ft int 59.Fn sx_try_xlock "struct sx *sx" 60.Ft void 61.Fn sx_sunlock "struct sx *sx" 62.Ft void 63.Fn sx_xunlock "struct sx *sx" | 44.Nd kernel shared/exclusive lock 45.Sh SYNOPSIS 46.Fd #include <sys/types.h> 47.Fd #include <sys/lock.h> 48.Fd #include <sys/mutex.h> 49.Fd #include <sys/sx.h> 50.Ft void 51.Fn sx_init "struct sx *sx" "const char *description" --- 6 unchanged lines hidden (view full) --- 58.Ft int 59.Fn sx_try_slock "struct sx *sx" 60.Ft int 61.Fn sx_try_xlock "struct sx *sx" 62.Ft void 63.Fn sx_sunlock "struct sx *sx" 64.Ft void 65.Fn sx_xunlock "struct sx *sx" |
66.Ft int 67.Fn sx_try_upgrade "struct sx *sx" 68.Ft void 69.Fn sx_downgrade "struct sx *sx" |
|
64.Sh DESCRIPTION 65Shared/exclusive locks are used to protect data that are read far more often 66than they are written. 67Mutexes are inherently more efficient than shared/exclusive locks, so 68shared/exclusive locks should be used prudently. 69.Pp 70Shared/exclusive locks are created with 71.Fn sx_init , --- 14 unchanged lines hidden (view full) --- 86and 87.Fn sx_sunlock . 88Threads acquire and release an exclusive lock by calling 89.Fn sx_xlock 90or 91.Fn sx_try_xlock 92and 93.Fn sx_xunlock . | 70.Sh DESCRIPTION 71Shared/exclusive locks are used to protect data that are read far more often 72than they are written. 73Mutexes are inherently more efficient than shared/exclusive locks, so 74shared/exclusive locks should be used prudently. 75.Pp 76Shared/exclusive locks are created with 77.Fn sx_init , --- 14 unchanged lines hidden (view full) --- 92and 93.Fn sx_sunlock . 94Threads acquire and release an exclusive lock by calling 95.Fn sx_xlock 96or 97.Fn sx_try_xlock 98and 99.Fn sx_xunlock . |
100A thread can attempt to upgrade a currently owned shared lock to an exclusive 101lock by calling 102.Fn sx_try_upgrade . 103A thread that owns an exclusive lock can downgrade it to a shared lock by 104calling 105.Fn sx_downgrade . |
|
94.Pp 95.Fn sx_try_slock 96and 97.Fn sx_try_xlock 98will return 0 if the shared/exclusive lock cannot be acquired immediately; 99otherwise the shared/exclusive lock will be acquired and a non-zero value will 100be returned. 101.Pp | 106.Pp 107.Fn sx_try_slock 108and 109.Fn sx_try_xlock 110will return 0 if the shared/exclusive lock cannot be acquired immediately; 111otherwise the shared/exclusive lock will be acquired and a non-zero value will 112be returned. 113.Pp |
114.Fn sx_try_upgrade 115will return 0 if the shared lock cannot be upgraded to an exclusive lock 116immediately; otherwise the exclusive lock will be acquired and a non-zero value 117will be returned. 118.Pp |
|
102A thread may not own a shared lock and an exclusive lock simultaneously; 103attempting to do so will result in deadlock. 104.Sh SEE ALSO 105.Xr mutex 9 | 119A thread may not own a shared lock and an exclusive lock simultaneously; 120attempting to do so will result in deadlock. 121.Sh SEE ALSO 122.Xr mutex 9 |