Results 1 to 5 of 5

Thread: QBasicAtomicInt::ref() - what the hell is this?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2010
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QBasicAtomicInt::ref() - what the hell is this?

    Hi, my app suddenly crashed inside the QBasicAtomicInt::ref() function. I see it's because of some foolishly uninitialized pointers, so I should be able to remedy the situation shortly. So what happened and how to debug it is out of question. Rather, I'm baffled by the function itself:
    Qt Code:
    1. inline bool QBasicAtomicInt::ref()
    2. {
    3. unsigned char ret;
    4. asm volatile("lock\n"
    5. "incl %0\n"
    6. "setne %1"
    7. : "=m" (_q_value), "=qm" (ret)
    8. : "m" (_q_value)
    9. : "memory");
    10. return ret != 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    What is it supposed to do? How does it do it? How does asm keyword combine with volatile? Why are asm commands quoted? What are the colons ( : ) doing here? What could '"m" (_q_value)' possibly mean? Please, someone, explain the magic to me

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QBasicAtomicInt::ref() - what the hell is this?

    I am not an asm junkie, but as far as I can tell, most (all?) your questions are answered here:
    http://www.ibiblio.org/gferg/ldp/GCC...WTO.html#ss5.4
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    Septi (20th November 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QBasicAtomicInt::ref() - what the hell is this?

    It's an atomic reference counter.

  5. The following user says thank you to tbscope for this useful post:

    Septi (20th November 2010)

  6. #4
    Join Date
    Jul 2010
    Posts
    12
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBasicAtomicInt::ref() - what the hell is this?

    Thanks for the answer, that's some interesting reading material. I was only familiar with Intel syntax before

  7. #5
    Join Date
    Mar 2008
    Location
    Marslev, Denmark
    Posts
    31
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QBasicAtomicInt::ref() - what the hell is this?

    When this happens, it usually means an object has been double deleted. Use a memory checker like valgrind to go over your code to find the place.
    Bo Thorsen, Viking Software
    Qt applications on Linux and Windows

Similar Threads

  1. Replies: 6
    Last Post: 5th May 2010, 23:25
  2. Small DLL hell adventure
    By Piskvorkar in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2010, 07:24
  3. dll hell
    By jhowland in forum Qt Programming
    Replies: 3
    Last Post: 6th September 2008, 14:30
  4. HDD & BIOS : why the hell is that so badly designed???
    By fullmetalcoder in forum General Discussion
    Replies: 13
    Last Post: 19th April 2006, 12:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.