summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/unix/posix/shmsupp/lock.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1995-08-11 14:27:23 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1995-08-11 14:27:23 +0000
commitaa9f19454a6912a337752fee5e0f98414de3e8a5 (patch)
tree19f558b8763cda168b1ea2d047c0270297147c2f /c/src/lib/libbsp/unix/posix/shmsupp/lock.c
parentclean up -- interrupt support is in place (diff)
downloadrtems-aa9f19454a6912a337752fee5e0f98414de3e8a5.tar.bz2
Initialization of semaphores was incorrect. It did not force
the count to "1" to indicate availability. Interrupt support was added. Problem where newlib's errno "overrides" that set by system calls was addressed. Fixed bug which resulted in all nodes using the same semaphore although an array of semaphores was allocated.
Diffstat (limited to 'c/src/lib/libbsp/unix/posix/shmsupp/lock.c')
-rw-r--r--c/src/lib/libbsp/unix/posix/shmsupp/lock.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/c/src/lib/libbsp/unix/posix/shmsupp/lock.c b/c/src/lib/libbsp/unix/posix/shmsupp/lock.c
index 9376b6d5e8..0dd0cbd8b3 100644
--- a/c/src/lib/libbsp/unix/posix/shmsupp/lock.c
+++ b/c/src/lib/libbsp/unix/posix/shmsupp/lock.c
@@ -41,8 +41,7 @@ void Shm_Initialize_lock(
Shm_Locked_queue_Control *lq_cb
)
{
- lq_cb->lock =
- ( lq_cb - Shm_Locked_queues ) / sizeof( Shm_Locked_queue_Control );
+ lq_cb->lock = lq_cb - Shm_Locked_queues;
}
/* Shm_Lock( &lq_cb )
@@ -60,24 +59,25 @@ void Shm_Lock(
struct sembuf sb;
int status;
- isr_level = 0;
-
sb.sem_num = lq_cb->lock;
sb.sem_op = -1;
sb.sem_flg = 0;
+
rtems_interrupt_disable( isr_level );
Shm_isrstat = isr_level;
while (1) {
status = semop(semid, &sb, 1);
- if ( status == 0 )
+ if ( status >= 0 )
break;
- if ( status == -1 && errno == EINTR )
- continue;
-
- fprintf( stderr, "shm lock(%d %d)\n", status, errno );
- exit( 0 );
+ if ( status == -1 ) {
+ fix_syscall_errno(); /* in case of newlib */
+ if (errno == EINTR)
+ continue;
+ perror("shm lock");
+ rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
+ }
}
}
@@ -95,21 +95,22 @@ void Shm_Unlock(
struct sembuf sb;
int status;
- isr_level = 0;
-
sb.sem_num = lq_cb->lock;
sb.sem_op = 1;
sb.sem_flg = 0;
while (1) {
status = semop(semid, &sb, 1);
- if ( status == 0 )
+ if ( status >= 0 )
break;
- if ( status == -1 && errno == EINTR )
- continue;
- fprintf( stderr, "shm unlock(%d %d)\n", status, errno );
- exit( 0 );
+ if ( status == -1 ) {
+ fix_syscall_errno(); /* in case of newlib */
+ if (errno == EINTR)
+ continue;
+ perror("shm unlock");
+ rtems_fatal_error_occurred(RTEMS_UNSATISFIED);
+ }
}
isr_level = Shm_isrstat;