public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Andrew Fish <afish@apple.com>
To: Arka Sharma <arka.sw1988@gmail.com>
Cc: edk2-devel@lists.01.org
Subject: Re: Closing events and releasing resources in notify function
Date: Fri, 24 Mar 2017 00:08:40 -0700	[thread overview]
Message-ID: <8F7C944F-352D-4D63-BEB5-59086F05C235@apple.com> (raw)
In-Reply-To: <CAPO=kN1PhP0YyZ-Fb_3vniF3a0zw9DMaYFkXG8+=f8Lq6C_j4g@mail.gmail.com>


> On Mar 24, 2017, at 12:07 AM, Arka Sharma <arka.sw1988@gmail.com> wrote:
> 
> Thanks Andrew for your reply. In this case I am creating the event
> with CreateEvent() and not with CreateEventEx(). I am attempting to
> free the Context inside the notify function which will be called after
> Event is signaled, and Context is only accessed before CreateEvent()
> and inside the NotifyRoutine(). So the change you are suggesting is
> inside the notify function I should call CloseEvent() first before
> freeing Context right ?
> 

Yes as your event can get signaled until you close it in the general case. 

Thanks,

Andrew Fish

> On Fri, Mar 24, 2017 at 12:07 PM, Andrew Fish <afish@apple.com> wrote:
>> 
>>> On Mar 23, 2017, at 11:22 PM, Arka Sharma <arka.sw1988@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> Is it ok to close the event and release the resource allocated to be
>>> sent as context inside the notify function. May be something like this
>>> 
>>> VOID
>>> EFIAPI
>>> NotifyRoutine (
>>>      EFI_EVENT Event,
>>>      VOID  *Context
>>> )
>>> {
>>>  //
>>>  // Perform intended task
>>>  //
>>>  FreePool (Context);
>>>  gBS->CloseEvent (Event);
>> 
>> You should close the event before you free the context, or you will have a race. You need to make sure there is no way for EFI to signal the event before you free the context.
>> 
>> This all assumes you don't have other code doing crazy stuff with the Context or Event. It would  be a different answer for CreateEventEx()
>> 
>> Thanks,
>> 
>> Andrew Fish
>> 
>>> }
>>> 
>>> In the above example Context was allocated before creating the event
>>> and passed as a parameter to CreateEvent().
>>> 
>>> Regards,
>>> Arka
>>> _______________________________________________
>>> edk2-devel mailing list
>>> edk2-devel@lists.01.org
>>> https://lists.01.org/mailman/listinfo/edk2-devel
>> 



      reply	other threads:[~2017-03-24  7:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24  6:22 Closing events and releasing resources in notify function Arka Sharma
2017-03-24  6:37 ` Andrew Fish
2017-03-24  7:07   ` Arka Sharma
2017-03-24  7:08     ` Andrew Fish [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8F7C944F-352D-4D63-BEB5-59086F05C235@apple.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox