[m-dev.] Changes to pragma c & runtime fixes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 6 16:44:07 AEST 1998


On 06-Aug-1998, Thomas Charles CONWAY <conway at cs.mu.OZ.AU> wrote:
> +The attributes which must be supported by all implementations
> +are as follows:
> + at table @asis
> +
> + at item @samp{may_call_mercury}/@samp{will_not_call_mercury} declares
> +whether or not execution inside this C code may call back into Mercury
> +or not.
> +
> + at item @samp{thread_safe}/@samp{not_thread_safe} declares whether or not
> +it is safe for multiple threads to execute this C code concurrently.
> +C code that is not thread_safe has code inserted around it to obtain
> +and release a mutex.  All non-thread-safe C code shares a single mutex.
> +
> + at end table

Please check the TexInfo formatting looks OK in all 3 versions
(info, dvi, html).  I think the use of @item here might be wrong.
I think it may be better to format that as

	...
	are as follows:
							% note blank line here
	@table @code
	@item may_call_mercury
	@itemx will_not_call_mercury
	These declare whether or not execution inside this C code may
	call back into Mercury or not.

	@item thread_safe
	@itemx not_thread_safe
	These declare ...

	@end table

	...

> Index: runtime/mercury_context.c
> ===================================================================
> RCS file: /home/staff/zs/imp/mercury/runtime/mercury_context.c,v
> retrieving revision 1.9
> diff -u -r1.9 mercury_context.c
> --- mercury_context.c	1998/07/28 01:01:38	1.9
> +++ mercury_context.c	1998/07/31 05:44:49
> @@ -54,6 +54,8 @@
>  	free_context_list_lock = make(MercuryLock);
>  	pthread_mutex_init(free_context_list_lock, MR_MUTEX_ATTR);
>  
> +	pthread_mutex_init(&MR_global_lock, MR_MUTEX_ATTR);
> +
>  	MR_KEY_CREATE(&MR_engine_base_key, NULL);
>  
>  #endif
> Index: runtime/mercury_engine.c
> ===================================================================
> RCS file: /home/staff/zs/imp/mercury/runtime/mercury_engine.c,v
> retrieving revision 1.12
> diff -u -r1.12 mercury_engine.c
> --- mercury_engine.c	1998/07/22 07:52:37	1.12
> +++ mercury_engine.c	1998/08/06 01:45:44
> @@ -116,6 +116,7 @@
>  #ifdef	MR_THREAD_SAFE
>  	eng->owner_thread = pthread_self();
>  	eng->c_depth = 0;
> +	eng->saved_owners = NULL;
>  #endif
>  
>  	/*
> @@ -232,9 +233,6 @@
>  void 
>  call_engine_inner(Code *entry_point)
>  {
> -#ifdef	MR_THREAD_SAFE
> -	MercuryThread saved_owner_thread;
> -#endif
>  	/*
>  	** Allocate some space for local variables in other
>  	** procedures. This is done because we may jump into the middle
> @@ -251,6 +249,11 @@
>  	** This technique should work and should be vaguely portable,
>  	** just so long as local variables and temporaries are allocated in
>  	** the same way in every function.
> +	**
> +	** WARNING!
> +	** Do not add local variables to call_engine_inner that you expect
> +	** to remain live across Mercury execution - Mercury execution will
> +	** scribble on the stack frame for this function.
>  	*/
>  
>  	unsigned char locals[LOCALS_SIZE];
> @@ -295,8 +298,17 @@
>  	*/
>  #ifdef	MR_THREAD_SAFE
>  	MR_ENGINE(c_depth)++;
> -	saved_owner_thread = MR_ENGINE(this_context)->owner_thread;
> +{
> +	MercuryThreadList *new_element;
> +
> +	new_element = make(MercuryThreadList);
> +	new_element->thread = MR_ENGINE(this_context)->owner_thread;
> +	new_element->next = MR_ENGINE(saved_owners);
> +	MR_ENGINE(saved_owners) = new_element;
> +}

This is a lot of overhead for every C->mercury call.

Why not just do the manipulation of saved_owner_thread in
call_engine() instead of call_engine_inner()?

(You can do that as a separate change, though.)

> +++ mercury_thread.c	1998/08/06 00:27:32
>  #ifdef MR_THREAD_SAFE
> +
> +void *
> +create_thread_2(void *goal);

Shouldn't that be declared static?

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list