Announcement

Collapse
No announcement yet.

External callback

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • External callback

    I have a program for voice recording/switching (with Dialogic HMP)
    The Dialogic software uses a callback function to send events to my program.
    Code:
    Function HMPCallback CDecl (ByVal Ev As Dword) As Long
      ...
    End Function
    That works fine, but I suspect that when the system is very busy there is re-entrancy (callback is called before finished)
    (It shouldn't do that, but the results say otherwise)
    Can I use Threadsafe on an external callback to prevent re-entrancy?
    Regards,
    Peter

  • #2
    Can I use Threadsafe on an external callback to prevent re-entrancy?
    If it's your function compiled with PowerBASIC, you may use the THREADSAFE directive or any other technique desired (e.g, Critical Section) for "thread-safeness"

    Note that the PB THREADSAFE directive uses a semaphore so it cannot be reentered even on the same thread of execution. (Which might be what you want anyway).

    You might want to look at your function to see what is taking so long that unwanted reentrancy is occurring.. or you might want to re-engineer your function such that re-entrant execution does not matter. That is, you might find some other method of "queuing" the actions of your callback procedure is indicated so that you don't needlessly impair the performance of your program as a whole.

    But your issue should not be "reentrancy" if your "Dialogic HMP" is waiting for the callback function to return.

    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Have you tried FUNCTION=1?
      Code:
      Function HMPCallback CDecl (ByVal Ev As Dword) As Long
       ...
       FUNCTION = 1
      End Function

      Comment


      • #4
        It has been a while since I looked at any Dialogic stuff.
        Question - Is each channel calling the same callback?

        Is the callback in its own thread?

        Are you using Async Callback vs Async Polled vs Asynch with event handlers - is that even still a thing??

        Or are you getting event notification (callbacks) through the standard Windows message handling??

        You gave me your Dialogic header files a while back... I haven't gotten around to them yet!

        Got any code we can look at?

        I need more info to understand how your "handshake" with the dialogic process is "wired up"

        Most interesting!

        Comment


        • #5
          David,

          There is one callback for all channels and events.
          I store it in a queue and process it later.

          The callback is called by the Dialogic software so it's not really interesting in which thread it resides. (it's in the main thread)

          Indeed there are two methods of communicating with the Dialogic software: the Windows message loop or a callback.
          Both work, but I find a callback better to manage, and so you can keep the Dialogic stuff separated.

          I also posted a test program with the header files,
          I also have a (quite extensive) application for an emergency phone helpdesk (to handle calls from people trapped in elevators) but thats specially made for a customer...
          Regards,
          Peter

          Comment


          • #6
            Peter - What is the symptom of the the problem? A windows error or Dialogic is not "keeping up" - how does the error manifest itself?

            I assume this is a Windows program with a dialog? Not a console program, right?

            Do you know how to use threads and things like CriticalSections?

            Also, is the EV (event dword) a pointer to something??

            Comment


            • #7
              Ev is the Event returned by Dialogic.
              Every incoming call gets a number assigned, and that's incremented aftwerwards.

              In rare cases when 2 calls arrive on exactly the same moment, the same number is assigned to both calls
              I'm still looking into how that can be possible...
              Regards,
              Peter

              Comment


              • #8
                Peter,

                i would make an extra function supplying the number - and this function must be threadsafe.

                I guess your callback might be called by different threads, so this callback can run twice or more in different threads at the same time. Write operations (increase a counter aka "number") must be made threadsafe then, because otherwise (if you are "lucky") a task switch might occur right before or while you increase your counter and you may end up with the same number in two callbacks or you might get gaps (missing/skipped numbers) in your queue.

                JK

                Comment


                • #9
                  Your callback function isn't using any STATIC or GLOBAL variables.,right?
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Who assigns the number your code or Dialogic?

                    Comment


                    • #11
                      Do you know about stuff like this:

                      Code:
                      GLOBAL GL_CRITICAL_SECTION_FOR_DIALOGIC_INDEX CRITICAL_SECTION
                      
                      
                       InitializeCriticalSection GL_CRITICAL_SECTION_FOR_DIALOGIC_INDEX CRITICAL_SECTION
                      
                      
                        EnterCriticalSection GL_CRITICAL_SECTION_FOR_DIALOGIC_INDEX CRITICAL_SECTION
                           INCR DIALOGIC_INDEX
                        LeaveCriticalSection GL_CRITICAL_SECTION_FOR_DIALOGIC_INDEX CRITICAL_SECTION
                      
                      
                       DeleteCriticalSection
                      You would want a separate thread for something like this so it doesn't block the main thread - where your forms are....

                      Where are you located on this earth??
                      Last edited by David Clarke; 26 Jul 2022, 05:01 PM.

                      Comment


                      • #12
                        Originally posted by David Clarke View Post
                        Where are you located on this earth??
                        According to his profile:
                        Location: Venray, The Netherlands

                        Click on a member's name (or right click and open in a new tab) and most of us have a location in our User Profile (and some have a lot more on the "About" tab

                        Comment


                        • #13
                          Thanks Stuart!
                          Guess he is too far for me to drop over at his office!

                          Comment

                          Working...
                          X