@@ -92,7 +92,7 @@ const int signals[] = {VisitSignal, InterruptSignal, PipeSignal};
92
92
const unsigned SignalCount = 3 ;
93
93
94
94
class MySystem ;
95
- MySystem* system ;
95
+ MySystem* globalSystem ;
96
96
97
97
void handleSignal (int signal, siginfo_t * info, void * context);
98
98
@@ -624,16 +624,18 @@ class MySystem : public System {
624
624
System::Library* next_;
625
625
};
626
626
627
- MySystem () : threadVisitor(0 ), visitTarget(0 )
627
+ MySystem (bool reentrant ) : reentrant(reentrant), threadVisitor(0 ), visitTarget(0 )
628
628
{
629
- expect (this , system == 0 );
630
- system = this ;
629
+ if (not reentrant) {
630
+ expect (this , globalSystem == 0 );
631
+ globalSystem = this ;
631
632
632
- expect (this , registerHandler (InterruptSignalIndex));
633
- expect (this , registerHandler (VisitSignalIndex));
634
- expect (this , registerHandler (PipeSignalIndex));
635
-
636
- expect (this , make (&visitLock) == 0 );
633
+ expect (this , registerHandler (InterruptSignalIndex));
634
+ expect (this , registerHandler (VisitSignalIndex));
635
+ expect (this , registerHandler (PipeSignalIndex));
636
+
637
+ expect (this , make (&visitLock) == 0 );
638
+ }
637
639
}
638
640
639
641
// Returns true on success, false on failure
@@ -708,6 +710,8 @@ class MySystem : public System {
708
710
System::Thread* sTarget ,
709
711
ThreadVisitor* visitor)
710
712
{
713
+ expect (this , not reentrant);
714
+
711
715
assertT (this , st != sTarget );
712
716
713
717
Thread* target = static_cast <Thread*>(sTarget );
@@ -767,7 +771,7 @@ class MySystem : public System {
767
771
768
772
threadVisitor = 0 ;
769
773
770
- system ->visitLock ->notifyAll (t);
774
+ globalSystem ->visitLock ->notifyAll (t);
771
775
772
776
return result;
773
777
#endif // not __APPLE__
@@ -938,18 +942,21 @@ class MySystem : public System {
938
942
939
943
virtual void dispose ()
940
944
{
941
- visitLock->dispose ();
945
+ if (not reentrant) {
946
+ visitLock->dispose ();
942
947
943
- expect (this , unregisterHandler (InterruptSignalIndex));
944
- expect (this , unregisterHandler (VisitSignalIndex));
945
- expect (this , unregisterHandler (PipeSignalIndex));
946
- system = 0 ;
948
+ expect (this , unregisterHandler (InterruptSignalIndex));
949
+ expect (this , unregisterHandler (VisitSignalIndex));
950
+ expect (this , unregisterHandler (PipeSignalIndex));
951
+ globalSystem = 0 ;
952
+ }
947
953
948
954
::free (this );
949
955
}
950
956
951
957
struct sigaction oldHandlers[SignalCount];
952
958
959
+ bool reentrant;
953
960
ThreadVisitor* threadVisitor;
954
961
Thread* visitTarget;
955
962
System::Monitor* visitLock;
@@ -965,13 +972,13 @@ void handleSignal(int signal, siginfo_t*, void* context)
965
972
966
973
switch (signal ) {
967
974
case VisitSignal: {
968
- system ->threadVisitor ->visit (ip, stack, link );
975
+ globalSystem ->threadVisitor ->visit (ip, stack, link );
969
976
970
- System::Thread* t = system ->visitTarget ;
971
- system ->visitTarget = 0 ;
977
+ System::Thread* t = globalSystem ->visitTarget ;
978
+ globalSystem ->visitTarget = 0 ;
972
979
973
- ACQUIRE_MONITOR (t, system ->visitLock );
974
- system ->visitLock ->notifyAll (t);
980
+ ACQUIRE_MONITOR (t, globalSystem ->visitLock );
981
+ globalSystem ->visitLock ->notifyAll (t);
975
982
} break ;
976
983
977
984
case InterruptSignal:
@@ -987,9 +994,9 @@ void handleSignal(int signal, siginfo_t*, void* context)
987
994
988
995
namespace vm {
989
996
990
- AVIAN_EXPORT System* makeSystem ()
997
+ AVIAN_EXPORT System* makeSystem (bool reentrant )
991
998
{
992
- return new (malloc (sizeof (MySystem))) MySystem ();
999
+ return new (malloc (sizeof (MySystem))) MySystem (reentrant );
993
1000
}
994
1001
995
1002
} // namespace vm
0 commit comments