trick/trick_source/trick_utils/shm/src/tsm_disconnect.c
Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
Changed all header file once include variables to follow the same naming
convention and not start with any underscores.  Also deleted old
incorrect copyright notices.  Also removed $Id: tags from all files.

Fixes #14.  Fixes #22.
2015-03-23 16:03:14 -05:00

34 lines
802 B
C

/*
* Disconnect (detach) a shared memory segment
*/
#include "../include/tsm.h"
#include "../include/tsm_proto.h"
int tsm_disconnect(TSMDevice * shm_device)
{
int ret;
ret = TSM_SUCCESS;
// if we had a read/write lock, destroy it first
if (shm_device->rwlock_addr != NULL) {
ret = pthread_rwlockattr_destroy(&shm_device->rwlattr);
if (ret == -1) {
perror("tsm_disconnect SHARED MEMORY DESTROY LOCK ATTRIBUTES FAILED");
}
ret = pthread_rwlock_destroy(shm_device->rwlock_addr);
if (ret == -1) {
perror("tsm_disconnect SHARED MEMORY DESTROY LOCK FAILED");
}
}
ret = shmdt(shm_device->addr);
if (ret == -1) {
perror("tsm_disconnect SHARED MEMORY DETACH FAILED");
}
return (ret);
}