Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Aug 1997 17:59:11 -0400 (EDT)
From:      Paul Southworth <pauls@locust.etext.org>
To:        freebsd-hackers@freebsd.org
Subject:   Re: MySQL using FreeBSD native threads (3.0)
Message-ID:  <Pine.NEB.3.95.970810175631.21447A-100000@locust.etext.org>

next in thread | raw e-mail | index | archive | help

Here's the latest regarding libc_r and MySQL.  The patch below is against
the libc_r source in 970618-SNAP.

-----------------------------------------------------------------------

Here is the 'newest' compleate patch that appears to work: (At least
sigwait() now works according to Posix and MySQL really neads this):

Please mail a copy of this to the freebsd-hackers list.

This mails ends with a compleat patch that fixes everything except
the pthread.h problem with struct sched_param, but I was able to
handle this with configure.

-------

Bugs found in Freebsd's pthread implementation:


----------------------------------------

- sigsuspend should replace the callers mask to the given mask, not add
  the given mask to the old mask.
  The signals should also be handled and not as with SIGWAIT where the
  signal function is ignored.

Fix:

uthread_sigsuspend.c:

		/* Save the current sigmal mask: */
		oset = _thread_run->sigmask;

!		/* Replace the caller's mask with the current one: */
!		_thread_run->sigmask= *set;	/* Patched by Monty */

		/* Wait for a signal: */
!		_thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__);


uthread_kern.c:

	case PS_FDR_WAIT:
	case PS_FDW_WAIT:
	case PS_SLEEP_WAIT:
+	case PS_SIGSUSPEND:

And of course add a definition for PS_SIGSUSPEND.

----------------------------------------

- It almost impossible to debug threads because all signals are masked in the
  threads library.

Fix:

uthread_kern.c, line 53

- static sigset_t sig_to_block = 0xffffffff;
+ static sigset_t sig_to_block = ~((1 << 5) | (1 << 6) | (1 << 4));

----------------------------------------

- The sigwait function is in the library but it isn't exported.
- A signal to a thread in sigwait doesn't set the thread 'runnable'.
  This is because the arguments to sigwait() is put to sigmask which doesn't
  work because the signal must be sent to _thread_signal().
- Signals that are not waited for with sigwait() should be handled before
  they are returned.
- sigwait returns 'random' value:

Fix:

Add uthread_sigwait.c to libc_r/uthread/Makefile.inc

Change sigwait to:


In pthread_privat.h

        PS_DEAD,
!       PS_STATE_MAX,
+       PS_SIGSUSPEND
};

----

        /*
         * Current signal mask and array of pending signals.
         */
!       sigset_t        sigmask,sigwaitmask;
        int             sigpend[NSIG];


uthread_kern.c:

Change:

        /* Waiting on a signal: */
        case PS_SIGWAIT:
                /* Change the state of the thread to run: */
                PTHREAD_NEW_STATE(pthread,PS_RUNNING);

                /* Return the signal number: */
                pthread->signo = sig;

                /* Flag the signal as dealt with: */
                done = 1;
                break;
        }

to

        /* Waiting on a signal: */
        case PS_SIGWAIT:
                /* Change the state of the thread to run: */
                PTHREAD_NEW_STATE(pthread,PS_RUNNING);

                if (sigismember(&pthread->sigwaitmask, sig))
                {
                  /* Return the signal number: */
                  pthread->signo = sig;

                  /* Flag the signal as dealt with: */
                  done = 1;
                }
                break;


----------------------------------------

Because one needs to access the struct sched_param slots this must be
defined when one includes pthread.h.  One should also change the slot name
from 'prior' to 'sched_priority' according to Posix.

Fix:

Move definition of structs sched_param from pthread_private.h to 
pthread.h.

Change:

struct sched_param {
        int     prio;
        void    *no_data;
};

to

struct sched_param {
        int     sched_priority;
        void    *no_data;
};


Empty definition of the schedparam functions would also be nice..



*******************************************************************************

Complete patch of the above with some small additions for sigsuspend:




diff of Makefile.inc in /usr/src/lib/libc_r/uthread/ and .
85a86
> 	uthread_sigwait.c \
diff of pthread_private.h in /usr/src/lib/libc_r/uthread/ and .
243c243,244
< 	PS_STATE_MAX
---
> 	PS_STATE_MAX,
> 	PS_SIGSUSPEND
344c345
< 	sigset_t	sigmask;
---
> 	sigset_t	sigmask,sigwaitmask;
diff of uthread_kern.c in /usr/src/lib/libc_r/uthread/ and .
53c53,54
< static sigset_t sig_to_block = 0xffffffff;
---
> /* Changed by monty for easy debugging of pthreads with gdb */
> static sigset_t sig_to_block = ~((1 << 5) | (1 << 6) | (1 << 4));
893a895
> 	case PS_SIGSUSPEND:
909a912,913
> 		if (sigismember(&pthread->sigwaitmask, sig))
> 		{
914a919
> 		}
1100a1106
> 		case PS_SIGSUSPEND:
1449a1456
> 			case PS_SIGSUSPEND:
diff of uthread_sigsuspend.c in /usr/src/lib/libc_r/uthread/ and .
50,51c50,51
< 		/* Combine the caller's mask with the current one: */
< 		_thread_run->sigmask |= *set;
---
> 		/* Replace the caller's mask with the current one: */
> 		_thread_run->sigmask= *set;/* Patched by Monty */
54c54
< 		_thread_kern_sched_state(PS_SIGWAIT, __FILE__, __LINE__);
---
> 		_thread_kern_sched_state(PS_SIGSUSPEND, __FILE__, __LINE__);
diff of uthread_sigwait.c in /usr/src/lib/libc_r/uthread/ and .
38a39,40
> /* This version of sigwait is modifed by monty@tcx.se to work properly */
> 
42c44
< 	int ret;
---
> 	int ret=0;
49,51d50
< 	/* Save the current sigmal mask: */
< 	oset = _thread_run->sigmask;
< 
53c52,56
< 	_thread_run->sigmask |= *set;
---
> 	_thread_run->sigmask &=  ~*set;
> 	_thread_run->sigwaitmask = *set;
> 
> 	/* Clear for easy error check */
> 	_thread_run->signo=0;
62a66,68
> 
> 	/* Reset the sigwait mask for debugging */
> 	_thread_run->sigwaitmask = 0;





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.NEB.3.95.970810175631.21447A-100000>