2525#define JRD_EXE_PROTO_H
2626
2727#include " ../jrd/cmp_proto.h"
28+ #include < atomic>
2829
2930namespace Jrd {
3031 class Request ;
@@ -58,6 +59,29 @@ void EXE_unwind(Jrd::thread_db*, Jrd::Request*);
5859
5960namespace Jrd
6061{
62+ class CachedRequestId
63+ {
64+ public:
65+ CachedRequestId ()
66+ : id(generator++)
67+ {
68+ fb_assert (id <= MAX_USHORT);
69+ }
70+
71+ CachedRequestId (const CachedRequestId&) = delete ;
72+ CachedRequestId& operator =(const CachedRequestId&) = delete ;
73+
74+ public:
75+ USHORT getId () const
76+ {
77+ return id;
78+ }
79+
80+ private:
81+ unsigned id;
82+ static inline std::atomic<unsigned > generator;
83+ };
84+
6185 // ASF: To make this class MT-safe in SS for v3, it should be AutoCacheRequest::release job to
6286 // inform CMP that the request is available for subsequent usage.
6387 class AutoCacheRequest
@@ -70,6 +94,13 @@ namespace Jrd
7094 {
7195 }
7296
97+ AutoCacheRequest (thread_db* tdbb, const CachedRequestId& cachedRequestId)
98+ : id(cachedRequestId.getId()),
99+ which(CACHED_REQUESTS),
100+ request(tdbb->getAttachment ()->findSystemRequest(tdbb, id, which))
101+ {
102+ }
103+
73104 AutoCacheRequest ()
74105 : id(0 ),
75106 which(0 ),
@@ -92,6 +123,15 @@ namespace Jrd
92123 request = tdbb->getAttachment ()->findSystemRequest (tdbb, id, which);
93124 }
94125
126+ void reset (thread_db* tdbb, const CachedRequestId& cachedRequestId)
127+ {
128+ release ();
129+
130+ id = cachedRequestId.getId ();
131+ which = CACHED_REQUESTS;
132+ request = tdbb->getAttachment ()->findSystemRequest (tdbb, id, which);
133+ }
134+
95135 void compile (thread_db* tdbb, const UCHAR* blr, ULONG blrLength)
96136 {
97137 if (request)
0 commit comments