Skip to content

Commit a0891b8

Browse files
committed
Thread: Set string pool thread
1 parent 5990cc0 commit a0891b8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/scratchcpp/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class LIBSCRATCHCPP_EXPORT Thread
2020
public:
2121
Thread(Target *target, IEngine *engine, Script *script);
2222
Thread(const Thread &) = delete;
23+
~Thread();
2324

2425
Target *target() const;
2526
IEngine *engine() const;

src/engine/thread.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
#include <scratchcpp/executioncontext.h>
77

88
#include "thread_p.h"
9+
#include "scratch/string_pool_p.h"
910

1011
using namespace libscratchcpp;
1112

1213
/*! Constructs Thread. */
1314
Thread::Thread(Target *target, IEngine *engine, Script *script) :
1415
impl(spimpl::make_unique_impl<ThreadPrivate>(target, engine, script))
1516
{
17+
string_pool_add_thread(this);
18+
1619
if (impl->script) {
1720
impl->code = impl->script->code();
1821

@@ -21,6 +24,12 @@ Thread::Thread(Target *target, IEngine *engine, Script *script) :
2124
}
2225
}
2326

27+
/*! Destroys Thread. */
28+
Thread::~Thread()
29+
{
30+
string_pool_remove_thread(this);
31+
}
32+
2433
/*! Returns the Target of the script. */
2534
Target *Thread::target() const
2635
{
@@ -42,7 +51,9 @@ Script *Thread::script() const
4251
/*! Runs the script until it finishes or yields. */
4352
void Thread::run()
4453
{
54+
string_pool_set_thread(this);
4555
impl->code->run(impl->executionContext.get());
56+
string_pool_set_thread(nullptr);
4657
}
4758

4859
/*! Stops the script. */

0 commit comments

Comments
 (0)