From: Arka Sharma <arka.sw1988@gmail.com>
To: Andrew Fish <afish@apple.com>
Cc: edk2-devel@lists.01.org
Subject: Re: Closing events and releasing resources in notify function
Date: Fri, 24 Mar 2017 12:37:14 +0530 [thread overview]
Message-ID: <CAPO=kN1PhP0YyZ-Fb_3vniF3a0zw9DMaYFkXG8+=f8Lq6C_j4g@mail.gmail.com> (raw)
In-Reply-To: <9C33D691-C2DF-4F19-933D-5D344B96554B@apple.com>
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 ?
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
>
next prev parent reply other threads:[~2017-03-24 7:07 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 [this message]
2017-03-24 7:08 ` Andrew Fish
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='CAPO=kN1PhP0YyZ-Fb_3vniF3a0zw9DMaYFkXG8+=f8Lq6C_j4g@mail.gmail.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