I'm pretty sure TSContDestroy() also destroys any mutex for the
continuation.  (Per our other discussion, I got exasperated trying to
make sure of this looking through the code with just vi.)

On Mon, Mar 19, 2018 at 10:23 AM, Derek Dagit <der...@oath.com.invalid> wrote:
> I might be missing the connection to the proposed Continuation constructor
> behavior with regard to the mutex.
>
> If there is a good reason to change this behavior, we should consider it.
> Otherwise it's probably best to keep consistency with the existing API.
>
> On Mon, Mar 19, 2018 at 10:16 AM, Walt Karas <wka...@oath.com.invalid>
> wrote:
>
>> 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
>>
>
>
>
> --
> Derek

Reply via email to