History

Merge pull request #142 from ccrma/feature/mainthreadhook

re-add mainthreadhook

Ge Wang committed 6 years ago

Commit 5e02dfc2 parents 2cef6db 7de6cc15 files · +107 −3Browse files

Unified · Split

5 files
  1. src/core/chuck.cpp +21 −0
  2. src/core/chuck.h +6 −0
  3. src/core/chuck_dl.cpp +48 −0
  4. src/core/chuck_dl.h +23 −2
  5. src/host/chuck_main.cpp +9 −1
src/core/chuck.cpp+21−0
@@ -1126,3 +1126,24 @@ void ChucK::poop() · 1125 unmodified lines
1126{1126{
1127 ::uh();1127 ::uh();
1128}1128}
1129
1130
1131
1132//-----------------------------------------------------------------------------
1133// name: setMainThreadHook()
1134// desc:
1135//-----------------------------------------------------------------------------
1136bool ChucK::setMainThreadHook(Chuck_DL_MainThreadHook * hook)
1137{
1138 m_hook = hook;
1139 return true;
1140}
1141
1142//-----------------------------------------------------------------------------
1143// name: getMainThreadHook()
1144// desc:
1145//-----------------------------------------------------------------------------
1146Chuck_DL_MainThreadHook * ChucK::getMainThreadHook()
1147{
1148 return m_hook;
1149}
src/core/chuck.h+6−0
@@ -122,6 +122,10 @@ public: · 121 unmodified lines
122public:122public:
123 // additional native chuck bindings/types (use with extra caution)123 // additional native chuck bindings/types (use with extra caution)
124 bool bind( f_ck_query queryFunc, const std::string & name );124 bool bind( f_ck_query queryFunc, const std::string & name );
125
126 bool setMainThreadHook(Chuck_DL_MainThreadHook * hook);
127
128 Chuck_DL_MainThreadHook * getMainThreadHook();
125 129
126public:130public:
127 // get VM (dangerous)131 // get VM (dangerous)
@@ -200,6 +204,8 @@ protected: · 72 unmodified lines
200 std::map< std::string, std::list<std::string> > m_listParams;204 std::map< std::string, std::list<std::string> > m_listParams;
201 // did user init?205 // did user init?
202 t_CKBOOL m_init;206 t_CKBOOL m_init;
207 // main thread "hook" (if there is a main thread)
208 Chuck_DL_MainThreadHook * m_hook = nullptr;
203};209};
204 210
205 211
src/core/chuck_dl.cpp+48−0
@@ -40,6 +40,7 @@ · 39 unmodified lines
40#include "chuck_instr.h"40#include "chuck_instr.h"
41#include "chuck_compile.h"41#include "chuck_compile.h"
42#include "chuck_vm.h"42#include "chuck_vm.h"
43#include "chuck.h"
43#include <sstream>44#include <sstream>
44using namespace std;45using namespace std;
45 46
@@ -556,6 +557,17 @@ t_CKBOOL CK_DLL_CALL ck_end_class( Chuck_DL_Query * query ) · 510 unmodified lines
556}557}
557 558
558 559
560//-----------------------------------------------------------------------------
561// name: ck_create_main_thread_hook()
562// desc: ...
563//-----------------------------------------------------------------------------
564Chuck_DL_MainThreadHook * CK_DLL_CALL ck_create_main_thread_hook( Chuck_DL_Query * query,
565 f_mainthreadhook hook,
566 f_mainthreadquit quit,
567 void * bindle )
568{
569 return new Chuck_DL_MainThreadHook( hook, quit, bindle, query->carrier() );
570}
559 571
560 572
561//-----------------------------------------------------------------------------573//-----------------------------------------------------------------------------
@@ -935,6 +947,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier ) · 373 unmodified lines
935 doc_class = ck_doc_class;947 doc_class = ck_doc_class;
936 doc_func = ck_doc_func;948 doc_func = ck_doc_func;
937 doc_var = ck_doc_var;949 doc_var = ck_doc_var;
950 create_main_thread_hook = ck_create_main_thread_hook;
938 m_carrier = carrier;951 m_carrier = carrier;
939 952
940// memset(reserved2, NULL, sizeof(void*)*RESERVED_SIZE);953// memset(reserved2, NULL, sizeof(void*)*RESERVED_SIZE);
@@ -1005,6 +1018,41 @@ Chuck_DL_Func::~Chuck_DL_Func() · 64 unmodified lines
1005}1018}
1006 1019
1007 1020
1021/*******************************************************************************
1022
1023 Main Thread Hook stuff
1024
1025*******************************************************************************/
1026
1027t_CKBOOL ck_mthook_activate(Chuck_DL_MainThreadHook *hook)
1028{
1029 hook->m_carrier->chuck->setMainThreadHook(hook);
1030 hook->m_active = true;
1031 return hook->m_active;
1032}
1033
1034t_CKBOOL ck_mthook_deactivate(Chuck_DL_MainThreadHook *hook)
1035{
1036 hook->m_carrier->chuck->setMainThreadHook(nullptr);
1037 hook->m_active = false;
1038 return hook->m_active;
1039}
1040
1041//-----------------------------------------------------------------------------
1042// name: Chuck_DL_MainThreadHook()
1043// desc: ...
1044//-----------------------------------------------------------------------------
1045Chuck_DL_MainThreadHook::Chuck_DL_MainThreadHook(f_mainthreadhook hook, f_mainthreadquit quit,
1046 void * bindle, Chuck_Carrier * carrier) :
1047m_hook(hook),
1048m_quit(quit),
1049m_carrier(carrier),
1050m_bindle(bindle),
1051activate(ck_mthook_activate),
1052deactivate(ck_mthook_deactivate),
1053m_active(FALSE)
1054{ }
1055
1008 1056
1009 1057
1010/*******************************************************************************1058/*******************************************************************************
src/core/chuck_dl.h+23−2
@@ -48,7 +48,7 @@ · 47 unmodified lines
48// major version must be the same between chuck:chugin48// major version must be the same between chuck:chugin
49#define CK_DLL_VERSION_MAJOR (0x0007)49#define CK_DLL_VERSION_MAJOR (0x0007)
50// minor version of chugin must be less than or equal to chuck's50// minor version of chugin must be less than or equal to chuck's
51#define CK_DLL_VERSION_MINOR (0x0000)51#define CK_DLL_VERSION_MINOR (0x0001)
52#define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min)))52#define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min)))
53#define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF)53#define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF)
54#define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF)54#define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF)
@@ -73,6 +73,7 @@ struct Chuck_DLL; · 18 unmodified lines
73struct Chuck_UGen;73struct Chuck_UGen;
74struct Chuck_UAna;74struct Chuck_UAna;
75struct Chuck_UAnaBlobProxy;75struct Chuck_UAnaBlobProxy;
76struct Chuck_DL_MainThreadHook;
76namespace Chuck_DL_Api { struct Api; }77namespace Chuck_DL_Api { struct Api; }
77 78
78 79
@@ -306,7 +307,9 @@ typedef void (CK_DLL_CALL * f_add_ugen_ctrl)( Chuck_DL_Query * query, f_ctrl ctr · 227 unmodified lines
306 const char * type, const char * name );307 const char * type, const char * name );
307// end class/namespace - must correspondent with begin_class. returns false on error308// end class/namespace - must correspondent with begin_class. returns false on error
308typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query );309typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query );
309 310// create main thread hook- used for executing a "hook" function in the main thread of a primary chuck instance
311typedef Chuck_DL_MainThreadHook * (CK_DLL_CALL * f_create_main_thread_hook)( Chuck_DL_Query * query, f_mainthreadhook hook, f_mainthreadquit quit, void * bindle );
312
310// documentation313// documentation
311// set current class documentation314// set current class documentation
312typedef t_CKBOOL (CK_DLL_CALL * f_doc_class)( Chuck_DL_Query * query, const char * doc );315typedef t_CKBOOL (CK_DLL_CALL * f_doc_class)( Chuck_DL_Query * query, const char * doc );
@@ -334,6 +337,7 @@ public: · 21 unmodified lines
334 Chuck_Compiler * compiler() const { return m_carrier->compiler; }337 Chuck_Compiler * compiler() const { return m_carrier->compiler; }
335 Chuck_VM * vm() const { return m_carrier->vm; }338 Chuck_VM * vm() const { return m_carrier->vm; }
336 Chuck_Env * env() const { return m_carrier->env; }339 Chuck_Env * env() const { return m_carrier->env; }
340 Chuck_Carrier * carrier() const { return m_carrier; }
337 341
338public:342public:
339 // function pointers - to be called from client module343 // function pointers - to be called from client module
@@ -375,6 +379,9 @@ public: · 35 unmodified lines
375 f_doc_var doc_var;379 f_doc_var doc_var;
376 f_add_example add_ex;380 f_add_example add_ex;
377 381
382 // re-added 1.4.0.1
383 f_create_main_thread_hook create_main_thread_hook;
384
378 // NOTE: everything below std::anything cannot be reliably accessed385 // NOTE: everything below std::anything cannot be reliably accessed
379 // by offset between dynamic modules, since std::anything could be variable386 // by offset between dynamic modules, since std::anything could be variable
380 // size -- put everything need to be accessed across modules above here!387 // size -- put everything need to be accessed across modules above here!
@@ -629,6 +636,20 @@ protected: · 248 unmodified lines
629};636};
630 637
631 638
639struct Chuck_DL_MainThreadHook
640{
641public:
642 Chuck_DL_MainThreadHook(f_mainthreadhook hook, f_mainthreadquit quit,
643 void * bindle, Chuck_Carrier * carrier);
644 t_CKBOOL (* const activate)(Chuck_DL_MainThreadHook *);
645 t_CKBOOL (* const deactivate)(Chuck_DL_MainThreadHook *);
646
647 Chuck_Carrier * const m_carrier;
648 f_mainthreadhook const m_hook;
649 f_mainthreadquit const m_quit;
650 void * const m_bindle;
651 t_CKBOOL m_active;
652};
632 653
633 654
634/* API to ChucK's innards */655/* API to ChucK's innards */
src/host/chuck_main.cpp+9−1
@@ -1037,7 +1037,11 @@ bool go( int argc, const char ** argv ) · 1036 unmodified lines
1037 // real-time audio1037 // real-time audio
1038 if( g_enable_realtime_audio )1038 if( g_enable_realtime_audio )
1039 {1039 {
1040 usleep( 10000 );1040 Chuck_DL_MainThreadHook * hook = the_chuck->getMainThreadHook();
1041 if (hook)
1042 hook->m_hook(hook->m_bindle);
1043 else
1044 usleep( 10000 );
1041 }1045 }
1042 else // silent mode1046 else // silent mode
1043 {1047 {
@@ -1046,6 +1050,10 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines
1046 }1050 }
1047 }1051 }
1048 1052
1053 Chuck_DL_MainThreadHook * hook = the_chuck->getMainThreadHook();
1054 if (hook)
1055 hook->m_quit(hook->m_bindle);
1056
1049 return TRUE;1057 return TRUE;
1050}1058}
1051 1059

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t