1/* BEGIN LICENSE BLOCK
2 * Version: CMPL 1.1
3 *
4 * The contents of this file are subject to the Cisco-style Mozilla Public
5 * License Version 1.1 (the "License"); you may not use this file except
6 * in compliance with the License.  You may obtain a copy of the License
7 * at www.eclipse-clp.org/license.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11 * the License for the specific language governing rights and limitations
12 * under the License.
13 *
14 * The Original Code is  The ECLiPSe Constraint Logic Programming System.
15 * The Initial Developer of the Original Code is  Cisco Systems, Inc.
16 * Portions created by the Initial Developer are
17 * Copyright (C) 1994-2006 Cisco Systems, Inc.  All Rights Reserved.
18 *
19 * Contributor(s): Kees Schuerman, ECRC
20 *
21 * END LICENSE BLOCK */
22/**********************************************************************
23**      System: Parallel Distributed System
24**        File: pds.mem.h
25**      Author: Kees Schuerman
26**      SccsId: "@(#)pds.mem.h	1.4 28 Nov 1995"
27** Description: The files pds.mem.h and pds.mem.c provide the interface
28**		to the memory and interrupt system. There are two
29**		compilation flags, i.e. THREAD_SAFE and INTERRUPT_SAFE.
30**		When processes are single threaded and no pds functions
31**		are invoked from interrupt handlers, there is no real
32**		need for enabling the thread safeness or interrupt safeness
33**		and neither of the flags should be activated. In general,
34**		one selects however THREAD_SAFE for applications with
35**		multithreaded processes and INTERRUPT_SAFE for applications
36**		with just single threaded processes.
37**		Thread synchronization is based on mutexes which may
38**		differ depending on their purpose, i.e. intra-process
39**		synchronization (local mutex: l_mutex_t) or inter-process
40**		synchronization (global mutex: g_mutex_t). In general the
41**		former are more efficient than the latter.
42***********************************************************************/
43
44#ifndef _PDS_MEM_H_
45#define _PDS_MEM_H_
46
47#include <memman.h>		/* ECLiPSe Memory and Interrupt System */
48
49
50/*
51** Interrupt System
52*/
53
54#if defined(__STDC__)
55extern void pds_int_init(void (* handler) (void));
56#else /* __STDC__ */
57extern void pds_int_init();
58#endif /* __STDC__ */
59
60#define pds_int_disabled  	InterruptsDisabled
61#define pds_int_pending  	InterruptsPending
62#define pds_disable_int()	Disable_Int()
63#define pds_enable_int()	Enable_Int()
64#define pds_set_int_pending()  	Set_Interrupts_Pending()
65#define pds_clr_int_pending()  	Clr_Interrupts_Pending()
66
67
68/*
69** Global Mutexes
70*/
71
72typedef a_mutex_t g_mutex_t;
73
74#define g_mutex_init(m)		a_mutex_init(m)
75#define g_mutex_lock(m)		a_mutex_lock(m)
76#define g_mutex_unlock(m)	a_mutex_unlock(m)
77
78
79/*
80** Local Mutexes
81*/
82
83#if defined(THREAD_SAFE)
84
85typedef a_mutex_t l_mutex_t;
86
87#define l_mutex_init(m)		a_mutex_init(m)
88#define l_mutex_lock(m)		a_mutex_lock(m)
89#define l_mutex_unlock(m)	a_mutex_unlock(m)
90
91#else /* THREAD_SAFE */
92
93typedef int l_mutex_t;
94
95#if defined(INTERRUPT_SAFE)
96
97#define l_mutex_init(m)
98#define l_mutex_lock(m)		pds_disable_int()
99#define l_mutex_unlock(m)	pds_enable_int()
100
101#else /* INTERRUPT_SAFE */
102
103#define l_mutex_init(m)
104#define l_mutex_lock(m)
105#define l_mutex_unlock(m)
106
107#endif /* INTERRUPT_SAFE */
108
109#endif /* THREAD_SAFE */
110
111
112/*
113** Memory System
114*/
115
116#define PDS_LINE_SIZE	128	/* PDS Virtual Cache Line Size         */
117
118typedef struct heap_descriptor pds_heap_descriptor_t;
119
120#if defined(__STDC__)
121extern char * pds_mem_init(char * file,
122			   char * address,
123			   pds_size_t size,
124			   pds_heap_descriptor_t * descriptor,
125			   unsigned option);
126#else /* __STDC__ */
127extern char * pds_mem_init();
128#endif /* __STDC__ */
129
130#define pds_mem_base()			   shared_mem_base()
131#define pds_mem_release(dscr)		   shared_mem_release(dscr)
132#define pds_mem_alloc(dscr,size)	   h_alloc(dscr,size)
133#define pds_mem_free(dscr,addr)		   h_free(dscr,addr)
134#define pds_mem_alloc_size(dscr,size)	   alloc_size(dscr,size)
135#define pds_mem_free_size(dscr,addr,size)  free_size(dscr,addr,size)
136
137
138#endif /* _PDS_MEM_H_ */
139