Skip to content

Commit

Permalink
Merge pull request #937 from was4444/1.11
Browse files Browse the repository at this point in the history
fix: pthread_mutex should be process-shared
(cherry picked from commit 97cd5c4)
  • Loading branch information
bogdan-iancu committed Aug 2, 2016
1 parent 2e60179 commit 2b79d96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile.defs
Expand Up @@ -1361,6 +1361,9 @@ ifeq ($(OS), linux)
DEFS+= -DUSE_POSIX_SEM # try posix sems
found_lock_method=yes
endif
ifneq (,$(findstring USE_PTHREAD_MUTEX, $(DEFS)))
LIBS += -pthread
endif
# check for >= 2.5.44
ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
ifeq ($(NO_EPOLL),)
Expand Down
19 changes: 17 additions & 2 deletions lock_ops.h
Expand Up @@ -104,8 +104,23 @@ typedef pthread_mutex_t gen_lock_t;

inline static gen_lock_t* lock_init(gen_lock_t* lock)
{
if (pthread_mutex_init(lock, 0)==0) return lock;
else return 0;
pthread_mutexattr_t attr;

if (pthread_mutexattr_init(&attr) != 0)
return 0;

if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) != 0) {
pthread_mutexattr_destroy(&attr);
return 0;
}

if (pthread_mutex_init(lock, &attr) != 0) {
pthread_mutexattr_destroy(&attr);
return 0;
}

pthread_mutexattr_destroy(&attr);
return lock;
}


Expand Down

0 comments on commit 2b79d96

Please sign in to comment.