mutex-common.h 2.6 KB
Newer Older
1
/*
2
 * mutex-common.h       -- Mutex support for STklos
3 4 5 6
 *
 * Copyright © 2006-2009 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
 *
 *
7 8 9 10
 * 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.
11
 *
12 13 14 15
 * 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.
16
 *
17 18
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20
 * USA.
21
 *
22 23
 *           Author: Erick Gallesio [eg@essi.fr]
 *    Creation date:  4-Feb-2006 11:03 (eg)
24
 * Last file update: 21-Sep-2018 08:56 (eg)
25 26 27 28 29 30
 */
#ifndef _STK_MUTEX_H
#define _STK_MUTEX_H

#include "stklos.h"

31
#if defined(THREADS_PTHREADS)
32 33 34 35 36 37 38
# include "mutex-pthreads.h"
#else
# include "mutex-none.h"
#endif

/* ====================================================================== *\
 *
39
 *                             M U T E X E S
40
 *
41 42 43 44 45 46 47 48
\* ====================================================================== */

struct mutex_obj {
  stk_header header;
  SCM name;
  SCM specific;
  SCM owner;
  int locked;
49
  struct sys_mutex_obj sys_mutex;
50 51
};

52 53 54 55 56
#define MUTEXP(p)               (BOXED_TYPE_EQ((p), tc_mutex))
#define MUTEX_NAME(p)           (((struct mutex_obj *) (p))->name)
#define MUTEX_SPECIFIC(p)       (((struct mutex_obj *) (p))->specific)
#define MUTEX_OWNER(p)          (((struct mutex_obj *) (p))->owner)
#define MUTEX_LOCKED(p)         (((struct mutex_obj *) (p))->locked)
57 58 59

/* ====================================================================== *\
 *
60
 *                             C O N D   V A R S
61
 *
62 63 64 65 66 67
\* ====================================================================== */

struct condv_obj {
  stk_header header;
  SCM name;
  SCM specific;
68
  struct sys_condv_obj sys_condv;
69 70
};

71 72 73
#define CONDVP(p)               (BOXED_TYPE_EQ((p), tc_condv))
#define CONDV_NAME(p)           (((struct condv_obj *) (p))->name)
#define CONDV_SPECIFIC(p)       (((struct condv_obj *) (p))->specific)
74 75 76 77 78 79 80 81 82 83 84

/* ====================================================================== */

extern SCM STk_sym_not_owned, STk_sym_abandoned, STk_sym_not_abandoned;

extern void STk_error_bad_mutex(SCM obj);
extern void STk_error_deadlock(void);

extern void STk_error_bad_condv(SCM obj);

#endif /* ! _STK_MUTEX_H */