Improvements to coroutining support. These changes allow us to do

Estimated hours taken: 20

Improvements to coroutining support. These changes allow us to do
provide io primatives that cause the Mercury context to suspend rather
than causing the engine to block.

configure.in:
	Test to see if we can handle contexts that block on IO
	using select().

compiler/pragma_c_gen.m:
	Include the predicate name in the calls to MR_OBTAIN_GLOBAL_C_LOCK
	and MR_RELEASE_GLOBAL_C_LOCK for improved debugging.

	Fix a bug where the global lock was not being released when
	semidet pragma c code failed.

runtime/mercury_thread.h:
	Change the global lock macros to include the message generated
	by the changes to pragma_c_gen.

library/char.m:
library/std_util.m:
	include `thread_safe' in the flags for a couple of pragma c
	definitions that seem to have missed out.

runtime/mercury_context.{c,h}:
	Add a list of "pending" contexts that are blocked on a
	file descriptor. When the runqueue becomes empty, we call
	select on all the pending contexts.

	Move schedule from the header file to the c file (changing
	it from a macro to a function) for easier debugging at a
	slight performance cost.

	TODO: add a nonblocking call to select so that we can poll
	for io from time to time rather than waiting till there is
	nothing else to do.

runtime/mercury_reg_workarounds.{c,h}:
	Make functions that forward to the FD_* macros, which on Linux
	attempt to use registers that we've already grabbed. Aarrggh!

runtime/mercury_thread.c:
	Tidy up some of the conditional compilation.

runtime/mercury_types.h:
	Remove the definition of SpinLock since we're not using them
	and are not likely to any time soon.
This commit is contained in:
Thomas Conway
1998-12-15 00:22:29 +00:00
parent 44440da422
commit b2b99e5b50
10 changed files with 195 additions and 33 deletions

View File

@@ -15,7 +15,7 @@
#if defined(MR_DIGITAL_UNIX_PTHREADS)
#define MR_MUTEX_ATTR pthread_mutexattr_default
#define MR_COND_ATTR pthread_condattr_default
#define MR_THREAD_ATTR pthread_attr_default
#define MR_THREAD_ATTR pthread_attr_default
#else
#define MR_MUTEX_ATTR NULL
#define MR_COND_ATTR NULL
@@ -27,7 +27,7 @@
typedef pthread_mutex_t MercuryLock;
typedef pthread_cond_t MercuryCond;
#if 0
#ifndef MR_DEBUG_THREADS
/*
** The following macros should be used once the
** use of locking in the generated code is considered
@@ -57,11 +57,11 @@
** predicates which are not thread-safe.
** See the comments below.
*/
#define MR_OBTAIN_GLOBAL_C_LOCK() MR_mutex_lock(&MR_global_lock, \
"pragma c code");
#define MR_OBTAIN_GLOBAL_C_LOCK(where) MR_LOCK(&MR_global_lock, \
(where));
#define MR_RELEASE_GLOBAL_C_LOCK() MR_mutex_unlock(&MR_global_lock, \
"pragma c code");
#define MR_RELEASE_GLOBAL_C_LOCK(where) MR_UNLOCK(&MR_global_lock, \
(where));
#if defined(MR_DIGITAL_UNIX_PTHREADS)
#define MR_GETSPECIFIC(key) ({ \