2002-10-16 15:54:23 +00:00
|
|
|
|
/* classes: h_files */
|
|
|
|
|
|
|
2002-12-02 00:59:27 +00:00
|
|
|
|
#ifndef SCM_NULL_THREADS_H
|
|
|
|
|
|
#define SCM_NULL_THREADS_H
|
2002-10-16 15:54:23 +00:00
|
|
|
|
|
2012-02-23 14:18:57 +01:00
|
|
|
|
/* Copyright (C) 2005, 2006, 2010 Free Software Foundation, Inc.
|
2002-10-16 15:54:23 +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-10-16 15:54:23 +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-10-16 15:54:23 +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-10-16 15:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* The null-threads implementation. We provide the subset of the
|
|
|
|
|
|
standard pthread API that is used by Guile, but no new threads can
|
|
|
|
|
|
be created.
|
* __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
|
|
|
|
This file merely exits so that Guile can be compiled and run
|
|
|
|
|
|
without using pthreads. Improving performance via optimizations
|
|
|
|
|
|
that are possible in a single-threaded program is not a primary
|
|
|
|
|
|
goal.
|
2002-12-02 00:59:27 +00:00
|
|
|
|
*/
|
2002-10-16 15:54:23 +00:00
|
|
|
|
|
2010-08-20 21:08:49 +02:00
|
|
|
|
#include <stdlib.h>
|
2016-07-24 13:16:45 +02:00
|
|
|
|
#include <signal.h>
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#include <errno.h>
|
2002-12-02 00:59:27 +00:00
|
|
|
|
|
2010-08-20 21:08:49 +02:00
|
|
|
|
/* Threads
|
2002-12-02 00:59:27 +00:00
|
|
|
|
*/
|
2016-07-24 13:16:45 +02:00
|
|
|
|
typedef int scm_i_pthread_t;
|
|
|
|
|
|
typedef void scm_i_pthread_attr_t;
|
|
|
|
|
|
|
|
|
|
|
|
static inline scm_i_pthread_t
|
|
|
|
|
|
scm_i_pthread_self (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_create (scm_i_pthread_t *t, const scm_i_pthread_attr_t *attr,
|
|
|
|
|
|
void* (*f) (void*), void *arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_detach (scm_i_pthread_t t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
|
scm_i_pthread_exit (void *retval)
|
|
|
|
|
|
{
|
|
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cancel (scm_i_pthread_t t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_sched_yield (void)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
/* Signals
|
|
|
|
|
|
*/
|
2016-07-24 13:16:45 +02:00
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_sigmask (int how, const sigset_t *set, sigset_t *oldset)
|
|
|
|
|
|
{
|
|
|
|
|
|
return sigprocmask (how, set, oldset);
|
|
|
|
|
|
}
|
2002-12-02 00:59:27 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Mutexes
|
|
|
|
|
|
*/
|
2016-07-24 13:16:45 +02:00
|
|
|
|
typedef enum {
|
|
|
|
|
|
SCM_I_PTHREAD_MUTEX_INITIALIZER = 0,
|
|
|
|
|
|
SCM_I_PTHREAD_MUTEX_LOCKED = 1
|
|
|
|
|
|
} scm_i_pthread_mutex_t;
|
|
|
|
|
|
typedef int scm_i_pthread_mutexattr_t;
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_mutex_init (scm_i_pthread_mutex_t *m,
|
|
|
|
|
|
scm_i_pthread_mutexattr_t *attr)
|
|
|
|
|
|
{
|
|
|
|
|
|
*m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_mutex_destroy (scm_i_pthread_mutex_t *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_mutex_trylock(scm_i_pthread_mutex_t *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (*m == SCM_I_PTHREAD_MUTEX_LOCKED)
|
|
|
|
|
|
return EDEADLK;
|
|
|
|
|
|
*m = SCM_I_PTHREAD_MUTEX_LOCKED;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_mutex_lock (scm_i_pthread_mutex_t *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
*m = SCM_I_PTHREAD_MUTEX_LOCKED;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_mutex_unlock (scm_i_pthread_mutex_t *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
*m = SCM_I_PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-10-23 20:47:49 +00:00
|
|
|
|
#define scm_i_pthread_mutexattr_recursive 0
|
2005-03-02 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
/* Condition variables
|
|
|
|
|
|
*/
|
2016-07-24 13:16:45 +02:00
|
|
|
|
typedef enum {
|
|
|
|
|
|
SCM_I_PTHREAD_COND_INITIALIZER = 0
|
|
|
|
|
|
} scm_i_pthread_cond_t;
|
|
|
|
|
|
typedef int scm_i_pthread_condattr_t;
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_init (scm_i_pthread_cond_t *c,
|
|
|
|
|
|
scm_i_pthread_condattr_t *attr)
|
|
|
|
|
|
{
|
|
|
|
|
|
*c = SCM_I_PTHREAD_COND_INITIALIZER;
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_destroy (scm_i_pthread_cond_t *c)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_signal (scm_i_pthread_cond_t *c)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_broadcast (scm_i_pthread_cond_t *c)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_wait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m)
|
|
|
|
|
|
{
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_cond_timedwait (scm_i_pthread_cond_t *c, scm_i_pthread_mutex_t *m,
|
|
|
|
|
|
const scm_t_timespec *t)
|
|
|
|
|
|
{
|
|
|
|
|
|
abort();
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2005-03-02 20:42:01 +00:00
|
|
|
|
|
|
|
|
|
|
/* Onces
|
|
|
|
|
|
*/
|
2016-07-24 13:16:45 +02:00
|
|
|
|
typedef enum {
|
|
|
|
|
|
SCM_I_PTHREAD_ONCE_INIT = 0,
|
|
|
|
|
|
SCM_I_PTHREAD_ONCE_ALREADY = 1
|
|
|
|
|
|
} scm_i_pthread_once_t;
|
|
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
|
scm_i_pthread_once (scm_i_pthread_once_t *o, void(*init)(void))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (*o == SCM_I_PTHREAD_ONCE_INIT)
|
|
|
|
|
|
{
|
|
|
|
|
|
*o = SCM_I_PTHREAD_ONCE_ALREADY;
|
|
|
|
|
|
init ();
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2002-12-02 00:59:27 +00:00
|
|
|
|
|
2005-03-02 20:42:01 +00:00
|
|
|
|
/* Thread specific storage
|
|
|
|
|
|
*/
|
|
|
|
|
|
typedef struct scm_i_pthread_key_t {
|
|
|
|
|
|
struct scm_i_pthread_key_t *next;
|
|
|
|
|
|
void *value;
|
|
|
|
|
|
void (*destr_func) (void *);
|
|
|
|
|
|
} scm_i_pthread_key_t;
|
|
|
|
|
|
|
|
|
|
|
|
SCM_API int scm_i_pthread_key_create (scm_i_pthread_key_t *key,
|
|
|
|
|
|
void (*destr_func) (void *));
|
|
|
|
|
|
#define scm_i_pthread_setspecific(k,p) ((k).value = (p))
|
|
|
|
|
|
#define scm_i_pthread_getspecific(k) ((k).value)
|
|
|
|
|
|
|
|
|
|
|
|
/* Convenience functions
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define scm_i_scm_pthread_mutex_lock scm_i_pthread_mutex_lock
|
2006-01-29 00:23:28 +00:00
|
|
|
|
#define scm_i_dynwind_pthread_mutex_lock scm_i_pthread_mutex_lock
|
2005-03-02 20:42:01 +00:00
|
|
|
|
#define scm_i_scm_pthread_cond_wait scm_i_pthread_cond_wait
|
|
|
|
|
|
#define scm_i_scm_pthread_cond_timedwait scm_i_pthread_cond_timedwait
|
2002-10-16 15:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
2002-12-02 00:59:27 +00:00
|
|
|
|
#endif /* SCM_NULL_THREADS_H */
|
2002-10-16 15:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Local Variables:
|
|
|
|
|
|
c-file-style: "gnu"
|
|
|
|
|
|
End:
|
|
|
|
|
|
*/
|