Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
e45583c0
Commit
e45583c0
authored
Aug 30, 2010
by
Martin Sustrik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OSX build fixed -- semaphore replaced by mutex
parent
f0a36f99
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
2 deletions
+53
-2
semaphore.hpp
src/semaphore.hpp
+53
-2
No files found.
src/semaphore.hpp
View file @
e45583c0
...
@@ -76,7 +76,59 @@ namespace zmq
...
@@ -76,7 +76,59 @@ namespace zmq
HANDLE
ev
;
HANDLE
ev
;
// Disable copying of the object.
semaphore_t
(
const
semaphore_t
&
);
void
operator
=
(
const
semaphore_t
&
);
};
#elif defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_OSX || defined ZMQ_HAVE_OPENVMS
// On platforms that allow for double locking of a mutex from the same
// thread, simple semaphore is implemented using mutex, as it is more
// efficient than full-blown semaphore.
// Note that OS-level semaphore is not implemented on OSX, so the below
// code is not only optimisation, it's necessary to make 0MQ work on OSX.
class
semaphore_t
{
public
:
// Initialise the semaphore.
inline
semaphore_t
()
{
int
rc
=
pthread_mutex_init
(
&
mutex
,
NULL
);
posix_assert
(
rc
);
rc
=
pthread_mutex_lock
(
&
mutex
);
posix_assert
(
rc
);
}
// Destroy the semaphore.
inline
~
semaphore_t
()
{
int
rc
=
pthread_mutex_unlock
(
&
mutex
);
posix_assert
(
rc
);
rc
=
pthread_mutex_destroy
(
&
mutex
);
posix_assert
(
rc
);
}
// Wait for the semaphore.
inline
void
wait
()
{
int
rc
=
pthread_mutex_lock
(
&
mutex
);
posix_assert
(
rc
);
}
// Post the semaphore.
inline
void
post
()
{
int
rc
=
pthread_mutex_unlock
(
&
mutex
);
posix_assert
(
rc
);
}
private
:
pthread_mutex_t
mutex
;
semaphore_t
(
const
semaphore_t
&
);
semaphore_t
(
const
semaphore_t
&
);
void
operator
=
(
const
semaphore_t
&
);
void
operator
=
(
const
semaphore_t
&
);
};
};
...
@@ -122,7 +174,6 @@ namespace zmq
...
@@ -122,7 +174,6 @@ namespace zmq
// Underlying system semaphore object.
// Underlying system semaphore object.
sem_t
sem
;
sem_t
sem
;
// Disable copying of the object.
semaphore_t
(
const
semaphore_t
&
);
semaphore_t
(
const
semaphore_t
&
);
void
operator
=
(
const
semaphore_t
&
);
void
operator
=
(
const
semaphore_t
&
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment