123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include <errno.h>
- #include <sysdep.h>
- #include <lowlevellock.h>
- #include <internaltypes.h>
- #include <semaphore.h>
- int
- sem_trywait (sem_t *sem)
- {
- struct sparc_old_sem *isem = (struct sparc_old_sem *) sem;
- int val;
- if (isem->value > 0)
- {
- if (__atomic_is_v9)
- val = atomic_decrement_if_positive (&isem->value);
- else
- {
- __sparc32_atomic_do_lock24 (&isem->lock);
- val = isem->value;
- if (val > 0)
- isem->value = val - 1;
- __sparc32_atomic_do_unlock24 (&isem->lock);
- }
- if (val > 0)
- return 0;
- }
- __set_errno (EAGAIN);
- return -1;
- }
|