int32_t psCreateMutex(psMutex_t *mutex, uint32_t flags) { pthread_mutexattr_t attr; int rc; if (flags & ~PS_SHARED) { psErrorInt("psCreateMutex unsupported flag %u\n", flags); return PS_PLATFORM_FAIL; } if ((rc = pthread_mutexattr_init(&attr)) < 0) { psErrorInt("pthread_mutexattr_init failed %d\n", rc); return PS_PLATFORM_FAIL; } if ((flags & PS_SHARED) && (rc = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED)) < 0) { pthread_mutexattr_destroy(&attr); psErrorInt("pthread_mutexattr shared failed %d\n", rc); return PS_PLATFORM_FAIL; } if ((rc = pthread_mutex_init(mutex, &attr)) != 0) { pthread_mutexattr_destroy(&attr); psErrorInt("pthread_mutex_init failed %d\n", rc); return PS_PLATFORM_FAIL; } if (pthread_mutexattr_destroy(&attr) != 0) { psTraceCore("pthread_mutexattr_destroy failed\n"); } return PS_SUCCESS; }
/* Module open and close */ int osdepMutexOpen(void) { int32 rc; if ((rc = pthread_mutexattr_init(&attr)) < 0) { psErrorInt("pthread_mutexattr_init failed %d\n", rc); return PS_PLATFORM_FAIL; } return PS_SUCCESS; }
/* Module open and close */ int osdepEntropyOpen(void) { /* Open /dev/random access non-blocking. */ if ((urandfd = open("/dev/urandom", O_RDONLY)) < 0) { psErrorInt("open of urandom failed %d\n", urandfd); return PS_PLATFORM_FAIL; } /* For platforms that don't have /dev/random, just assign it to urandom */ if ((randfd = open("/dev/random", O_RDONLY | O_NONBLOCK)) < 0) { randfd=urandfd; } return PS_SUCCESS; }