* Signal a userland semaphore. */
| 3229 | * Signal a userland semaphore. |
| 3230 | */ |
| 3231 | static int |
| 3232 | do_sem_wake(struct thread *td, struct _usem *sem) |
| 3233 | { |
| 3234 | struct umtx_key key; |
| 3235 | int error, cnt; |
| 3236 | uint32_t flags; |
| 3237 | |
| 3238 | error = fueword32(&sem->_flags, &flags); |
| 3239 | if (error == -1) |
| 3240 | return (EFAULT); |
| 3241 | if ((error = umtx_key_get(sem, TYPE_SEM, GET_SHARE(flags), &key)) != 0) |
| 3242 | return (error); |
| 3243 | umtxq_lock(&key); |
| 3244 | umtxq_busy(&key); |
| 3245 | cnt = umtxq_count(&key); |
| 3246 | if (cnt > 0) { |
| 3247 | /* |
| 3248 | * Check if count is greater than 0, this means the memory is |
| 3249 | * still being referenced by user code, so we can safely |
| 3250 | * update _has_waiters flag. |
| 3251 | */ |
| 3252 | if (cnt == 1) { |
| 3253 | umtxq_unlock(&key); |
| 3254 | error = suword32(&sem->_has_waiters, 0); |
| 3255 | umtxq_lock(&key); |
| 3256 | if (error == -1) |
| 3257 | error = EFAULT; |
| 3258 | } |
| 3259 | umtxq_signal(&key, 1); |
| 3260 | } |
| 3261 | umtxq_unbusy(&key); |
| 3262 | umtxq_unlock(&key); |
| 3263 | umtx_key_release(&key); |
| 3264 | return (error); |
| 3265 | } |
| 3266 | #endif |
| 3267 | |
| 3268 | static int |
no test coverage detected