kernel - Add lock canceling features
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 22 Nov 2014 08:10:19 +0000 (00:10 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 22 Nov 2014 08:10:19 +0000 (00:10 -0800)
commit4e3d9e11e7d9e81412b5db414ebe9054f555487d
tree1ec024d613f133070e2392747b579c1888aab9c2
parent5e700a85e9a78dd74defb3e598b285cf087018ef
kernel - Add lock canceling features

* The current (typically exclusive) lock holder can enable cancel mode
  by executing lockmgr(lk, LK_CANCEL_BEG, 0).  This call always succeeds.
  The lock state is not otherwise affected.

  Any current threads blocked on the lock or any future thread which
  attempts to gain the lock, who also specify the LK_CANCELABLE flag,
  will be canceled as long as cancel mode is active and their operation
  will return ENOLCK.

  NOTE! Threads which do not specify LK_CANCELABLE are not affected by
cancel mode and their blocking locks will block normally.

  WARNING!  Cancel mode is not stackable.  The system will panic if you
  enable cancel mode on a lock where it is already enabled.

* The current (typically exclusive) lock holder can terminate cancel mode
  by executing lockmgr(lk, LK_CANCEL_END, 0).  This call always succeeds.
  Once canceled, any other threads that would block on the lock and specify
  the LK_CANCELABLE flag will block normally and not be canceled.

  The current lock holder can also terminate cancel mode by simply releasing
  the last lock with LK_RELEASE.  That is, a release where the lock count
  returns to 0.

* Lock canceling is an optional feature.  Your lock cannot be canceled unless
  you specify LK_CANCELABLE.
sys/kern/kern_lock.c
sys/kern/kern_sysctl.c
sys/sys/lock.h