Added rsmi_dev_pci_replay_counter_get()

Also, added code to destroy/recreate mutex if we can't get a lock
within 3 seconds, when shared memory mutex is initialized.
This commit is contained in:
Chris Freehill
2019-05-06 11:26:40 -05:00
orang tua 5e24a77193
melakukan 34c977bd06
11 mengubah file dengan 88 tambahan dan 21 penghapusan
+16 -2
Melihat File
@@ -8,6 +8,7 @@
#include <stdio.h> // perror
#include <stdlib.h> // malloc, free
#include <string.h> // strcpy
#include <time.h> // clock_gettime
shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
shared_mutex_t mutex = {NULL, 0, NULL, 0};
@@ -51,7 +52,17 @@ shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
return mutex;
}
if (mutex.created == 0 && ((shared_mutex_t *)addr)->ptr == NULL) {
pthread_mutex_t *mutex_ptr = (pthread_mutex_t *)addr;
// Make sure the mutex wasn't left in a locked state. If we can't
// acquire it in 3 sec., re-do everything.
struct timespec expireTime;
clock_gettime(CLOCK_REALTIME, &expireTime);
expireTime.tv_sec += 3;
int ret = pthread_mutex_timedlock(mutex_ptr, &expireTime);
if (ret || (mutex.created == 0 && ((shared_mutex_t *)addr)->ptr == NULL)) {
// Something is out of sync. Unlink shm and start over.
if (shm_unlink(name)) {
mutex.shm_fd = 0;
@@ -60,9 +71,12 @@ shared_mutex_t shared_mutex_init(const char *name, mode_t mode) {
free(mutex.name);
return shared_mutex_init(name, mode);
} else {
if (pthread_mutex_unlock(mutex_ptr)) {
perror("pthread_mutex_unlock");
}
}
pthread_mutex_t *mutex_ptr = (pthread_mutex_t *)addr;
if (mutex.created) {
pthread_mutexattr_t attr;
+3
Melihat File
@@ -1,3 +1,6 @@
// NOLINT(legal/copyright)
// See LICENSE file
#ifndef SRC_SHARED_MUTEX_SHARED_MUTEX_H_
#define SRC_SHARED_MUTEX_SHARED_MUTEX_H_