Rev 6082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6082 | Rev 6102 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | 17 | ||
18 | #include |
18 | #include |
19 | #include |
19 | #include |
20 | #include |
20 | #include |
21 | #include |
- | |
Line 22... | Line 21... | ||
22 | #include |
21 | #include |
23 | 22 | ||
24 | struct kref { |
23 | struct kref { |
Line 97... | Line 96... | ||
97 | static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)) |
96 | static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)) |
98 | { |
97 | { |
99 | return kref_sub(kref, 1, release); |
98 | return kref_sub(kref, 1, release); |
100 | } |
99 | } |
Line 101... | Line -... | ||
101 | - | ||
102 | /** |
- | |
103 | * kref_put_spinlock_irqsave - decrement refcount for object. |
- | |
104 | * @kref: object. |
- | |
105 | * @release: pointer to the function that will clean up the object when the |
- | |
106 | * last reference to the object is released. |
- | |
107 | * This pointer is required, and it is not acceptable to pass kfree |
- | |
108 | * in as this function. |
- | |
109 | * @lock: lock to take in release case |
- | |
110 | * |
- | |
111 | * Behaves identical to kref_put with one exception. If the reference count |
- | |
112 | * drops to zero, the lock will be taken atomically wrt dropping the reference |
- | |
113 | * count. The release function has to call spin_unlock() without _irqrestore. |
- | |
114 | */ |
- | |
115 | static inline int kref_put_spinlock_irqsave(struct kref *kref, |
- | |
116 | void (*release)(struct kref *kref), |
- | |
117 | spinlock_t *lock) |
- | |
118 | { |
- | |
119 | unsigned long flags; |
- | |
120 | - | ||
121 | WARN_ON(release == NULL); |
- | |
122 | if (atomic_add_unless(&kref->refcount, -1, 1)) |
- | |
123 | return 0; |
- | |
124 | spin_lock_irqsave(lock, flags); |
- | |
125 | if (atomic_dec_and_test(&kref->refcount)) { |
- | |
126 | release(kref); |
- | |
127 | local_irq_restore(flags); |
- | |
128 | return 1; |
- | |
129 | } |
- | |
130 | spin_unlock_irqrestore(lock, flags); |
- | |
131 | return 0; |
- | |
132 | } |
- | |
133 | 100 | ||
134 | static inline int kref_put_mutex(struct kref *kref, |
101 | static inline int kref_put_mutex(struct kref *kref, |
135 | void (*release)(struct kref *kref), |
102 | void (*release)(struct kref *kref), |
136 | struct mutex *lock) |
103 | struct mutex *lock) |
137 | { |
104 | { |