thread-common.h 2.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * thread-common.h	-- Thread support for STklos
 * 
 * Copyright  2006 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
 * 
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
 * USA.
 * 
 *           Author: Erick Gallesio [eg@essi.fr]
 *    Creation date:  4-Feb-2006 11:03 (eg)
eg's avatar
eg committed
24
 * Last file update: 25-Oct-2006 10:19 (eg)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 */
#ifndef _STK_THREAD_H
#define _STK_THREAD_H

#include "stklos.h"

#ifdef THREADS_LURC
# include "thread-lurc.h"
#elif defined(THREADS_PTHREADS)
# include "thread-pthreads.h"
#else
# include "thread-none.h"
#endif

#ifndef THREADS_NONE

enum thread_state { th_new, th_runnable, th_terminated, th_blocked};

struct thread_obj {
  stk_header header;
  SCM thunk;
  SCM name;
  SCM specific;
  SCM end_result;
  SCM end_exception;
  enum thread_state state;
51
  int stack_stize;
52
  vm_thread_t *vm;
53
  struct sys_thread_obj sys_thread;
54 55 56 57 58 59 60 61 62 63
};


#define THREADP(p)		(BOXED_TYPE_EQ((p), tc_thread))
#define THREAD_THUNK(p)		(((struct thread_obj *) (p))->thunk)
#define THREAD_NAME(p)		(((struct thread_obj *) (p))->name)
#define THREAD_SPECIFIC(p)	(((struct thread_obj *) (p))->specific)
#define THREAD_RESULT(p)	(((struct thread_obj *) (p))->end_result)
#define THREAD_EXCEPTION(p)	(((struct thread_obj *) (p))->end_exception)
#define THREAD_STATE(p)		(((struct thread_obj *) (p))->state)
64
#define THREAD_STACK_SIZE(p)	(((struct thread_obj *) (p))->stack_stize)
65 66 67 68 69 70 71 72
#define THREAD_VM(p)		(((struct thread_obj *) (p))->vm)

extern void STk_error_bad_thread(SCM obj);

extern SCM STk_cond_thread_terminated;

#endif /* ! THREADS_NONE */

73
struct timeval STk_thread_abstime_to_reltime(double abs_secs);
74 75 76
extern SCM STk_primordial_thread; 

#endif /* ! _STK_THREAD_H */