@@ -148,7 +148,8 @@ int swFactoryProcess_start(swFactory *factory)
148
148
{
149
149
worker = swServer_get_worker (serv , i );
150
150
worker -> notify = & (worker_notify [i ]);
151
- worker -> shm = worker_shm + (i * serv -> response_max_length );
151
+ worker -> store .ptr = worker_shm + (i * serv -> response_max_length );
152
+ worker -> store .lock = 0 ;
152
153
153
154
if (swPipeNotify_auto (worker -> notify , 1 , 0 ))
154
155
{
@@ -609,6 +610,15 @@ int swFactoryProcess_finish(swFactory *factory, swSendData *resp)
609
610
*/
610
611
if (resp -> length > 0 )
611
612
{
613
+ int64_t wait_reactor ;
614
+
615
+ /**
616
+ * Storage is in use right now, wait notify.
617
+ */
618
+ if (worker -> store .lock == 1 )
619
+ {
620
+ worker -> notify -> read (worker -> notify , & wait_reactor , sizeof (wait_reactor ));
621
+ }
612
622
swPackage_response response ;
613
623
614
624
response .length = resp -> length ;
@@ -618,7 +628,12 @@ int swFactoryProcess_finish(swFactory *factory, swSendData *resp)
618
628
sdata ._send .info .len = sizeof (response );
619
629
620
630
memcpy (sdata ._send .data , & response , sizeof (response ));
621
- memcpy (worker -> shm , resp -> data , resp -> length );
631
+
632
+ /**
633
+ * Lock the worker storage
634
+ */
635
+ worker -> store .lock = 1 ;
636
+ memcpy (worker -> store .ptr , resp -> data , resp -> length );
622
637
}
623
638
else
624
639
{
@@ -684,11 +699,6 @@ int swFactoryProcess_finish(swFactory *factory, swSendData *resp)
684
699
{
685
700
swWarn ("sendto to reactor failed. Error: %s [%d]" , strerror (errno ), errno );
686
701
}
687
- else if (resp -> length > 0 )
688
- {
689
- int64_t wait_reactor ;
690
- worker -> notify -> read (worker -> notify , & wait_reactor , sizeof (wait_reactor ));
691
- }
692
702
return ret ;
693
703
}
694
704
@@ -895,7 +905,8 @@ static int swFactoryProcess_worker_loop(swFactory *factory, int worker_pti)
895
905
* for msg queue
896
906
* 头部放一个long让msg queue可以直接插入到消息队列中
897
907
*/
898
- static __thread struct {
908
+ static __thread struct
909
+ {
899
910
long pti ;
900
911
swDataHead _send ;
901
912
} sw_notify_data ;
0 commit comments