Changeset 571:17685531a0f3

Show
Ignore:
Timestamp:
06/02/08 01:50:10 (7 months ago)
Author:
David Anderson <dave@…>
Branch:
default
Message:

Tweak the API of lock.h around a little.

Locking spinlocks by value instead of by ref through a macro was
treacherous, and so has been removed in favor of a more transparent
API. Unlocking is now an inline function instead of a macro.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • nxos/base/lock.h

    r384 r571  
    11/** @file lock.h 
    2  *  @brief Locking primitives 
     2 *  @brief Locking primitives. 
    33 */ 
    44 
    5 /* Copyright (C) 2007 the NxOS developers 
     5/* Copyright (c) 2007,2008 the NxOS developers 
    66 * 
    77 * See AUTHORS for a full list of the developers. 
     
    6565 * spinlock can be acquired. 
    6666 * 
    67  * @note This means that a spinlock is only useful when you need to 
    68  * synchronize between the main execution context and an interrupt 
    69  * handler, or some other form of preemption that can break free of the 
    70  * spinlock's infinite loop. 
     67 * @note These semantics mean that a spinlock is only useful when you 
     68 * need to synchronize between the main execution context and an 
     69 * interrupt handler, or some other form of preemption that can break 
     70 * free of the spinlock's infinite loop. 
    7171 */ 
    7272/*@{*/ 
     
    8181#define SPINLOCK_INIT_LOCKED 1 
    8282 
    83 /** @cond DOXYGEN_SKIP */ 
    84 void nx_spinlock_acquire_from_ref(spinlock *lock); 
    85 bool nx_spinlock_try_acquire_from_ref(spinlock *lock); 
    86 /** @endcond */ 
    87  
    8883/** Acquire @a lock and return. 
    8984 * 
    9085 * Will loop indefinitely until the spinlock can be acquired. 
    9186 * 
    92  * @param lock The spinlock to acquire. 
     87 * @param lock Pointer to the spinlock to acquire. 
    9388 */ 
    94 #define nx_spinlock_acquire(lock) spinlock_acquire_from_ref(&(lock)) 
     89void nx_spinlock_acquire(spinlock *lock); 
    9590 
    9691/** Attempt to acquire @a lock and return the result. 
     
    9994 * fail to acquire the spinlock. 
    10095 * 
    101  * @param lock The spinlock to acquire. 
     96 * @param lock Pointer to the spinlock to acquire. 
    10297 * @return 1 if the spinlock was acquired, 0 if it was already locked. 
    10398 */ 
    104 #define nx_spinlock_try_acquire(lock) spinlock_try_acquire_from_ref(&(lock)) 
     99void nx_spinlock_try_acquire(spinlock *lock); 
    105100 
    106101/** Release @a lock. 
     
    108103 * Does not block. 
    109104 * 
    110  * @param lock The spinlock to release. 
     105 * @param lock Pointer to the spinlock to release. 
    111106 */ 
    112 #define nx_spinlock_release(lock) { lock = 0; } 
     107void nx_spinlock_release(spinlock *lock); 
     108 
     109inline void nx_spinlock_release(spinlock *lock) { 
     110  *lock = 0; 
     111} 
    113112 
    114113/*@}*/