source: anotherchoice/tags/jsp-1.4.4-full-UTF8/systask/cxxrt.c@ 363

Last change on this file since 363 was 363, checked in by ykominami, 5 years ago

add tags/jsp-1.4.4-full-UTF8

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/*
2 * TOPPERS/JSP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
5 *
6 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2003-2004 by Takagi Nobuhisa
9 *
10 * 上記著作権者
11は,以下の (1)〜(4) の条件か,Free Software Foundation
12 * によってå…
13¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
14 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
15 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
16å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
17 * 利用と呼ぶ)することを無償で許諾する.
18 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
19 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
20 * スコード中に含まれていること.
21 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
22 * 用できる形で再é…
23å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
24å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
25 * 者
26マニュアルなど)に,上記の著作権表示,この利用条件および下記
27 * の無保証規定を掲載すること.
28 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
29 * 用できない形で再é…
30å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®ã„ずれかの条件を満たすこ
31 * と.
32 * (a) 再é…
33å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
34マニュアルなど)に,上記の著
35 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
36 * (b) 再é…
37å¸ƒã®å½¢æ…
38‹ã‚’,別に定める方法によって,TOPPERSプロジェクトに
39 * 報告すること.
40 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
41 * 害からも,上記著作権者
42およびTOPPERSプロジェクトをå…
43è²¬ã™ã‚‹ã“と.
44 *
45 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
46お
47 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
48 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
49 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
50 *
51 * @(#) $Id: cxxrt.c,v 1.3 2004/09/17 09:11:44 honda Exp $
52 */
53#include "../kernel/jsp_kernel.h"
54#include "../kernel/task.h"
55#include "kernel_id.h"
56
57typedef int _toppers_cxxrt_sync_t;
58typedef volatile char _toppers_cxxrt_once_t;
59
60static inline int _get_tid()
61{
62 return runtsk - tcb_table + TMIN_TSKID;
63}
64
65/*
66 * For Syncronization
67 */
68int _toppers_cxxrt_lock(_toppers_cxxrt_sync_t *sync)
69{
70 if (iniflg)
71 dis_dsp();
72 return 0;
73}
74
75int _toppers_cxxrt_trylock(_toppers_cxxrt_sync_t *sync)
76{
77 return _toppers_cxxrt_lock(sync);
78}
79
80int _toppers_cxxrt_unlock(_toppers_cxxrt_sync_t *sync)
81{
82 if (iniflg)
83 ena_dsp();
84 return 0;
85}
86
87int _toppers_cxxrt_get_tskid(void)
88{
89 return iniflg ? _get_tid() : 0;
90}
91
92/*
93 * For recursive semaphore lock
94 */
95static ID cxxrt_holder;
96static UINT cxxrt_counter;
97
98static inline void _toppers_cxxrt_recursive_semaphore_lock(ID semid)
99{
100 if (iniflg && !sns_dsp())
101 {
102 ID tskid;
103 tskid = _get_tid();
104
105 if (cxxrt_holder != tskid)
106 {
107 wai_sem(semid);
108 cxxrt_holder = tskid;
109 }
110 ++cxxrt_counter;
111 }
112}
113
114static inline void _toppers_cxxrt_recursive_semaphore_unlock(ID semid)
115{
116 if (iniflg && !sns_dsp())
117 {
118 if (--cxxrt_counter == 0)
119 {
120 cxxrt_holder = 0;
121 sig_sem(semid);
122 }
123 }
124}
125
126
127/*
128 * For function call once
129 */
130int _toppers_cxxrt_once(_toppers_cxxrt_once_t *once, void (*func)(void))
131{
132 if (!*once)
133 {
134 static _toppers_cxxrt_sync_t sync;
135
136 _toppers_cxxrt_recursive_semaphore_lock(_CXXRT_SEM);
137 if (!*once)
138 {
139 (*func)();
140 *once = 1;
141 }
142 _toppers_cxxrt_recursive_semaphore_unlock(_CXXRT_SEM);
143 }
144 return 0;
145}
146
147
148/*
149 * For task-local storage
150 */
151#ifndef CXXRT_KEY_MAX
152#define CXXRT_KEY_MAX 2
153#endif
154
155struct _toppers_cxxrt_tls
156{
157 void **data;
158 void (*dtor)(void*);
159};
160
161extern const ID tmax_tskid;
162
163static void **tls_data[CXXRT_KEY_MAX];
164static struct _toppers_cxxrt_tls tls[CXXRT_KEY_MAX];
165
166int _toppers_cxxrt_key_create(struct _toppers_cxxrt_tls **key, void (*dtor)(void*))
167{
168 struct _toppers_cxxrt_tls *p;
169
170 for (p = &tls[0]; p < &tls[CXXRT_KEY_MAX]; p++)
171 {
172 if (p->data == NULL)
173 {
174 p->data = tls_data[p - &tls[0]];
175 p->dtor = dtor;
176 *key = p;
177 return 0;
178 }
179 }
180 return -1;
181}
182
183int _toppers_cxxrt_key_delete(struct _toppers_cxxrt_tls *key)
184{
185 int i;
186
187 for (i = 0; i <= tmax_tskid; i++)
188 {
189 if (key->dtor != 0)
190 (*key->dtor)(key->data[i]);
191 }
192 key->data = NULL;
193 key->dtor = 0;
194 return 0;
195}
196
197/* JSP 1.4との互換性のために_toppers_cxxrt_reset_specificを残しておく */
198void _toppers_cxxrt_reset_specific(void)
199{
200}
201
202void _toppers_cxxrt_init(void)
203{
204 int i, tmax = tmax_tskid + 1;
205 void **p = (void**)malloc(sizeof(void*) * CXXRT_KEY_MAX * tmax);
206
207 for (i = 0; i < CXXRT_KEY_MAX * tmax; i++)
208 p[i] = NULL;
209 for (i = 0; i < CXXRT_KEY_MAX; i++)
210 tls_data[i] = p + i * tmax;
211}
212
Note: See TracBrowser for help on using the repository browser.