2002-12-02 01:00:20 +00:00
|
|
|
|
/* classes: h_files */
|
|
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#ifndef SCM_PTHREADS_THREADS_H
|
|
|
|
|
|
#define SCM_PTHREADS_THREADS_H
|
2002-12-02 01:00:20 +00:00
|
|
|
|
|
2012-02-23 14:18:57 +01:00
|
|
|
|
/* Copyright (C) 2002, 2005, 2006, 2011 Free Software Foundation, Inc.
|
2002-12-02 01:00:20 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
2002-12-02 01:00:20 +00:00
|
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2002-12-02 01:00:20 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
2002-12-02 01:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* __scm.h (SCM_ALLOW_INTS_ONLY): Removed.
(SCM_NONREC_CRITICAL_SECTION_START,
SCM_NONREC_CRITICAL_SECTION_END, SCM_REC_CRITICAL_SECTION_START,
SCM_REC_CRITICAL_SECTION_END): New macros.
(SCM_CRITICAL_SECTION_START/END): Defined here.
* eval.c: Insert SOURCE_SECTION_START / SOURCE_SECTION_END around
the three calls to scm_m_expand_body.
* gc.h: #include "libguile/pthread-threads.h";
(SCM_FREELIST_CREATE, SCM_FREELIST_LOC): New macros.
* gc.c (scm_i_freelist, scm_i_freelist2): Defined to be of type
scm_t_key;
* gc.c, gc-freelist.c, inline.h: Use SCM_FREELIST_LOC for freelist
access.
* gc-freelist.c (scm_gc_init_freelist): Create freelist keys.
* gc-freelist.c, threads.c (really_launch): Use
SCM_FREELIST_CREATE.
* gc-malloc.c (scm_realloc, scm_gc_register_collectable_memory):
* gc.c (scm_i_expensive_validation_check, scm_gc,
scm_gc_for_newcell): Put threads to sleep before doing GC-related
heap administration so that those pieces of code are executed
single-threaded. We might consider rewriting these code sections
in terms of a "call_gc_code_singly_threaded" construct instead of
calling the pair of scm_i_thread_put_to_sleep () and
scm_i_thread_wake_up (). Also, we would want to have as many of
these sections eleminated.
* init.c (scm_init_guile_1): Call scm_threads_prehistory.
* inline.h: #include "libguile/threads.h"
* pthread-threads.h: Macros now conform more closely to the
pthreads interface. Some of them now take a second argument.
* threads.c, threads.h: Many changes.
* configure.in: Temporarily replaced "copt" threads option with new
option "pthreads".
(USE_PTHREAD_THREADS): Define if pthreads configured.
2002-12-09 13:42:58 +00:00
|
|
|
|
/* The pthreads-threads implementation. This is a direct mapping.
|
2002-12-02 01:00:20 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2002-12-16 15:24:13 +00:00
|
|
|
|
#include <sched.h>
|
2002-12-02 01:00:20 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Threads
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define scm_i_pthread_t pthread_t
|
|
|
|
|
|
#define scm_i_pthread_self pthread_self
|
2011-05-26 18:43:09 +02:00
|
|
|
|
#define scm_i_pthread_create pthread_create
|
|
|
|
|
|
#define scm_i_pthread_detach pthread_detach
|
2011-03-29 13:21:44 +02:00
|
|
|
|
|
|
|
|
|
|
#define scm_i_pthread_exit pthread_exit
|
|
|
|
|
|
#define scm_i_pthread_cancel pthread_cancel
|
|
|
|
|
|
|
2007-10-20 11:09:58 +00:00
|
|
|
|
#define scm_i_pthread_cleanup_push pthread_cleanup_push
|
|
|
|
|
|
#define scm_i_pthread_cleanup_pop pthread_cleanup_pop
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#define scm_i_sched_yield sched_yield
|
|
|
|
|
|
|
|
|
|
|
|
/* Signals
|
* __scm.h (SCM_ALLOW_INTS_ONLY): Removed.
(SCM_NONREC_CRITICAL_SECTION_START,
SCM_NONREC_CRITICAL_SECTION_END, SCM_REC_CRITICAL_SECTION_START,
SCM_REC_CRITICAL_SECTION_END): New macros.
(SCM_CRITICAL_SECTION_START/END): Defined here.
* eval.c: Insert SOURCE_SECTION_START / SOURCE_SECTION_END around
the three calls to scm_m_expand_body.
* gc.h: #include "libguile/pthread-threads.h";
(SCM_FREELIST_CREATE, SCM_FREELIST_LOC): New macros.
* gc.c (scm_i_freelist, scm_i_freelist2): Defined to be of type
scm_t_key;
* gc.c, gc-freelist.c, inline.h: Use SCM_FREELIST_LOC for freelist
access.
* gc-freelist.c (scm_gc_init_freelist): Create freelist keys.
* gc-freelist.c, threads.c (really_launch): Use
SCM_FREELIST_CREATE.
* gc-malloc.c (scm_realloc, scm_gc_register_collectable_memory):
* gc.c (scm_i_expensive_validation_check, scm_gc,
scm_gc_for_newcell): Put threads to sleep before doing GC-related
heap administration so that those pieces of code are executed
single-threaded. We might consider rewriting these code sections
in terms of a "call_gc_code_singly_threaded" construct instead of
calling the pair of scm_i_thread_put_to_sleep () and
scm_i_thread_wake_up (). Also, we would want to have as many of
these sections eleminated.
* init.c (scm_init_guile_1): Call scm_threads_prehistory.
* inline.h: #include "libguile/threads.h"
* pthread-threads.h: Macros now conform more closely to the
pthreads interface. Some of them now take a second argument.
* threads.c, threads.h: Many changes.
* configure.in: Temporarily replaced "copt" threads option with new
option "pthreads".
(USE_PTHREAD_THREADS): Define if pthreads configured.
2002-12-09 13:42:58 +00:00
|
|
|
|
*/
|
2011-04-03 22:03:56 +02:00
|
|
|
|
#define scm_i_pthread_sigmask pthread_sigmask
|
* __scm.h (SCM_ALLOW_INTS_ONLY): Removed.
(SCM_NONREC_CRITICAL_SECTION_START,
SCM_NONREC_CRITICAL_SECTION_END, SCM_REC_CRITICAL_SECTION_START,
SCM_REC_CRITICAL_SECTION_END): New macros.
(SCM_CRITICAL_SECTION_START/END): Defined here.
* eval.c: Insert SOURCE_SECTION_START / SOURCE_SECTION_END around
the three calls to scm_m_expand_body.
* gc.h: #include "libguile/pthread-threads.h";
(SCM_FREELIST_CREATE, SCM_FREELIST_LOC): New macros.
* gc.c (scm_i_freelist, scm_i_freelist2): Defined to be of type
scm_t_key;
* gc.c, gc-freelist.c, inline.h: Use SCM_FREELIST_LOC for freelist
access.
* gc-freelist.c (scm_gc_init_freelist): Create freelist keys.
* gc-freelist.c, threads.c (really_launch): Use
SCM_FREELIST_CREATE.
* gc-malloc.c (scm_realloc, scm_gc_register_collectable_memory):
* gc.c (scm_i_expensive_validation_check, scm_gc,
scm_gc_for_newcell): Put threads to sleep before doing GC-related
heap administration so that those pieces of code are executed
single-threaded. We might consider rewriting these code sections
in terms of a "call_gc_code_singly_threaded" construct instead of
calling the pair of scm_i_thread_put_to_sleep () and
scm_i_thread_wake_up (). Also, we would want to have as many of
these sections eleminated.
* init.c (scm_init_guile_1): Call scm_threads_prehistory.
* inline.h: #include "libguile/threads.h"
* pthread-threads.h: Macros now conform more closely to the
pthreads interface. Some of them now take a second argument.
* threads.c, threads.h: Many changes.
* configure.in: Temporarily replaced "copt" threads option with new
option "pthreads".
(USE_PTHREAD_THREADS): Define if pthreads configured.
2002-12-09 13:42:58 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Mutexes
|
|
|
|
|
|
*/
|
2007-10-10 16:46:26 +00:00
|
|
|
|
#if SCM_NEED_BRACES_ON_PTHREAD_MUTEX_INITIALIZER
|
|
|
|
|
|
# define SCM_I_PTHREAD_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
|
|
|
|
|
|
#else
|
|
|
|
|
|
# define SCM_I_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
|
|
|
|
|
#endif
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#define scm_i_pthread_mutex_t pthread_mutex_t
|
|
|
|
|
|
#define scm_i_pthread_mutex_init pthread_mutex_init
|
|
|
|
|
|
#define scm_i_pthread_mutex_destroy pthread_mutex_destroy
|
|
|
|
|
|
#define scm_i_pthread_mutex_trylock pthread_mutex_trylock
|
|
|
|
|
|
#define scm_i_pthread_mutex_lock pthread_mutex_lock
|
|
|
|
|
|
#define scm_i_pthread_mutex_unlock pthread_mutex_unlock
|
2005-10-23 20:47:49 +00:00
|
|
|
|
extern pthread_mutexattr_t scm_i_pthread_mutexattr_recursive[1];
|
2005-03-02 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
/* Condition variables
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define SCM_I_PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
|
|
|
|
|
|
#define scm_i_pthread_cond_t pthread_cond_t
|
|
|
|
|
|
#define scm_i_pthread_cond_init pthread_cond_init
|
|
|
|
|
|
#define scm_i_pthread_cond_destroy pthread_cond_destroy
|
|
|
|
|
|
#define scm_i_pthread_cond_signal pthread_cond_signal
|
|
|
|
|
|
#define scm_i_pthread_cond_broadcast pthread_cond_broadcast
|
|
|
|
|
|
#define scm_i_pthread_cond_wait pthread_cond_wait
|
|
|
|
|
|
#define scm_i_pthread_cond_timedwait pthread_cond_timedwait
|
|
|
|
|
|
|
|
|
|
|
|
/* Onces
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define scm_i_pthread_once_t pthread_once_t
|
|
|
|
|
|
#define scm_i_pthread_once pthread_once
|
2006-10-09 23:40:48 +00:00
|
|
|
|
#if SCM_NEED_BRACES_ON_PTHREAD_ONCE_INIT
|
|
|
|
|
|
#define SCM_I_PTHREAD_ONCE_INIT { PTHREAD_ONCE_INIT }
|
|
|
|
|
|
#else
|
|
|
|
|
|
#define SCM_I_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
|
|
|
|
|
|
#endif
|
2002-12-02 01:00:20 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Thread specific storage
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define scm_i_pthread_key_t pthread_key_t
|
|
|
|
|
|
#define scm_i_pthread_key_create pthread_key_create
|
|
|
|
|
|
#define scm_i_pthread_setspecific pthread_setspecific
|
|
|
|
|
|
#define scm_i_pthread_getspecific pthread_getspecific
|
2002-12-18 10:53:23 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Convenience functions
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define scm_i_scm_pthread_mutex_lock scm_pthread_mutex_lock
|
2006-01-29 00:23:28 +00:00
|
|
|
|
#define scm_i_dynwind_pthread_mutex_lock scm_dynwind_pthread_mutex_lock
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#define scm_i_scm_pthread_cond_wait scm_pthread_cond_wait
|
|
|
|
|
|
#define scm_i_scm_pthread_cond_timedwait scm_pthread_cond_timedwait
|
* __scm.h (SCM_DEFER_INTS, SCM_ALLOW_INTS): New definitions.
Simply lock a thread C API recursive mutex.
(SCM_NONREC_CRITICAL_SECTION_START,
SCM_NONREC_CRITICAL_SECTION_END, SCM_REC_CRITICAL_SECTION_START,
SCM_REC_CRITICAL_SECTION_END): Removed.
* eval.c: Replaced SOURCE_SECTION_START / SOURCE_SECTION_END with
direct calls to scm_rec_mutex_lock / unlock around the three calls
to scm_m_expand_body.
* eval.c, eval.h (promise_free): New function.
(scm_force): Rewritten; Now thread-safe; Removed
SCM_DEFER/ALLOW_INTS.
* pthread-threads.h: Added partially implemented plugin interface
for recursive mutexes. These are, for now, only intended to be
used internally within the Guile implementation.
* pthread-threads.c: New file.
* threads.c: Conditionally #include "pthread-threads.c".
* eval.c, eval.h (scm_makprom, scm_force): Rewritten to be
thread-safe;
* snarf.h (SCM_MUTEX, SCM_GLOBAL_MUTEX, SCM_REC_MUTEX,
SCM_GLOBAL_REC_MUTEX): New macros.
* eval.c, threads.c, threads.h, snarf.h: Rewrote critical section
macros---use mutexes instead.
* tags.h (SCM_IM_FUTURE): New tag.
* eval.c (scm_m_future): New primitive macro.
(SCM_CEVAL): Support futures.
(unmemocopy): Support unmemoization of futures.
* print.c (scm_isymnames): Name of future isym.
2002-12-15 14:24:34 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#endif /* SCM_PTHREADS_THREADS_H */
|
2002-12-02 01:00:20 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|