The current C interface is bad because resources are not freed in destructors, and the use of raw void pointers is necessary.
On Mon, Mar 19, 2018 at 10:09 AM, Derek Dagit <der...@oath.com.invalid> wrote: > OK, so I am in favor of consistency with the existing C API, if possible > and only if there is not good reason to break with the way the C API is > doing it. > > On Mon, Mar 19, 2018 at 9:58 AM, Walt Karas <wka...@oath.com.invalid> wrote: > >> yes >> >> >> On Mon, Mar 19, 2018 at 9:54 AM, Derek Dagit <der...@oath.com.invalid> >> wrote: >> >> Continuation(TSMutex mutexp = TSMutexCreate()) : >> > >> > Not every continuation requires a mutex. To get behavior similar to the >> > current C API we would need to pass a `nullptr` to the constructor, >> right? >> > >> > On Fri, Mar 16, 2018 at 6:39 PM, Walt Karas <wka...@oath.com.invalid> >> wrote: >> > >> >> Does this seem like a good wrapper class for continuations in the C++ >> API? >> >> >> >> class Continuation >> >> { >> >> public: >> >> Continuation(TSMutex mutexp = TSMutexCreate()) : >> >> _cont(TSContCreate(_generalEventFunc, mutexp)) >> >> { >> >> TSContDataSet(_cont, static_cast<void *>(this)); >> >> } >> >> >> >> TSCont >> >> asTSCont() const >> >> { >> >> return _cont; >> >> } >> >> >> >> void >> >> destroy() >> >> { >> >> if (_cont) { >> >> TSContDestroy(_cont); >> >> _cont = nullptr; >> >> } >> >> } >> >> >> >> ~Continuation() >> >> { >> >> if (_cont) { >> >> TSContDestroy(_cont); >> >> } >> >> } >> >> >> >> // No copying. >> >> Continuation(const Continuation &) = delete; >> >> Continuation &operator=(const Continuation &) = delete; >> >> >> >> // Moving allowed. >> >> Continuation(Continuation &&that) >> >> { >> >> _cont = that._cont; >> >> that._cont = nullptr; >> >> } >> >> Continuation & >> >> operator=(Continuation &&that) >> >> { >> >> if (&that != this) { >> >> if (_cont) { >> >> TSContDestroy(_cont); >> >> } >> >> _cont = that._cont; >> >> that._cont = nullptr; >> >> } >> >> return *this; >> >> } >> >> >> >> explicit operator bool() const { return _cont != nullptr; } >> >> >> >> private: >> >> // Distinct continuation behavior is achieved by overriding this >> >> function in a derived continuation type. >> >> // >> >> virtual int _run(TSEvent event, void *edata) = 0; >> >> >> >> // This is the event function for all continuations in C++ plugins. >> >> // >> >> static int _generalEventFunc(TSCont cont, TSEvent event, void *edata); >> >> >> >> TSCont _cont; >> >> }; >> >> >> > >> > >> > >> > -- >> > Derek >> > > > > -- > Derek