This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
An operation declared in a protected body is not directly accessible to a user of the protected object, and it would appear that there is no need to provide a locking version of the operation. However, it is possible to use 'Access from within the protected body to pass a pointer to the internal operation outside of the object, in order to provide a callback facility. This idiom is used with Ada2005 Timing_Events for example. This patch ensures that a locking version of such a private operation is always provided, so that it is available to analyze an 'Access attribute within the same protectedy body. The following must compile quietly: --- with Ada.Real_Time.Timing_Events; package Alarm_Clock is protected type Alarm_Type is procedure Set; entry Wait; end Alarm_Type; end Alarm_Clock; --- package body Alarm_Clock is use Ada.Real_Time; Timer: Timing_Events.Timing_Event; Fired: Boolean := False; protected body Alarm_Type is procedure Wakeup (Event: in out Timing_Events.Timing_Event) is begin Fired := True; end Wakeup; procedure Set is begin Timer.Set_Handler (In_Time => Seconds (2), Handler => Wakeup'Access); end; entry Wait when Fired is begin null; end Wait; end Alarm_Type; end Alarm_Clock; Tested on x86_64-pc-linux-gnu, committed on trunk 2009-11-30 Ed Schonberg <schonberg@adacore.com> * exp_ch9.ads (Build_Private_Protected_Declaration): For a protected operation that is only declared in a protected body, create a corresponding subprogram declaration. * exp_ch9.adb (Expand_N_Protected_Body): Create protected body of operation in all cases, including for an operation that is only declared in the body. * sem_ch6.adb: Call Build_Private_Protected_Declaration * exp_ch6.adb (Expand_N_Subprogram_Declaration): For an operation declared in a protected body, create the declaration for the corresponding protected version of the operation.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |