• R/O
  • SSH
  • HTTPS

globalbase: Commit


Commit MetaInfo

Revisão5993 (tree)
Hora2020-05-06 00:15:06
Autorjoshua

Mensagem de Log

stdArrayQueue critical section

Mudança Sumário

Diff

--- modules/tinyState/trunk/src/arch/posix/h/std/stdOpenSSL.h (revision 5992)
+++ modules/tinyState/trunk/src/arch/posix/h/std/stdOpenSSL.h (revision 5993)
@@ -25,6 +25,7 @@
2525 ~stdOpenSSL();
2626 static stdOpenSSL * New(tsApplication * app);
2727 private:
28+ tsApplication * _app;
2829 stdThreadOpenSSL * thread;
2930 static stdOpenSSL * current;
3031 static void pthreads_locking_callback(
--- modules/tinyState/trunk/src/arch/posix/std/stdOpenSSL.cpp (revision 5992)
+++ modules/tinyState/trunk/src/arch/posix/std/stdOpenSSL.cpp (revision 5993)
@@ -41,8 +41,8 @@
4141 CRYPTO_set_locking_callback(pthreads_locking_callback);
4242
4343 REF_SET(thread,NEW stdThreadOpenSSL(this));
44- tsThread::ins_setup(thread);
45-
44+ app->getThreadRoot()->ins_setup(thread);
45+ REF_SET(_app,app);
4646 }
4747
4848 stdOpenSSL::~stdOpenSSL()
@@ -65,8 +65,9 @@
6565
6666 CRYPTO_cleanup_all_ex_data();
6767
68- tsThread::del_setup(thread);
68+ _app->getThreadRoot()->del_setup(thread);
6969 REF_SET(thread,0);
70+ REF_SET(_app,0);
7071
7172 ::printf("stdOpenSSL finish\n");
7273 }
--- modules/tinyState/trunk/src/classes/gt/c++/gtTypeLockOnHelper.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/gt/c++/gtTypeLockOnHelper.cpp (revision 5993)
@@ -20,7 +20,7 @@
2020 void inherit(gtType * parent,
2121 gtType * target,
2222 gtTypeLockOn * lockon);
23- virtual int priority();
23+ virtual int priority(tinyState * caller);
2424
2525 gtType *& parent;
2626 private:
@@ -67,15 +67,18 @@
6767 }
6868
6969 int
70-gtTypeLockOnHelper_::priority()
70+gtTypeLockOnHelper_::priority(tinyState * caller)
7171 {
7272 gtType * pp;
73- if ( fix_pri )
73+ if ( fix_pri ) {
74+ if ( caller )
75+ listen(caller,TSE_PRIORITY);
7476 return fix_pri;
77+ }
7578 for ( pp = parent ; pp ; pp = dynamic_cast<gtType*>(pp->parent) )
7679 if ( pp->helper )
77- return pp->helper->priority();
78- return parent->priority();
80+ return pp->helper->priority(caller);
81+ return parent->priority(caller);
7982 }
8083
8184
@@ -95,6 +98,7 @@
9598 TS_STATE(ACT_TINYSTATE_START)
9699 {
97100 int pri;
101+tinyState * gbr;
98102 if ( C_TEST(parent->state,C_ZOM|C_FIN) )
99103 return rDO|FIN_START;
100104 if ( C_TEST(target->state,C_ZOM|C_FIN) )
@@ -102,11 +106,16 @@
102106 if ( !target->is_updated(ifThis) )
103107 return ACT_START;
104108 REF_SET(idstr,(NEW stdString("gtTypeLockOnHelper:%i:",
105- pri=priority()))->add(parent->uri()));
106- if ( application->get_global(idstr->get_str()) == 0 ) {
109+ pri=priority(0)))->add(parent->uri()));
110+ gbr = dynamic_cast<tinyState*>(application->get_global(idstr->get_str()));
111+ if ( gbr == 0 ) {
107112 application->set_global(idstr->get_str(),ifThis);
108113 fix_pri = pri + 1;
114+ invoke_listen(NEW stdEvent(TSE_PRIORITY,ifThis,(INTEGER64)0));
109115 }
116+ else {
117+ gbr->listen(ifThis,TSE_DESTROY);
118+ }
110119 application->gc->exe(ifThis);
111120 return rDO|ACT_RET;
112121 }
@@ -124,7 +133,10 @@
124133 lockon->sync();
125134 if ( fix_pri )
126135 parent->report(ifThis);
127- fix_pri = 0;
136+ if ( fix_pri ) {
137+ fix_pri = 0;
138+ invoke_listen(NEW stdEvent(TSE_PRIORITY,ifThis,(INTEGER64)0));
139+ }
128140 return ACT_START;
129141 }
130142 TS_STATE(FIN_START)
@@ -132,6 +144,7 @@
132144 REF_SET(lockon,0);
133145 REF_SET(target,0);
134146 REF_SET(idstr,0);
147+ invoke_listen(NEW stdEvent(TSE_PRIORITY,ifThis,(INTEGER64)0));
135148 return rDO|FIN_TINYSTATE_START;
136149 }
137150
--- modules/tinyState/trunk/src/classes/ts/c++/fwIO.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/fwIO.cpp (revision 5993)
@@ -605,7 +605,7 @@
605605 ok = this->read_objs->del(mfd,ts_io_get_comein);
606606 if ( ok == 0 )
607607 break;
608- result->ins(ok->obj->priority(),ok);
608+ result->ins(ok->obj->priority(0),ok);
609609 }
610610 mfd->fsp = &fdwrite;
611611 mfd->fexp = &fdexp;
@@ -613,7 +613,7 @@
613613 ok = this->write_objs->del(mfd,ts_io_get_comein);
614614 if ( ok == 0 )
615615 break;
616- result->ins(ok->obj->priority(),ok);
616+ result->ins(ok->obj->priority(0),ok);
617617 }
618618 }
619619 {
@@ -624,7 +624,7 @@
624624 now,ts_io_get_interval_comein);
625625 if ( ok == 0 )
626626 break;
627- result->ins(ok->obj->priority(),ok);
627+ result->ins(ok->obj->priority(0),ok);
628628 }
629629 }
630630 for ( ; ; ) {
--- modules/tinyState/trunk/src/classes/ts/c++/stdHalfOrderQueueTS.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/stdHalfOrderQueueTS.cpp (revision 5993)
@@ -6,19 +6,19 @@
66 {
77 }
88
9-stdHalfOrderQueueTS::stdHalfOrderQueueTS(stdHalfOrderQueueTS * q)
9+stdHalfOrderQueueTS::stdHalfOrderQueueTS(stdHalfOrderQueueTS * q,tinyState * caller)
1010 {
1111 tinyState * ts;
1212 for ( ; ; ) {
13- ts = q->del();
13+ ts = q->del(caller);
1414 if ( ts == 0 )
1515 break;
16- ins(ts->priority(),ts);
16+ ins(ts->priority(0),ts);
1717 }
1818 }
1919
2020 tinyState *
21-stdHalfOrderQueueTS::del()
21+stdHalfOrderQueueTS::del(tinyState * caller)
2222 {
2323 tinyState * ret;
2424 int key,key2;
@@ -26,10 +26,10 @@
2626 ret = dynamic_cast<tinyState*>(stdHalfOrderQueue::del(&key));
2727 if ( ret == 0 )
2828 return 0;
29- key2 = ret->priority();
30- if ( key == key2 )
29+ key2 = ret->priority(caller);
30+ if ( caller == 0 || key == key2 )
3131 return ret;
32- hoq = NEW stdHalfOrderQueueTS(this);
32+ hoq = NEW stdHalfOrderQueueTS(this,caller);
3333 hoq->ins(key2,ret);
3434 REF_SET(top,hoq->__top());
3535 return dynamic_cast<tinyState*>(stdHalfOrderQueue::del(&key));
--- modules/tinyState/trunk/src/classes/ts/c++/tinyState.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/tinyState.cpp (revision 5993)
@@ -1,4 +1,7 @@
11
2+
3+
4+
25 #include <stdio.h>
36
47 #include "_ts/c++/tinyState_.h"
@@ -53,7 +56,7 @@
5356 virtual int eventHandler(stdEvent * ev);
5457 static int static_eventHandler(tinyState*,stdEvent*);
5558 void inherit(tinyState* parent);
56- virtual int priority();
59+ virtual int priority(tinyState * caller=0);
5760 virtual void wakeup();
5861 void remove_listener(stdEventHandle*);
5962 virtual void destroy();
@@ -278,7 +281,8 @@
278281 onlyOneEvent_mask =
279282 TSE_EVM(TSE_WAKEUP)|
280283 TSE_EVM(TSE_STATE)|
281- TSE_EVM(TSE_DESTROY);
284+ TSE_EVM(TSE_DESTROY)|
285+ TSE_EVM(TSE_PRIORITY);
282286 REF_SET(this->que,NEW stdQueue<stdEvent>());
283287 REF_SET(this->rv_que,NEW stdQueue<stdEvent>());
284288 REF_SET(this->parent,parent);
@@ -359,7 +363,7 @@
359363 }
360364
361365 int
362-tinyState_::priority()
366+tinyState_::priority(tinyState * caller)
363367 {
364368 return TS_DEFAULT_PRIORITY;
365369 }
@@ -749,6 +753,8 @@
749753 tinyState_::listen(tinyState * listener,int type,TS_HANDLER_FUNC handler)
750754 {
751755 stdEventHandle * eh;
756+ if ( listener == 0 )
757+ return 0;
752758 eh = this->search_listen(type,listener);
753759 if ( eh )
754760 return eh;
@@ -759,6 +765,8 @@
759765 tinyState_::listen(tinyState * listener,int type)
760766 {
761767 stdEventHandle * eh;
768+ if ( listener == 0 )
769+ return 0;
762770 eh = this->search_listen(type,listener);
763771 if ( eh )
764772 return eh;
--- modules/tinyState/trunk/src/classes/ts/c++/tsApplication.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/tsApplication.cpp (revision 5993)
@@ -44,12 +44,12 @@
4444
4545 void inherit(tinyState* parent,TS_APPLICATION_FUNC func,void * arg);
4646 stdFrameWork * getFrameWork();
47+ tsThreadRoot * getThreadRoot();
4748 void setFrameWork(stdFrameWork * fw);
4849 void set_global(const char * name,stdObject *);
4950 void del_global(const char * name);
5051 stdObject * get_global(const char * name);
5152
52- int dinamic_priority;
5353 tsInsensitive * insensitive;
5454 tsGC * gc;
5555 tinyState * refCountQueue;
@@ -59,6 +59,7 @@
5959 uint8_t restart_flag;
6060 private:
6161 stdFrameWork * fwClass;
62+ tsThreadRoot * threadRoot;
6263 stdQueue<tsApplicationGlobal> * global;
6364 void (*initial_func)(tsApplication*,void*);
6465 void * initial_arg;
@@ -139,6 +140,14 @@
139140 invoke_listen(NEW stdEvent(TSE_UPDATED,ifThis,(INTEGER64)0));
140141 }
141142
143+
144+tsThreadRoot *
145+tsApplication_::getThreadRoot()
146+{
147+ return threadRoot;
148+}
149+
150+
142151 void
143152 tsApplication_::del_global(const char * name)
144153 {
@@ -179,6 +188,7 @@
179188 REF_SET(gc,NEW tsGC(ifThis));
180189 if ( this->initial_func )
181190 (*this->initial_func)(ifThis,this->initial_arg);
191+ REF_SET(threadRoot,NEW tsThreadRoot(ifThis));
182192 return rDO|INI_APPLICATION_START;
183193 }
184194 TS_STATE(INI_APPLICATION_START)
@@ -197,6 +207,15 @@
197207 }
198208 TS_STATE(FIN_TS_APPLICATION_START)
199209 {
210+ threadRoot->destroy();
211+ return rDO|FIN_THREAD_ROOT_LOOP;
212+}
213+TS_STATE(FIN_THREAD_ROOT_LOOP)
214+{
215+ if ( this->fwClass && this->fwClass->loop(ifThis) > 0 )
216+ return rDO;
217+ REF_SET(threadRoot,0);
218+
200219 eventHandler_flag = 0;
201220 insensitive->listen(ifThis,TSE_DESTROY);
202221 insensitive->destroy();
@@ -210,10 +229,15 @@
210229 return 0;
211230 if ( C_TEST(gc->state,C_ZOM) == 0 )
212231 return 0;
213- tsThread::stop();
232+ return rDO|FIN_TS_APPLICATION_WAIT2;
233+}
234+TS_STATE(FIN_TS_APPLICATION_WAIT2)
235+{
214236 REF_SET(this->fwClass,0);
215237 REF_SET(this->global,0);
216238 REF_SET(insensitive,0);
239+ REF_SET(gc,0);
240+ REF_SET(threadRoot,0);
217241 if ( restart_flag ) {
218242 restart_flag = 0;
219243 return rDO|INI_START;
--- modules/tinyState/trunk/src/classes/ts/c++/tsGC.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/tsGC.cpp (revision 5993)
@@ -22,12 +22,14 @@
2222 tinyState * parent);
2323
2424 void exe(tinyState * caller);
25+ virtual stdEvent * filter(stdEvent * ev);
26+
2527 private:
2628 protected:
2729 stdHalfOrderQueueTS * que;
2830 int last_pri;
29- int dinamic_priority;
3031
32+ unsigned priority_flag:1;
3133 sTimer timer;
3234 };
3335
@@ -72,11 +74,20 @@
7274 tsGC_::exe(tinyState * caller)
7375 {
7476 int pri;
75- que->ins(caller->priority(),caller);
77+ que->ins(caller->priority(ifThis),caller);
7678 wakeup();
7779 }
7880
7981
82+stdEvent *
83+tsGC_::filter(stdEvent * ev)
84+{
85+ if ( ev->type == TSE_PRIORITY )
86+ priority_flag = 1;
87+ return ev;
88+}
89+
90+
8091 /*******************************************
8192 STATE MACHINE
8293 ********************************************/
@@ -83,7 +94,6 @@
8394
8495 TS_STATE(INI_START)
8596 {
86- dinamic_priority = application->dinamic_priority;
8797 REF_SET(que,(NEW stdHalfOrderQueueTS()));
8898 return rDO|ACT_START;
8999 }
@@ -108,16 +118,16 @@
108118 int pri;
109119 if ( tsGC::timer_mode && timer.is_expire(ifThis) )
110120 return rDO|ACT_START;
111- if ( dinamic_priority != application->dinamic_priority ) {
112- dinamic_priority = application->dinamic_priority;
113- REF_SET(que,NEW stdHalfOrderQueueTS(que));
121+ if ( priority_flag ) {
122+ priority_flag = 0;
123+ REF_SET(que,NEW stdHalfOrderQueueTS(que,ifThis));
114124 }
115- ok = que->del();
125+ ok = que->del(0);
116126 if ( ok == 0 )
117127 return rDO|ACT_START;
118- pri = ok->priority();
128+ pri = ok->priority(0);
119129 if ( tsGC::timer_mode == 0 && last_pri && last_pri != pri ) {
120- que->ins(ok->priority(),ok);
130+ que->ins(ok->priority(ifThis),ok);
121131 return rDO|ACT_START;
122132 }
123133 ok->eventHandler(
--- modules/tinyState/trunk/src/classes/ts/c++/tsThread.cpp (revision 5992)
+++ modules/tinyState/trunk/src/classes/ts/c++/tsThread.cpp (revision 5993)
@@ -1,3 +1,10 @@
1+//
2+// after rev.5992.
3+//
4+//
5+
6+
7+
18 #include <pthread.h>
29 #include <sys/time.h>
310 #include <sys/types.h>
@@ -8,13 +15,7 @@
815 #include "ts/c++/stdQueue.h"
916 #include "ts/c++/co_tsThreadKill.h"
1017
11-#define R (0)
12-#define W (1)
1318
14-#define ACC_TIMER 2
15-#define DEC_TIMER 10
16-
17-
1819 CLASS_TINYSTATE(tsThread,tinyState)
1920
2021 #if 0
@@ -23,28 +24,15 @@
2324 #include "ts/c++/fwIO.h"
2425 #include "ts/c++/stdInterval.h"
2526 #include "ts/c++/sTimer.h"
27+#include "ts/c++/stdHalfOrderQueue.h"
2628
27-#define PIPE_SIZE 10
2829
29-class thrQueue;
30-
31-
32-#define THR_STATE_INIT 0
33-#define THR_STATE_RUN 1
34-#define THR_STATE_TERMINATE 4
35-#define THR_STATE_CALL_FUNC 5
36-#define THR_STATE_SUSPEND 6
37-
3830 class TS_THISCLASS : public TS_BASECLASS {
3931 public:
40- tsThread * thread_next;
41- tsThread * thread_prev;
42-
43- tsThread * que_next;
44-
4532 tsThread_(
4633 tinyState * parent,
4734 tsThread ** this_p,
35+ tsThreadRoot * _root,
4836 TS_STATE_TYPE pos_state,
4937 TS_STATE_TYPE thr_func,
5038 stdEvent * evt,
@@ -52,6 +40,7 @@
5240 void inherit(
5341 tinyState * parent,
5442 tsThread ** this_p,
43+ tsThreadRoot * _root,
5544 TS_STATE_TYPE pos_state,
5645 TS_STATE_TYPE thr_func,
5746 stdEvent * evt,
@@ -63,15 +52,6 @@
6352 void kill_finish();
6453 void thr_set_kill_state(pthread_t * me=0);
6554
66- static void ins_setup(stdThread * thr);
67- static void del_setup(stdThread * thr);
68- static int get_current_tsThread_nos();
69- static void stop();
70-
71- static int max_thread();
72- static void max_thread(int nos);
73-
74- static void * __tsThread_body(void * arg);
7555 void __tsThread_body_private();
7656
7757 void thr_call(THR_FUNC func,void * msg);
@@ -78,7 +58,9 @@
7858 void thr_event();
7959 void thr_throw(int ev_type);
8060 void thr_throw_invoke();
61+ void base_call_func(int force_ret);
8162
63+
8264 int thr_state;
8365 int thr_attr;
8466
@@ -89,49 +71,15 @@
8971 INTEGER64 ins_time;
9072 pthread_cond_t private_cond;
9173
74+
75+ tsThread * _thr_next;
76+ uint8_t thr_inQue;
9277 private:
78+ tsThreadRoot * root;
9379
94- static void _do_setup();
95- static void _do_cleanup();
80+ sTimer timer;
9681
97- fwIO * io;
9882
99- static tsThread * thread_head;
100-
101- static int initialize_flag;
102- static int max_thread_nos;
103- static int current_thread_nos;
104- static int current_tsThread_nos;
105- static int run_thread_nos;
106- static uint8_t thread_stop;
107- static pthread_mutex_t mu;
108- static pthread_cond_t cond;
109- static int pipe_fd[2];
110- static tsThread * host_thread;
111-
112- static thrQueue * ready;
113- static thrQueue * call_main;
114- static char buffer[PIPE_SIZE];
115- static int pipe_count;
116-
117- static INTEGER64 acc_start_time;
118- static INTEGER64 delta_start_time;
119- static INTEGER64 total_run_time;
120- static INTEGER64 last_dec_time;
121-
122- static stdQueue<stdThread> * setup_list;
123-
124- static void lock();
125- static void unlock();
126- static void cond_signal();
127- static void create();
128- static void launch();
129- static int cond_timed_wait();
130- void inc_max_thread_nos();
131- static void acc_max_thread_nos(int acc);
132-
133- static void _push_pipe();
134-
13583 stdEvent * initial_event;
13684 TS_STATE_TYPE pos_state;
13785 TS_STATE_TYPE thread_func;
@@ -140,14 +88,9 @@
14088 pthread_t * current_pthread;
14189 uint8_t kill_flag;
14290
143- void base_call_func(tsThread * target,int force_ret);
144-
14591 void _wait_private_cond();
14692
147- tsThread ** this_p;
14893 protected:
149- sTimer timer;
150- unsigned timer_flag:1;
15194 unsigned private_cond_init:1;
15295
15396 INTEGER64 throw_ev_flags;
@@ -154,47 +97,7 @@
15497 };
15598
15699
157-class thrQueue : public stdObject {
158-public:
159- tsThread * head;
160- tsThread * tail;
161- int count;
162100
163- thrQueue() {
164- }
165- ~thrQueue() {
166- }
167- void ins(tsThread * thr) {
168- if ( thr->que_in )
169- return;
170- thr->que_in = 1;
171- thr->que_next = 0;
172- if ( head == 0 )
173- head = tail = thr;
174- else {
175- tail->que_next = thr;
176- tail = thr;
177- }
178- thr->ins_time = stdInterval::now();
179- count ++;
180- }
181- tsThread * del() {
182- tsThread * ret;
183- if ( head == 0 )
184- return 0;
185- ret = head;
186- head = ret->que_next;
187- if ( head == 0 )
188- tail = 0;
189- if ( ret->que_in == 0 )
190- stdObject::panic("NON QUEUED OBJECT !!");
191- ret->que_in = 0;
192- count --;
193- return ret;
194- }
195-};
196-
197-
198101 TS_END_IMPLEMENT
199102
200103 TS_BEGIN_INTERFACE
@@ -211,120 +114,17 @@
211114
212115
213116
214-/*******************************************
215- RELATED FUNCTIONS
216-********************************************/
217117
218-stdThread::stdThread(stdObject *parent)
219-{
220- REF_SET(this->parent,parent);
221-}
222-stdThread::~stdThread()
223-{
224- REF_SET(parent,0);
225-}
226-void
227-stdThread::setup()
228-{
229-}
230-void
231-stdThread::cleanup()
232-{
233-}
234-
235118 /*******************************************
236119 PUBLIC FUNCTIONS
237120 ********************************************/
238121
239-tsThread *
240-tsThread_::thread_head;
241122
242-int
243-tsThread_::initialize_flag;
244-int
245-tsThread_::max_thread_nos = 1;
246-int
247-tsThread_::current_thread_nos;
248-int
249-tsThread_::run_thread_nos;
250-int
251-tsThread_::current_tsThread_nos;
252-pthread_mutex_t
253-tsThread_::mu;
254-pthread_cond_t
255-tsThread_::cond;
256-int
257-tsThread_::pipe_fd[2];
258-uint8_t
259-tsThread_::thread_stop;
260123
261-tsThread *
262-tsThread_::host_thread;
263-thrQueue *
264-tsThread_::ready;
265-thrQueue *
266-tsThread_::call_main;
267-char
268-tsThread_::buffer[PIPE_SIZE];
269-INTEGER64
270-tsThread_::acc_start_time;
271-INTEGER64
272-tsThread_::delta_start_time;
273-INTEGER64
274-tsThread_::total_run_time;
275-INTEGER64
276-tsThread_::last_dec_time;
277-int
278-tsThread_::pipe_count;
279-stdQueue<stdThread> *
280-tsThread_::setup_list;
281-
282-void
283-tsThread_::ins_setup(stdThread * thr)
284-{
285- lock();
286- if ( setup_list == 0 )
287- REF_SET(setup_list,(NEW stdQueue<stdThread>()));
288- setup_list->ins(MAX_INTEGER64,thr);
289- unlock();
290-}
291-
292-void
293-tsThread_::del_setup(stdThread * thr)
294-{ lock();
295- if ( setup_list )
296- setup_list->del(thr,0);
297- unlock();
298-}
299-
300-void
301-tsThread_::_do_setup()
302-{
303-stdQueueElement<stdThread> * elp;
304- if ( setup_list )
305- for ( elp = setup_list->head ; elp ; elp = elp->next )
306- elp->data->setup();
307-}
308-
309-void
310-tsThread_::_do_cleanup()
311-{
312-stdQueueElement<stdThread> * elp;
313- if ( setup_list )
314- for ( elp = setup_list->head ; elp ; elp = elp->next )
315- elp->data->cleanup();
316-}
317-
318-int
319-tsThread_::get_current_tsThread_nos()
320-{
321- return current_tsThread_nos;
322-}
323-
324-
325124 tsThread_::tsThread_(
326125 tinyState * parent,
327126 tsThread ** this_p,
127+ tsThreadRoot * _root,
328128 TS_STATE_TYPE pos_state,
329129 TS_STATE_TYPE thr_func,
330130 stdEvent * evt,
@@ -332,27 +132,12 @@
332132 :
333133 tinyState_(parent)
334134 {
335- if ( initialize_flag == 0 ) {
336- initialize_flag = 1;
337- pthread_mutex_init(&mu,0);
338- pthread_cond_init(&cond,0);
339- if ( soPIPE(pipe_fd) < 0 ) {
340- perror("THREAD PIPE");
341- stdObject::panic("THREAD PIPE");
342- }
343- REF_SET(ready,NEW thrQueue());
344- REF_SET(call_main,NEW thrQueue());
345- }
346- current_tsThread_nos ++;
347-
348- this->this_p = this_p;
349135 this->pos_state = pos_state;
350136 thr_attr = attr;
351137 thr_state = THR_STATE_INIT;
352138 REF_SET(initial_event,evt);
139+ REF_SET(root,_root);
353140 thread_func = thr_func;
354- if ( max_thread_nos == 0 )
355- max_thread(1);
356141 }
357142
358143 void
@@ -359,22 +144,13 @@
359144 tsThread_::inherit(
360145 tinyState * parent,
361146 tsThread ** this_p,
147+ tsThreadRoot * _root,
362148 TS_STATE_TYPE pos_state,
363149 TS_STATE_TYPE thr_func,
364150 stdEvent * evt,
365151 int attr)
366152 {
367- if ( thread_head == 0 ) {
368- REF_SET(thread_head,ifThis);
369- REF_SET(thread_next,ifThis);
370- REF_SET(thread_prev,ifThis);
371- }
372- else {
373- REF_SET(thread_next,thread_head);
374- REF_SET(thread_prev,thread_head->thread_prev);
375- REF_SET(thread_next->thread_prev,ifThis);
376- REF_SET(thread_prev->thread_next,ifThis);
377- }
153+ REF_SET(*this_p,ifThis);
378154 this->TS_BASECLASS::inherit(parent);
379155 }
380156
@@ -384,15 +160,15 @@
384160 {
385161 if ( ev_type == 0 )
386162 return;
387- lock();
163+ root->lock();
388164 if ( throw_ev_flags & (1LL<<ev_type) ) {
389- unlock();
165+ root->unlock();
390166 return;
391167 }
392168 throw_ev_flags |= (1LL<<ev_type);
393- call_main->ins(ifThis);
394- _push_pipe();
395- unlock();
169+ root->_insQue(ifThis);
170+ root->_push_pipe();
171+ root->unlock();
396172 }
397173
398174 void
@@ -400,10 +176,10 @@
400176 {
401177 int ev_type;
402178 INTEGER64 tef;
403- lock();
179+ root->lock();
404180 tef = throw_ev_flags;
405181 throw_ev_flags = 0;
406- unlock();
182+ root->unlock();
407183 for ( ; tef ; )
408184 for ( ev_type = 1 ; tef >= (1LL<<ev_type) ; ev_type ++ ) {
409185 if ( !(tef & (1LL<<ev_type)) ) {
@@ -418,7 +194,7 @@
418194 void
419195 tsThread_::thr_call(THR_FUNC func,void*msg)
420196 {
421- lock();
197+ root->lock();
422198 if ( private_cond_init == 0 ) {
423199 pthread_cond_init(&private_cond,0);
424200 private_cond_init = 1;
@@ -426,322 +202,62 @@
426202 thr_call_func = func;
427203 thr_call_msg = msg;
428204 thr_state = THR_STATE_CALL_FUNC;
429- call_main->ins(ifThis);
430- _push_pipe();
205+ root->_insQue(ifThis);
206+ root->_push_pipe();
431207 _wait_private_cond();
432- unlock();
208+ root->unlock();
433209 }
434210
435211 void
436-tsThread_::thr_event()
437-{
438- lock();
439- if ( thr_state != THR_STATE_SUSPEND ) {
440- unlock();
441- return;
442- }
443- unlock();
444- base_call_func(ifThis,1);
445-}
446-
447-
448-TS_STATE_TYPE
449-tsThread::thr_call_state(tinyState * THIS,void * msg)
450-{
451-THR_CALL_TYPE * c_msg;
452-TS_STATE_TYPE ret;
453- c_msg = (THR_CALL_TYPE*)msg;
454- c_msg->ret = ret = THIS->do_thread(c_msg->call,
455- NEW stdEvent(TSE_PACKET,
456- THIS,
457- c_msg->msg));
458- return ret;
459-}
460-
461-
462-
463-void
464-tsThread_::base_call_func(tsThread * target,int force_ret)
465-{
466-TS_STATE_TYPE ret;
467- if ( target->thr_call_func )
468- ret = (*target->thr_call_func)(target->parent,target->thr_call_msg);
469- else ret = force_ret;
470- lock();
471- if ( ret == 0 ) {
472- target->thr_state = THR_STATE_SUSPEND;
473- }
474- else {
475- target->thr_state = THR_STATE_RUN;
476- pthread_cond_signal(&target->private_cond);
477- }
478- unlock();
479-}
480-
481-void
482212 tsThread_::_wait_private_cond()
483213 {
484214 int ret;
485215 for ( ; thr_state != THR_STATE_RUN ; ) {
486- pthread_cond_wait(&private_cond,&mu);
216+ pthread_cond_wait(&private_cond,&root->mu);
487217 }
488218 }
489219
490-int
491-tsThread_::max_thread()
492-{
493- return max_thread_nos;
494-}
495-void
496-tsThread_::max_thread(int nos)
497-{
498-}
499220
500221 void
501-tsThread_::lock()
222+tsThread_::thr_event()
502223 {
503- pthread_mutex_lock(&mu);
504-}
505-
506-void
507-tsThread_::unlock()
508-{
509- pthread_mutex_unlock(&mu);
510-}
511-
512-void
513-tsThread_::cond_signal()
514-{
515- pthread_cond_signal(&cond);
516-}
517-
518-
519-int
520-tsThread_::cond_timed_wait()
521-{
522-struct timespec timeout;
523-struct timeval now;
524-int ret;
525- gettimeofday(&now,0);
526- timeout.tv_sec = now.tv_sec + DEC_TIMER;
527- timeout.tv_nsec = now.tv_usec * 1000;
528- for ( ; ; ) {
529- ret = pthread_cond_timedwait(&cond,&mu,&timeout);
530- switch ( ret ) {
531- case ETIMEDOUT:
532- return -1;
533- case EINTR:
534- continue;
535- default:
536- return 0;
537- }
538- break;
539- }
540-}
541-
542-void
543-tsThread_::create()
544-{
545-pthread_attr_t phy_attr;
546-pthread_t phy_thread;
547- pthread_attr_init(&phy_attr);
548- pthread_attr_setdetachstate(&phy_attr,PTHREAD_CREATE_DETACHED);
549- pthread_create(&phy_thread,&phy_attr,__tsThread_body,0);
550-}
551-
552-void
553-tsThread_::launch()
554-{
555- if ( ready->head == 0 )
224+ root->lock();
225+ if ( thr_state != THR_STATE_SUSPEND ) {
226+ root->unlock();
556227 return;
557- if ( max_thread_nos > 0 ) {
558- if ( current_thread_nos >= max_thread_nos ) {
559-if ( run_thread_nos >= current_thread_nos )
560-::printf("--------------------------------------------------- LAUNCH-FULL %i %i\n",run_thread_nos,current_thread_nos);
561- cond_signal();
562- return;
563- }
564- current_thread_nos ++;
565- create();
566228 }
567- else if ( current_thread_nos < current_tsThread_nos ) {
568- current_thread_nos ++;
569- create();
570- }
571- cond_signal();
229+ root->unlock();
230+ base_call_func(1);
572231 }
573232
574-void
575-tsThread_::stop()
576-{
577- lock();
578- thread_stop = 1;
579- for ( ; current_thread_nos ; ) {
580- cond_signal();
581- cond_timed_wait();
582- }
583- unlock();
584-}
585233
586-
587234 void
588-tsThread_::acc_max_thread_nos(int inc)
235+tsThread_::base_call_func(int force_ret)
589236 {
590-INTEGER64 now;
591- if ( delta_start_time ) {
592- now = stdInterval::now();
593-//::printf("acc_max_thread_nos %i %lli\n",run_thread_nos,now - delta_start_time);
594- total_run_time +=
595- (now - delta_start_time)
596- * run_thread_nos;
597- delta_start_time = now;
237+TS_STATE_TYPE ret;
238+ if ( thr_call_func )
239+ ret = (*thr_call_func)(parent,thr_call_msg);
240+ else ret = force_ret;
241+ root->lock();
242+ if ( ret == 0 ) {
243+ thr_state = THR_STATE_SUSPEND;
598244 }
599- if ( inc > 0 )
600- run_thread_nos ++;
601- else if ( inc < 0 )
602- run_thread_nos --;
603-}
604-
605-void
606-tsThread_::inc_max_thread_nos()
607-{
608-INTEGER64 now,interval;
609-int launch_flag;
610- lock();
611- launch_flag = 0;
612- for ( ; ; ) {
613- now = stdInterval::now();
614- if ( acc_start_time == 0 ) {
615- acc_start_time = now;
616- delta_start_time = now;
617- total_run_time = 0;
618- timer_flag = 1;
619- timer.start(ifThis,ACC_TIMER*1000*1000,TSE_TIMER);
620- break;
621- }
622- if ( timer_flag == 0 ) {
623- INTEGER64 dif;
624- dif = ACC_TIMER*1000*1000 - now + acc_start_time;
625- if ( dif <= 0 )
626- goto expire;
627- timer_flag = 1;
628- timer.start(ifThis,dif,TSE_TIMER);
629- break;
630- }
631- if ( timer.is_expire(ifThis) ) {
632- INTEGER64 p;
633-
634- expire:
635- acc_max_thread_nos(0);
636- p = total_run_time * 10 /
637- ((now - acc_start_time) );
638-//::printf("MAX THREAD NOS-1 %lli %lli %lli\n",p,total_run_time,now - acc_start_time);
639- p = (p + 32)/10;
640- if ( p < max_thread_nos && max_thread_nos > 1 ) {
641- if ( now - last_dec_time >=
642- DEC_TIMER*1000*1000 ) {
643- max_thread_nos --;
644- last_dec_time = now;
645- }
646- }
647- else if ( p > max_thread_nos ) {
648- max_thread_nos ++;
649- launch_flag = 1;
650- last_dec_time = now;
651- }
652- else
653- last_dec_time = now;
654-//::printf("MAX THREAD NOS-2 %lli %i\n",p,max_thread_nos);
655- acc_start_time = now;
656- total_run_time = 0;
657- timer_flag = 1;
658- timer.start(ifThis,ACC_TIMER*1000*1000,TSE_TIMER);
659- break;
660- }
661- break;
245+ else {
246+ thr_state = THR_STATE_RUN;
247+ pthread_cond_signal(&private_cond);
662248 }
663- if ( launch_flag )
664- launch();
665- unlock();
249+ root->unlock();
666250 }
667251
668-void *
669-tsThread_::__tsThread_body(void * arg)
670-{
671-tsThread * target;
672-pthread_t self_id;
673-
674- self_id = pthread_self();
675- lock();
676- _do_setup();
677- for ( ; ; ) {
678- target = ready->del();
679- if ( target == 0 ) {
680- if ( (max_thread_nos > 0 &&
681- current_thread_nos > max_thread_nos) ||
682- thread_stop ||
683- cond_timed_wait() < 0 ) {
684- target = ready->del();
685- if ( target )
686- goto exec;
687- _do_cleanup();
688- current_thread_nos --;
689- if ( current_thread_nos == 0 )
690- cond_signal();
691- unlock();
692- return 0;
693- }
694- continue;
695- }
696- exec:
697- acc_max_thread_nos(1);
698-//::printf("TH ST %i %i %i %i\n",ready->count,max_thread_nos,current_thread_nos,run_thread_nos);
699- target->thr_set_kill_state(&self_id);
700- target->__tsThread_body_private();
701- target->thr_set_kill_state();
702-//::printf("TH ED %i %i %i %i\n",ready->count,max_thread_nos,current_thread_nos,run_thread_nos);
703- call_main->ins(target);
704- acc_max_thread_nos(-1);
705- _push_pipe();
706- }
707- _do_cleanup();
708- unlock();
709- return 0;
710-}
711-
712252 void
713-tsThread_::_push_pipe()
714-{
715-char push;
716-int ret;
717- push = 0;
718- if ( pipe_count <= 0 ) {
719- for ( ; ; ) {
720- ret = ::write(pipe_fd[W],&push,1);
721- if ( ret < 0 ) {
722- if ( errno == EINTR )
723- continue;
724- perror("THREAD WRITE PIPE ERROR");
725- stdObject::panic("cannot write 1 byte\n");
726- }
727- if ( ret == 0 ) {
728- stdObject::panic("THREAD WRITE END PIPE ?\n");
729- }
730- break;
731- }
732- pipe_count ++;
733- }
734-}
735-
736-void
737253 tsThread_::__tsThread_body_private()
738254 {
739255 TS_STATE_TYPE state;
740- thr_state = THR_STATE_RUN;
256+// thr_state = THR_STATE_RUN;
741257 for ( ; ; ) {
742- unlock();
258+ root->unlock();
743259 state = parent->do_thread(thread_func,initial_event);
744- lock();
260+ root->lock();
745261 switch ( state ) {
746262 case 0:
747263 terminate_state = pos_state;
@@ -761,7 +277,7 @@
761277 tsThread_::kill(int sig)
762278 {
763279 int ret;
764- lock();
280+ root->lock();
765281 if ( current_pthread )
766282 pthread_kill(*current_pthread,sig);
767283 ret = kill_flag;
@@ -777,7 +293,7 @@
777293 case KF_CATCH_REQUEST:
778294 break;
779295 }
780- unlock();
296+ root->unlock();
781297 return ret;
782298 }
783299
@@ -799,7 +315,7 @@
799315 {
800316 int ret;
801317 ret = kill_flag;
802- lock();
318+ root->lock();
803319 switch ( kill_flag ) {
804320 case KF_IDLE:
805321 kill_flag = KF_CATCH;
@@ -811,13 +327,13 @@
811327 case KF_CATCH_REQUEST:
812328 break;
813329 }
814- unlock();
815- return 0;
330+ root->unlock();
331+ return ret;
816332 }
817333 void
818334 tsThread_::kill_finish()
819335 {
820- lock();
336+ root->lock();
821337 switch ( kill_flag ) {
822338 case KF_IDLE:
823339 case KF_REQUEST:
@@ -829,116 +345,76 @@
829345 kill_flag = KF_REQUEST;
830346 break;
831347 }
832- unlock();
348+ root->unlock();
833349 }
834350
351+
835352 /*******************************************
836353 STATE MACHINE
837354 ********************************************/
838355
839-
840-TS_STATE(INI_TINYSTATE_FINISH)
356+TS_STATE(INI_START)
841357 {
842- REF_SET(*this_p,ifThis);
843- REF_SET(io,dynamic_cast<fwIO*>(application->getFrameWork()));
844- lock();
845- ready->ins(ifThis);
846- launch();
847- unlock();
848-
849358 return rDO|ACT_START;
850359 }
851-TS_STATE(ACT_TINYSTATE_START)
360+TS_STATE(ACT_START)
852361 {
853- if ( host_thread == 0 ) {
854- REF_SET(host_thread,ifThis);
855- return rDO|ACT_HOST;
856- }
857- if ( host_thread == ifThis )
858- return rDO|ACT_HOST;
859- return ACT_START;
362+ root->ins(ifThis);
363+ return rDO|ACT_TOP_WAIT;
860364 }
861-TS_STATE(ACT_HOST)
365+TS_STATE(ACT_TOP_WAIT)
862366 {
863- io->read(ifThis,pipe_fd[R]);
864- inc_max_thread_nos();
865- return ACT_HOST_RET;
367+ if ( is_destroyed() )
368+ return rDO|FIN_START;
369+ if ( thr_state != THR_STATE_INIT )
370+ return rDO|ACT_FINISH_WAIT;
371+ if ( root->get_readyTop() != ifThis )
372+ return 0;
373+ timer.start(ifThis,ACC_TIMER*1000*1000);
374+ return rDO|ACT_RUN_WAIT;
866375 }
867-TS_STATE(ACT_HOST_RET)
376+TS_STATE(ACT_RUN_WAIT)
868377 {
869-tsThread * target;
870-int er;
871- inc_max_thread_nos();
872- if ( ev->type != TSE_RETURN )
873- return 0;
874- lock();
875- for ( ; (er = ::read(pipe_fd[R],buffer,PIPE_SIZE)) < 0 ; ) {
876- if ( errno == EINTR )
877- continue;
878- perror("THREAD READ PIPE ERROR !!");
879- stdObject::panic("THRAED READ PIPE ERROR !!");
378+ if ( thr_state != THR_STATE_INIT )
379+ return rDO|ACT_FINISH_WAIT;
380+ if ( root->get_readyTop() != ifThis )
381+ return rDO|ACT_TOP_WAIT;
382+ if ( timer.is_expire(ifThis) ) {
383+ root->create();
384+ return rDO|ACT_FINISH_WAIT;
880385 }
881- pipe_count -= er;
882- unlock();
883- for ( ; ; ) {
884- lock();
885- target = call_main->del();
886- unlock();
887- if ( target == 0 )
888- break;
889- target->thr_throw_invoke();
890- switch ( target->thr_state ) {
891- case THR_STATE_CALL_FUNC:
892- base_call_func(target,0);
893- break;
894- case THR_STATE_TERMINATE:
895- target->destroy();
896- break;
897- }
898- }
899- return rDO|ACT_START;
386+ return 0;
900387 }
388+TS_STATE(ACT_FINISH_WAIT)
389+{
390+ if ( is_destroyed() )
391+ return rDO|FIN_START;
392+ return 0;
393+}
901394
902395 TS_STATE(FIN_START)
903396 {
397+ root->del(ifThis);
398+ return rDO|FIN_WAIT;
399+}
400+TS_STATE(FIN_WAIT)
401+{
402+ root->lock();
403+ if ( thr_inQue ) {
404+ root->unlock();
405+ return 0;
406+ }
407+ root->unlock();
408+
904409 parent->eventHandler(
905410 NEW stdEvent(TSE_THREAD,ifThis,
906411 (INTEGER64)terminate_state));
907- if ( thread_head == ifThis ) {
908- if ( thread_head == thread_next ) {
909- REF_SET(thread_head,0);
910- REF_SET(thread_next,0);
911- REF_SET(thread_prev,0);
912- return rDO|FIN_FREE_MUTEX;
913- }
914- REF_SET(thread_head,thread_next);
915- }
916- REF_SET(thread_prev->thread_next,thread_next);
917- REF_SET(thread_next->thread_prev,thread_prev);
918- REF_SET(thread_next,0);
919- REF_SET(thread_prev,0);
920412
921- REF_SET(io,0);
922- return rDO|FIN_FREE_MUTEX;
923-}
924-TS_STATE(FIN_FREE_MUTEX)
925-{
926413 REF_SET(initial_event,0);
927414 if ( private_cond_init )
928415 pthread_cond_destroy(&private_cond);
929416
930- if ( host_thread == 0 || host_thread == ifThis) {
931- if ( thread_head ) {
932- REF_SET(host_thread,thread_head);
933- host_thread->wakeup();
934- }
935- else {
936- REF_SET(host_thread,0);
937- }
938- }
939- current_tsThread_nos --;
940- if ( current_tsThread_nos == 0 )
941- application->wakeup();
417+ REF_SET(root,0);
942418 return rDO|FIN_TINYSTATE_START;
943419 }
944420
--- modules/tinyState/trunk/src/h/ts/c++/stdArrayQueue.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/stdArrayQueue.h (revision 5993)
@@ -175,6 +175,12 @@
175175 wait_count ++;
176176 pthread_cond_wait(&cond,&mu);
177177 }
178+#ifdef AQ_DEBUG_MODE
179+ if ( ix->ary[tail%ix->length()] == 0 &&
180+ debug_list->ary[tail%a->length()] ) {
181+ stdObject::panic("invalid debug_list");
182+ }
183+#endif
178184 tail ++;
179185 return 0;
180186 }
@@ -214,6 +220,7 @@
214220 return 0;
215221 }
216222 int detach(unsigned int p,sAQindex<__TYPE> * org) {
223+ int ins_flag = 0;
217224 if ( head < tail ) {
218225 if ( head <= p && p < tail )
219226 return AQE_ERROR;
@@ -224,6 +231,7 @@
224231 return AQE_ERROR;
225232 if ( ix->ary[p%ix->length()] == AQ_INS ) {
226233 ix->ary[p%ix->length()] = 0;
234+ ins_flag = 1;
227235 }
228236 else {
229237 ix->ary[p%ix->length()] --;
@@ -239,7 +247,12 @@
239247 pp = &(*pp)->debug_next);
240248 if ( *pp )
241249 *pp = org->debug_next;
242-
250+ else if ( ins_flag == 0 )
251+ stdObject::panic("no object that detach");
252+ if ( ix->ary[p%ix->length()] == 0 &&
253+ debug_list->ary[p%a->length()] ) {
254+ stdObject::panic("invalid debug_list");
255+ }
243256 #endif
244257 return 0;
245258 }
@@ -274,16 +287,38 @@
274287 sAQindex() {
275288 pos = 0;
276289 ptr = 0;
290+ a = 0;
291+ proc_flag = 0;
292+#ifdef AQ_DEBUG_MODE
293+ debug_next = 0;
294+ _line = 0;
295+ _file = 0;
296+ _stamp = this;
297+#endif
277298 }
278299 sAQindex(sPtr<stdArrayQueue<__TYPE> > aa) {
279300 pos = 0;
280301 ptr = 0;
281302 a = aa;
303+ proc_flag = 0;
304+#ifdef AQ_DEBUG_MODE
305+ debug_next = 0;
306+ _line = 0;
307+ _file = 0;
308+ _stamp = this;
309+#endif
282310 }
283311 sAQindex(const sAQindex & inp) {
284312 a = inp.a;
285313 pos = 0;
286314 ptr = 0;
315+ proc_flag = 0;
316+#ifdef AQ_DEBUG_MODE
317+ debug_next = 0;
318+ _line = 0;
319+ _file = 0;
320+ _stamp = this;
321+#endif
287322 if ( a.is_clear() ) {
288323 pos = inp.pos;
289324 return;
@@ -299,6 +334,10 @@
299334 a->lock();
300335 detach();
301336 a->unlock();
337+#ifdef AQ_DEBUG_MODE
338+ if ( _stamp != this )
339+ stdObject::panic("not equal stamp");
340+#endif
302341 }
303342 int status() {
304343 if ( a.is_clear() )
@@ -398,6 +437,9 @@
398437 detach();
399438 pos = ret;
400439 ptr = a->get(pos);
440+ if ( proc_flag )
441+ stdObject::panic("proc_flag ins");
442+ proc_flag = 1;
401443 return 0;
402444 }
403445 int del() {
@@ -425,12 +467,65 @@
425467 return a->pop();
426468 }
427469 sAQindex& operator=(sAQindex inp) {
428- if ( a ) {
470+sPtr<stdArrayQueue<__TYPE> > prev_a;
471+int prev_pos;
472+__TYPE * prev_ptr;
473+prev_a = a;
474+prev_pos = pos;
475+prev_ptr = ptr;
476+int prev_tt = 0;
477+
478+ if ( a.is_clear() ) {
479+if ( ptr )
480+stdObject::panic("???1");
481+ if ( inp.a.is_clear() ) {
482+ pos = inp.pos;
483+ }
484+ else {
485+ a = inp.a;
486+ a->lock();
487+ pos = inp.pos;
488+ attach();
489+ a->unlock();
490+ }
491+ }
492+ else {
493+ if ( inp.a.is_clear() ) {
494+ a->lock();
495+ detach();
496+ a->unlock();
497+ pos = inp.pos;
498+ }
499+ else {
500+ if ( a == inp.a ) {
501+ a->lock();
502+ detach();
503+ pos = inp.pos;
504+ attach();
505+ a->unlock();
506+ }
507+ else {
508+ a->lock();
509+ inp.a->lock();
510+ detach();
511+ a->unlock();
512+
513+ a = inp.a;
514+ pos = inp.pos;
515+ attach();
516+ a->unlock();
517+ }
518+ }
519+ }
520+ return *this;
521+
522+ if ( !a.is_clear() ) {
523+prev_tt = 1;
429524 a->lock();
430525 detach();
431526 a->unlock();
432527 }
433- if ( inp.a )
528+ if ( !inp.a.is_clear() )
434529 a = inp.a;
435530 a->lock();
436531 pos = inp.pos;
@@ -529,7 +624,9 @@
529624 sAQindex<__TYPE> * debug_next;
530625 const char * _file;
531626 int _line;
627+ sAQindex<__TYPE> * _stamp;
532628 #endif
629+ unsigned proc_flag:1;
533630
534631 sPtr<stdArrayQueue<__TYPE> > a;
535632 int pos;
@@ -537,11 +634,17 @@
537634
538635 int attach() {
539636 int ret;
540- if ( ptr )
637+ if ( ptr ) {
638+ stdObject::panic("double attach");
541639 return 0;
640+ }
641+ if ( this != _stamp )
642+ stdObject::panic("different stamp");
542643 ret = a->attach(pos,this);
543- if ( ret == 0 )
644+ if ( ret == 0 ) {
544645 ptr = a->get(pos);
646+ proc_flag = 1;
647+ }
545648 else ptr = 0;
546649 return ret;
547650 }
@@ -548,6 +651,9 @@
548651 int detach() {
549652 if ( ptr == 0 )
550653 return 0;
654+ if ( proc_flag == 0 )
655+ stdObject::panic("no attach detach");
656+ proc_flag = 0;
551657 a->detach(pos,this);
552658 ptr = 0;
553659 return 0;
--- modules/tinyState/trunk/src/h/ts/c++/stdEvent.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/stdEvent.h (revision 5993)
@@ -79,7 +79,8 @@
7979 #define TSE_THREAD 17
8080 #define TSE_PACKET 18
8181 #define TSE_ACCESS 19
82-#define TSE_MAX 20
82+#define TSE_PRIORITY 20
83+#define TSE_MAX 21
8384
8485 #define TSE_EVM(x) (1<<(x))
8586
--- modules/tinyState/trunk/src/h/ts/c++/stdHalfOrderQueue.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/stdHalfOrderQueue.h (revision 5993)
@@ -33,6 +33,11 @@
3333 stdHalfOrderNode * __top() {
3434 return top;
3535 };
36+ stdObject * getTop() {
37+ if ( top )
38+ return top->data;
39+ return 0;
40+ }
3641 int count();
3742 protected:
3843 static void _ins(stdHalfOrderNode *,int key,stdObject * data);
--- modules/tinyState/trunk/src/h/ts/c++/stdHalfOrderQueueTS.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/stdHalfOrderQueueTS.h (revision 5993)
@@ -9,8 +9,11 @@
99 class stdHalfOrderQueueTS : public stdHalfOrderQueue {
1010 public:
1111 stdHalfOrderQueueTS();
12- stdHalfOrderQueueTS(stdHalfOrderQueueTS * q);
13- tinyState * del();
12+ stdHalfOrderQueueTS(stdHalfOrderQueueTS * q,tinyState * caller);
13+ tinyState * del(tinyState * caller);
14+ tinyState * getTop() {
15+ return dynamic_cast<tinyState*>(stdHalfOrderQueue::getTop());
16+ }
1417 };
1518
1619 #endif
--- modules/tinyState/trunk/src/h/ts/c++/stdQueue.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/stdQueue.h (revision 5993)
@@ -46,6 +46,7 @@
4646 stdQueueElement<__TYPE> * tail;
4747
4848 int count;
49+ unsigned insNeq:1;
4950
5051
5152
@@ -80,8 +81,14 @@
8081 else {
8182 elp = &head;
8283 for ( ; *elp ; elp = &(*elp)->next ) {
83- if ( (*elp)->key >= key )
84- break;
84+ if ( insNeq ) {
85+ if ( (*elp)->key > key )
86+ break;
87+ }
88+ else {
89+ if ( (*elp)->key >= key )
90+ break;
91+ }
8592 }
8693 REF_SET(el->next,*elp);
8794 REF_SET(*elp,el);
@@ -362,6 +369,7 @@
362369 {
363370 this->head = this->tail = 0;
364371 this->count = 0;
372+ this->insNeq = q->insNeq;
365373 q->check(this,copy_stdQueue);
366374 }
367375
@@ -383,8 +391,10 @@
383391 {
384392 this->head = this->tail = 0;
385393 this->count = 0;
394+ this->insNeq = 0;
386395 if ( q == 0 )
387396 return;
397+ this->insNeq = q->insNeq;
388398 q->check(this,copy_stdQueue);
389399 }
390400
--- modules/tinyState/trunk/src/h/ts/c++/tsApplication.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/tsApplication.h (revision 5993)
@@ -7,6 +7,7 @@
77 #include "ts/c++/stdString.h"
88 #include "ts/c++/tsInsensitive.h"
99 #include "ts/c++/tsGC.h"
10+#include "ts/c++/tsThreadRoot.h"
1011
1112 class tsApplication;
1213 class tsApplication_;
--- modules/tinyState/trunk/src/h/ts/c++/tsThread.h (revision 5992)
+++ modules/tinyState/trunk/src/h/ts/c++/tsThread.h (revision 5993)
@@ -5,21 +5,13 @@
55
66 #include <pthread.h>
77 #include <signal.h>
8+#include "ts/c++/tsThreadRoot.h"
89
10+class tsThreadRoot;
911 class tinyState;
1012 typedef TS_STATE_TYPE (*THR_FUNC)(tinyState * THIS,void*msg);
1113
1214
13-class stdThread : public stdObject {
14-public:
15- stdThread(stdObject * parent);
16- ~stdThread();
17- virtual void setup();
18- virtual void cleanup();
19-private:
20- stdObject * parent;
21-};
22-
2315 #include "ts/c++/tinyState.h"
2416 #include "_ts/c++/tsThread_pb.h"
2517
@@ -35,7 +27,8 @@
3527 inline TS_STATE_TYPE FORCEINLINE \
3628 TS_THISCLASS::_state_##thrState(stdEvent*ev) \
3729 { \
38- NEW tsThread(ifThis,&thread,thrState,thrState##__thread,ev,thread_attr); \
30+ NEW tsThread(ifThis,&thread,application->getThreadRoot(), \
31+ thrState,thrState##__thread,ev,thread_attr); \
3932 return thrState##__thread_wait; \
4033 } \
4134 TS_STATE_TYPE \
Show on old repository browser