[Pkg-gnupg-commit] [gpgme] 03/12: doc: Fix minor errors in I/O callback example
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Sep 22 23:29:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch cleanup-2016-09-22
in repository gpgme.
commit 0aaf1dedd629446ab991fff76581b4b58e4872a0
Author: Daiki Ueno <ueno at gnu.org>
Date: Tue Feb 9 17:03:50 2016 +0900
doc: Fix minor errors in I/O callback example
* gpgme.texi (I/O Callback Example): Fix typos, add timeout to select,
and initialize mutex as recursive.
Signed-off-by: Daiki Ueno <ueno at gnu.org>
---
doc/gpgme.texi | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index ec7ebb7..6d6d692 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -6016,6 +6016,7 @@ do_select (struct event_loop *loop)
fd_set wfds;
int i, n;
int any = 0;
+ struct timeval tv;
struct one_fd *fdlist = loop->fds;
pthread_mutex_lock (&loop->lock);
@@ -6024,11 +6025,14 @@ do_select (struct event_loop *loop)
for (i = 0; i < MAX_FDS; i++)
if (fdlist[i].fd != -1)
FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
- pthread_mutex_unlock (&loop->unlock);
+ pthread_mutex_unlock (&loop->lock);
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 1000;
do
@{
- n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
+ n = select (FD_SETSIZE, &rfds, &wfds, NULL, &tv);
@}
while (n < 0 && errno == EINTR);
@@ -6082,6 +6086,7 @@ main (int argc, char *argv[])
gpgme_error_t err;
gpgme_data_t sig, text;
int i;
+ pthread_mutexattr_t attr;
struct gpgme_io_cbs io_cbs =
@{
add_io_cb,
@@ -6091,12 +6096,19 @@ main (int argc, char *argv[])
&result
@};
- init_gpgme (void);
+ init_gpgme ();
/* Initialize the loop structure. */
- pthread_mutex_init (&loop.lock, NULL);
+
+ /* The mutex must be recursive, since remove_io_cb (which acquires a
+ lock) can be called while holding a lock acquired in do_select. */
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init (&loop.lock, &attr);
+ pthread_mutexattr_destroy (&attr);
+
for (i = 0; i < MAX_FDS; i++)
- loop->fds[i].fd = -1;
+ loop.fds[i].fd = -1;
/* Initialize the result structure. */
result.done = 0;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git
More information about the Pkg-gnupg-commit
mailing list