• R/O
  • SSH
  • HTTPS

globalbase: Commit


Commit MetaInfo

Revisão5988 (tree)
Hora2019-11-24 23:04:27
Autorjoshua

Mensagem de Log

sPtr and mutex

Mudança Sumário

Diff

--- modules/tinyState/trunk/src/classes/ts/c++/stdObject.cpp (revision 5987)
+++ modules/tinyState/trunk/src/classes/ts/c++/stdObject.cpp (revision 5988)
@@ -17,24 +17,117 @@
1717 stdObject::refMutex;
1818 uint8_t
1919 stdObject::refMutex_init;
20+uint8_t
21+stdObject::refMutex_debug;
2022 pthread_t
2123 stdObject::refMutex_thread;
24+int
25+stdObject::refMutex_count;
2226
2327 stdObject::stdObject()
2428 {
29+ refLock();
2530 this->ref = 0;
2631 this->insert_zombie_list();
27-
32+ refUnlock();
2833 }
2934
3035
3136 stdObject::~stdObject()
3237 {
38+ refLock();
3339 this->delete_zombie_list();
40+ refUnlock();
3441 }
3542
3643
44+void
45+stdObject::refLock() {
46+int er;
47+pthread_t tid;
3748
49+ if ( refMutex_init == 0 ) {
50+ pthread_mutexattr_t attr;
51+ pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
52+ if ( (er = pthread_mutex_init(&refMutex,&attr)) ) {
53+ refMutex_init = 2;
54+ if ( (er = pthread_mutex_init(&refMutex,0)) ) {
55+ fprintf(stderr,"%s\n",strerror(er));
56+ stdObject::panic("refLock-0");
57+ }
58+ }
59+ else
60+ refMutex_init = 1;
61+ }
62+ if ( refMutex_init == 1 ) {
63+ if ( (er=pthread_mutex_lock(&refMutex)) ) {
64+ fprintf(stderr,"%s\n",strerror(er));
65+ stdObject::panic("refLock-0");
66+ }
67+ }
68+ else {
69+ tid = pthread_self();
70+if ( refMutex_debug )
71+::printf("refLock-IN %p %p %i\n",tid,refMutex_thread,refMutex_count);
72+ if ( refMutex_thread == tid ) {
73+ refMutex_count ++;
74+if ( refMutex_debug )
75+::printf("refLock-0 %p %i\n",refMutex_thread,refMutex_count);
76+ return;
77+ }
78+ if ( (er=pthread_mutex_lock(&refMutex)) ) {
79+ fprintf(stderr,"%s\n",strerror(er));
80+ stdObject::panic("refLock-0");
81+ }
82+ if ( refMutex_count ) {
83+ if ( refMutex_thread != tid )
84+ stdObject::panic("refLock-1");
85+ }
86+ else {
87+ if ( refMutex_thread != 0 )
88+ stdObject::panic("refLock-2");
89+ }
90+ refMutex_thread = tid;
91+ refMutex_count ++;
92+if ( refMutex_debug )
93+::printf("refLock-1 %p %i\n",refMutex_thread,refMutex_count);
94+ }
95+}
96+
97+
98+void
99+stdObject::refUnlock() {
100+int er;
101+ if ( refMutex_init == 1 ) {
102+ if ( (er=pthread_mutex_unlock(&refMutex)) ) {
103+ fprintf(stderr,"%s\n",strerror(er));
104+ stdObject::panic("refUnlock-3");
105+ }
106+ }
107+ else {
108+if ( refMutex_debug )
109+::printf("refUnlock %p %i\n",refMutex_thread,refMutex_count);
110+ if ( refMutex_count == 0 )
111+ stdObject::panic("refUnlock-1!!");
112+ pthread_t tid;
113+ tid = pthread_self();
114+ if ( refMutex_thread != tid )
115+ stdObject::panic("refUnlock-2!!");
116+ refMutex_count --;
117+ if ( refMutex_count == 0 ) {
118+ refMutex_thread = 0;
119+if ( refMutex_debug )
120+::printf("refUnlock-1 %p %i\n",refMutex_thread,refMutex_count);
121+ if ( (er=pthread_mutex_unlock(&refMutex)) ) {
122+ fprintf(stderr,"%s\n",strerror(er));
123+ stdObject::panic("refUnlock-3");
124+ }
125+ }
126+ }
127+}
128+
129+
130+
38131 void
39132 stdObject::addref()
40133 {
--- modules/tinyState/trunk/src/classes/ts/c++/tsThread.cpp (revision 5987)
+++ modules/tinyState/trunk/src/classes/ts/c++/tsThread.cpp (revision 5988)
@@ -634,7 +634,7 @@
634634 p = total_run_time * 10 /
635635 ((now - acc_start_time) );
636636 //::printf("MAX THREAD NOS-1 %lli %lli %lli\n",p,total_run_time,now - acc_start_time);
637- p = (p + 12)/10;
637+ p = (p + 32)/10;
638638 if ( p < max_thread_nos && max_thread_nos > 1 ) {
639639 if ( now - last_dec_time >=
640640 DEC_TIMER*1000*1000 ) {
--- modules/tinyState/trunk/src/h/ts/c++/sPtr.h (revision 5987)
+++ modules/tinyState/trunk/src/h/ts/c++/sPtr.h (revision 5988)
@@ -72,6 +72,8 @@
7272 ptr->addref();
7373 }
7474 void _initial(__TYPE * inp) {
75+ pthread_t tid;
76+ tid = pthread_self();
7577 ptr = inp;
7678 if ( ptr )
7779 ptr->addref();
--- modules/tinyState/trunk/src/h/ts/c++/stdObject.h (revision 5987)
+++ modules/tinyState/trunk/src/h/ts/c++/stdObject.h (revision 5988)
@@ -28,34 +28,22 @@
2828
2929 static const char * trace_all;
3030 static int load_mem_amount;
31-/*
31+
3232 static void refLock();
3333 static void refUnlock();
34-*/
35- static void refLock() {
36- if ( refMutex_init == 0 ) {
37- pthread_mutexattr_t attr;
38- pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
39- pthread_mutex_init(&refMutex,&attr);
40- refMutex_init = 1;
41- }
42- pthread_mutex_lock(&refMutex);
43- refMutex_thread = pthread_self();
44- }
45- static void refUnlock() {
46- pthread_mutex_unlock(&refMutex);
47- }
4834
4935
36+ static uint8_t refMutex_debug;
5037 protected:
5138 virtual void refNotice() {}
5239 virtual void refNotice1() {}
5340 virtual void refCount(int ref,int inc_flag) {}
5441
42+private:
5543 static pthread_mutex_t refMutex;
5644 static uint8_t refMutex_init;
5745 static pthread_t refMutex_thread;
58-private:
46+ static int refMutex_count;
5947
6048 void insert_zombie_list();
6149 void delete_zombie_list();
Show on old repository browser