Files
@ d6b9b2ac5869
Branch filter:
Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public-bincomp/vmkernel64/release/core/vmkapi_spinlock.h
d6b9b2ac5869
17.9 KiB
text/x-chdr
ESXi-5.5-U2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | /* **********************************************************
* Copyright 2010-2012 VMware, Inc. All rights reserved.
* **********************************************************/
/*
* @VMKAPIMOD_LICENSE@
*/
/*
******************************************************************************
* Spin Locks */ /**
*
* \addtogroup Core
* @{
* \defgroup SpinLocks Spin Locks
*
* \par Lock acquisition behavior for lock types VMK_SPINLOCK and
* VMK_SPINLOCK_RW:\n
* In the case of lock contention, locks of types VMK_SPINLOCK and
* VMK_SPINLOCK_RW will spin for a short amount of time. If the lock
* acquisition does not succeed during the spinning phase, the lock acquisition
* function will block.
*
* @{
*
******************************************************************************
*/
#ifndef _VMKAPI_SPINLOCKS_H_
#define _VMKAPI_SPINLOCKS_H_
/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */
/** Invalid lock handle */
#define VMK_LOCK_INVALID ((vmk_Lock)-1)
/** Invalid lock rank */
#define VMK_SPINLOCK_RANK_INVALID (0)
/** Lock rank for unranked locks */
#define VMK_SPINLOCK_UNRANKED (0xFFFF)
/**
* \brief Lock Handle
*/
typedef struct vmk_LockInt *vmk_Lock;
/**
* \brief Spinlock Types
* @{
*/
typedef vmk_uint8 vmk_SpinlockType;
/** Spinlock usable from a world context */
#define VMK_SPINLOCK (1)
/** RW Spinlock usable from a world context */
#define VMK_SPINLOCK_RW (3)
/** @} */
/**
* \brief Rank for locks
*/
typedef vmk_uint16 vmk_LockRank;
/**
* \brief Spinlock Creation Properties
*/
typedef struct vmk_SpinlockCreateProps {
/** Module ID for which the spinlock is created */
vmk_ModuleID moduleID;
/** Heap from which the spinlock will be allocated */
vmk_HeapID heapID;
/** Name of the spinlock */
vmk_Name name;
/** Type of the lock */
vmk_SpinlockType type;
/**
* Domain in which the spinlock will be rank checked in. If domain is set to
* invalid then the rank also has to be set to invalid and vice versa.
*/
vmk_LockDomainID domain;
/** Rank of the spinlock. May only be set if domain is set to a valid value. */
vmk_LockRank rank;
} vmk_SpinlockCreateProps;
/*
******************************************************************************
* vmk_SpinlockCreate -- */ /**
*
* \brief Allocate and initialize a spinlock
*
* Creates a new spinlock initializes it.
*
* \param[in] props Pointer to a valid vmk_SpinlockCreateProps struct
* \param[out] lock Pointer to the initialized spinlock
*
* \retval VMK_OK on success, error code otherwise
*
* \note Spinlocks can only be created from a world context
* \note This function will not block
*
******************************************************************************
*/
VMK_ReturnStatus
vmk_SpinlockCreate(vmk_SpinlockCreateProps *props,
vmk_Lock *lock);
/*
******************************************************************************
* vmk_SpinlockDestroy -- */ /**
*
* \brief Destroy a spinlock previously created with vmk_SpinlockCreate
*
* Destroy the given lock and free the allocated memory
*
* \param[in] lock Pointer to the spinlock
*
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockDestroy(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockAllocSize */ /**
*
* \brief Size of an allocated spinlock of the specified type
*
* \result Allocation size
*
* \note This function will not block
*
******************************************************************************
*/
vmk_ByteCountSmall
vmk_SpinlockAllocSize(vmk_SpinlockType type);
/*
******************************************************************************
* vmk_SpinlockLock -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK
*
* \param[in,out] lock Spinlock to be acquired
*
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
* \note The lock acquisition might not succeed if the world receives a
* VMK_DEATH_PENDING signal while it is waiting for the lock.
*
* \retval VMK_OK World acquired the lock.
* \retval VMK_DEATH_PENDING World blocked during the lock acquisition
* and awoken because the world is dying and
* being reaped by the scheduler. The caller
* is expected to return as soon as possible.
* The lock has not been acquired.
*
******************************************************************************
*/
VMK_ReturnStatus
vmk_SpinlockLock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockReadLock -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK_RW for reading
*
* \param[in,out] lock R/W Spinlock to be acquired
*
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockReadUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
* \note The lock acquisition might not succeed if the world receives a
* VMK_DEATH_PENDING signal while it is waiting for the lock.
*
* \retval VMK_OK World acquired the read lock.
* \retval VMK_DEATH_PENDING World blocked during the lock acquisition
* and awoken because the world is dying and
* being reaped by the scheduler. The caller
* is expected to return as soon as possible.
* The read lock has not been acquired.
*
******************************************************************************
*/
VMK_ReturnStatus
vmk_SpinlockReadLock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockWriteLock -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK_RW for an exclusive write
* operation
*
* \param[in,out] lock R/W Spinlock to be acquired
*
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockWriteUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
* \note The lock acquisition might not succeed if the world receives a
* VMK_DEATH_PENDING signal while it is waiting for the lock.
*
* \retval VMK_OK World acquired the write lock.
* \retval VMK_DEATH_PENDING World blocked during the lock acquisition
* and awoken because the world is dying and
* being reaped by the scheduler. The caller
* is expected to return as soon as possible.
* The write lock has not been acquired.
*
******************************************************************************
*/
VMK_ReturnStatus
vmk_SpinlockWriteLock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockLockIgnoreDeathPending -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK
*
* \param[in,out] lock Spinlock to be acquired
*
* \note This functions should only be used by callers that must acquire a
* lock, for instance to perform clean up, even after a world has
* already received the VMK_DEATH_PENDING signal.
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
*
******************************************************************************
*/
void
vmk_SpinlockLockIgnoreDeathPending(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockReadLockIgnoreDeathPending -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK_RW for reading
*
* \param[in,out] lock R/W Spinlock to be acquired
*
* \note This functions should only be used by callers that must acquire a
* lock, for instance to perform clean up, even after a world has
* already received the VMK_DEATH_PENDING signal.
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockReadUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
*
******************************************************************************
*/
void
vmk_SpinlockReadLockIgnoreDeathPending(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockWriteLockIgnoreDeathPending -- */ /**
*
* \brief Acquire a spinlock of type VMK_SPINLOCK_RW for an exclusive write
* operation
*
* \param[in,out] lock R/W Spinlock to be acquired
*
* \note This functions should only be used by callers that must acquire a
* lock, for instance to perform clean up, even after a world has
* already received the VMK_DEATH_PENDING signal.
* \note Lock checks are only executed when enabled for a given build. They
* are always enabled for debug builds.
* \note A caller has to release the spinlock with a subsequent call to
* vmk_SpinlockWriteUnlock
* \note Callers are required to minimize the time and code that is executed
* while any type of spinlock is held.
* \note This function might block in case of lock contention
*
******************************************************************************
*/
void
vmk_SpinlockWriteLockIgnoreDeathPending(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockUnlock -- */ /**
*
* \brief Release a spinlock previously acquired via vmk_SpinlockLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are required to release spinlocks in the reverse order in which
* they were acquired
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockUnlock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockUnlockOutOfOrder -- */ /**
*
* \brief Out of order release of a spinlock previously acquired via
* vmk_SpinlockLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are normally required to release spinlocks in the reverse
* order in which they were acquired. This function allows for out
* of order releases but this should only be done when it is known to
* be safe. This function should only be used for out of order releases;
* in all other cases vmk_SpinlockUnlock should be used.
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockUnlockOutOfOrder(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockReadUnlock -- */ /**
*
* \brief Release a R/W spinlock previously acquired via vmk_SpinlockReadLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are required to release spinlocks in the reverse order in which
* they were acquired
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockReadUnlock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockReadUnlockOutOfOrder -- */ /**
*
* \brief Out of order release of a R/W spinlock previously acquired via
* vmk_SpinlockReadLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are normally required to release spinlocks in the reverse
* order in which they were acquired. This function allows for out
* of order releases but this should only be done when it is known to
* be safe. This function should only be used for out of order releases;
* in all other cases vmk_SpinlockReadUnlock should be used.
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockReadUnlockOutOfOrder(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockWriteUnlock -- */ /**
*
* \brief Release a R/W spinlock previously acquired via vmk_SpinlockWriteLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are required to release spinlocks in the reverse order in which
* they were acquired
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockWriteUnlock(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockWriteUnlockOutOfOrder -- */ /**
*
* \brief Out of order release of a R/W spinlock previously acquired via
* vmk_SpinlockWriteLock
*
* \param[in,out] lock Spinlock to be released
*
* \note Callers are normally required to release spinlocks in the reverse
* order in which they were acquired. This function allows for out
* of order releases but this should only be done when it is known to
* be safe. This function should only be used for out of order releases;
* in all other cases vmk_SpinlockWriteUnlock should be used.
* \note This function will not block
*
******************************************************************************
*/
void
vmk_SpinlockWriteUnlockOutOfOrder(vmk_Lock lock);
/*
******************************************************************************
* vmk_SpinlockAssertReaderHeldByWorldInt --
*
* This is used by vmk_SpinlockAssertHeldByWorld(). VMKAPI clients should not
* call this function directly.
*
* \note This function will not block
*
******************************************************************************
*/
/** \cond nodoc */
void
vmk_SpinlockAssertReaderHeldByWorldInt(vmk_Lock lock);
/** \endcond */
/*
******************************************************************************
* vmk_SpinlockAssertReaderHeldByWorld -- */ /**
*
* \brief Asserts that a VMK_SPINLOCK_RW reader lock is held by the current world
*
* \param[in] lock VMK_SPINLOCK_RW reader lock to check
*
* \note Checks are only executed on debug builds.
* \note This function should only be called with a lock of lock type
* VMK_SPINLOCK_RW which is holding a VMK_SPINLOCK_RW reader lock.
* \note This function will not block
*
******************************************************************************
*/
static VMK_ALWAYS_INLINE void
vmk_SpinlockAssertReaderHeldByWorld(
vmk_Lock lock)
{
#ifdef VMX86_DEBUG
vmk_SpinlockAssertReaderHeldByWorldInt(lock);
#endif
}
/*
******************************************************************************
* vmk_SpinlockAssertHeldByWorldInt --
*
* This is used by vmk_SpinlockAssertHeldByWorld(). VMKAPI clients should not
* call this function directly.
*
* \note This function will not block
*
******************************************************************************
*/
/** \cond nodoc */
void
vmk_SpinlockAssertHeldByWorldInt(vmk_Lock lock);
/** \endcond */
/*
******************************************************************************
* vmk_SpinlockAssertHeldByWorld -- */ /**
*
* \brief Asserts that a lock is held by the current world
*
* \param[in] lock Lock to check
*
* \note Checks are only executed on debug builds.
* \note This function should only be called with a lock of lock type
* VMK_SPINLOCK or VMK_SPINLOCK_RW (RW locks that are writer locks only).
* For reader locks, use vmk_SpinlockAssertReaderHeldByWorld().
* \note This function will not block
*
******************************************************************************
*/
static VMK_ALWAYS_INLINE void
vmk_SpinlockAssertHeldByWorld(
vmk_Lock lock)
{
#ifdef VMX86_DEBUG
vmk_SpinlockAssertHeldByWorldInt(lock);
#endif
}
#endif
/** @} */
/** @} */
|