@@ -75,34 +75,13 @@ namespace
7575 START_SESSION
7676 };
7777
78- class Guard
79- {
80- public:
81- explicit Guard (ProfilerIpc* ipc)
82- : sharedMemory(ipc->sharedMemory)
83- {
84- sharedMemory->mutexLock ();
85- }
86-
87- ~Guard ()
88- {
89- sharedMemory->mutexUnlock ();
90- }
91-
92- Guard (const Guard&) = delete ;
93- Guard& operator =(const Guard&) = delete ;
94-
95- private:
96- SharedMemoryBase* const sharedMemory;
97- };
98-
9978 struct Header : public MemoryHeader
10079 {
10180 event_t serverEvent;
10281 event_t clientEvent;
10382 USHORT bufferSize;
10483 std::atomic<Tag> tag;
105- std::atomic_uint seq;
84+ unsigned seq;
10685 SpinLock bufferMutex;
10786 char userName[USERNAME_LENGTH + 1 ]; // \0 if has PROFILE_ANY_ATTACHMENT
10887 alignas (FB_ALIGNMENT) UCHAR buffer[4096 ];
@@ -738,9 +717,7 @@ ProfilerIpc::ProfilerIpc(thread_db* tdbb, MemoryPool& pool, AttNumber aAttachmen
738717
739718 if (isServer)
740719 {
741- Guard guard (this );
742-
743- header->seq = 0 ;
720+ SharedMutexGuard guard (sharedMemory);
744721
745722 if (sharedMemory->eventInit (&header->serverEvent ) != FB_SUCCESS)
746723 (Arg::Gds (isc_random) << " ProfilerIpc eventInit(serverEvent) failed" ).raise ();
@@ -749,7 +726,7 @@ ProfilerIpc::ProfilerIpc(thread_db* tdbb, MemoryPool& pool, AttNumber aAttachmen
749726
750727ProfilerIpc::~ProfilerIpc ()
751728{
752- Guard guard (this );
729+ SharedMutexGuard guard (sharedMemory );
753730
754731 const auto header = sharedMemory->getHeader ();
755732
@@ -809,7 +786,7 @@ void ProfilerIpc::internalSendAndReceive(thread_db* tdbb, Tag tag,
809786 LCK_release (tdbb, &tempLock);
810787 }
811788
812- Guard guard (this );
789+ SharedMutexGuard guard (sharedMemory );
813790
814791 const auto header = sharedMemory->getHeader ();
815792
@@ -852,7 +829,7 @@ void ProfilerIpc::internalSendAndReceive(thread_db* tdbb, Tag tag,
852829 memcpy (header->buffer , in, inSize);
853830
854831 header->tag = tag;
855- const auto seq = ++header->seq ;
832+ ++header->seq ;
856833
857834 bufferMutexLock.unlock ();
858835
@@ -1045,8 +1022,8 @@ void ProfilerListener::watcherThread()
10451022 errorMsg += temp;
10461023 }
10471024
1048- header-> bufferSize = MIN (errorMsg.length (), sizeof (header->buffer ));
1049- memcpy (header-> buffer , errorMsg.c_str (), header-> bufferSize );
1025+ buffer. getBuffer ( MIN (errorMsg.length (), sizeof (header->buffer )), false );
1026+ memcpy (buffer. begin () , errorMsg.c_str (), buffer. getCount () );
10501027 }
10511028
10521029 fb_assert (buffer.getCount () <= sizeof (header->buffer ));
@@ -1183,8 +1160,7 @@ void ProfilerListener::processCommand(thread_db* tdbb, ProfilerIpc::Tag tag, UCh
11831160 in->pluginOptionsNull ? 0 : in->pluginOptions .length );
11841161
11851162 ProfilerPackage::StartSessionOutput::Type* out;
1186- buffer.resize (sizeof (*out));
1187- out = reinterpret_cast <decltype (out)>(buffer.begin ());
1163+ out = reinterpret_cast <decltype (out)>(buffer.getBuffer (sizeof (*out), false ));
11881164
11891165 out->sessionIdNull = FB_FALSE;
11901166 out->sessionId = profilerManager->startSession (tdbb, flushInterval,
0 commit comments