Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. convert interlockedincrement to atomic
Forum Updated to NodeBB v4.3 + New Features

convert interlockedincrement to atomic

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 6 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    I am porting a code from c++ on windows to qt
    i have the following part
    InterlockedDecrement(&m_lRunCount)
    where
    volatile long m_lRunCount;

    I need to convert this to use atomic or any other method in Qt

    jsulmJ SGaistS 2 Replies Last reply
    0
    • S SherifOmran

      I am porting a code from c++ on windows to qt
      i have the following part
      InterlockedDecrement(&m_lRunCount)
      where
      volatile long m_lRunCount;

      I need to convert this to use atomic or any other method in Qt

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SherifOmran Did you read https://doc.qt.io/qt-5/atomic-operations.html ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        thank you for the link. But in my case i don't need to implement QAtomicBase. However i need to use it but this is an int and i have a unsigned long long? thats what cause the issue. How should i use it?

        jsulmJ 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Can't you just use std::atomic<long>?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2
          • S SherifOmran

            I am porting a code from c++ on windows to qt
            i have the following part
            InterlockedDecrement(&m_lRunCount)
            where
            volatile long m_lRunCount;

            I need to convert this to use atomic or any other method in Qt

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @SherifOmran said in convert interlockedincrement to atomic:

            I am porting a code from c++ on windows to qt

            Hi,

            Qt is a C++ framework so there's no porting to do.

            Or do you mean that you want to migrate some platform specific bits to be cross-platform ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • S SherifOmran

              thank you for the link. But in my case i don't need to implement QAtomicBase. However i need to use it but this is an int and i have a unsigned long long? thats what cause the issue. How should i use it?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @SherifOmran Did you read this link: https://doc.qt.io/qt-5/qatomicinteger.html#public-functions ?
              "The template parameter T must be a C++ integer type:
              8-bit: char, signed char, unsigned char, qint8, quint8
              16-bit: short, unsigned short, qint16, quint16, char16_t (C++11)
              32-bit: int, unsigned int, qint32, quint32, char32_t (C++11)
              64-bit: long long, unsigned long long, qint64, quint64
              platform-specific size: long, unsigned long
              pointer size: qintptr, quintptr, qptrdiff"

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SherifOmran
                wrote on last edited by
                #7

                I mean that i want to have a similar function like InterlockedDecrement into mingw
                with Qt.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @SherifOmran said in convert interlockedincrement to atomic:

                  into mingw

                  Why can't you use InterlockedIncrement there? Or the suggestions from @jsulm and others?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SherifOmran
                    wrote on last edited by
                    #9

                    MinGw does not undersand interlockedincrement and for me the atomic is new to me, never used it before.

                    mrjjM jsulmJ 2 Replies Last reply
                    0
                    • S SherifOmran

                      MinGw does not undersand interlockedincrement and for me the atomic is new to me, never used it before.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      @SherifOmran
                      Hi
                      mingw should be able to use useInterlockedDecrement
                      https://docs.microsoft.com/en-us/windows/desktop/api/winnt/nf-winnt-interlockeddecrement
                      if you link against Kernel32
                      so try wtih
                      LIBS += -lkernel32
                      in .pro file ( qmake + run rebuild all)
                      and see if it will use it then.

                      1 Reply Last reply
                      2
                      • S SherifOmran

                        MinGw does not undersand interlockedincrement and for me the atomic is new to me, never used it before.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @SherifOmran said in convert interlockedincrement to atomic:

                        for me the atomic is new to me

                        There is really nothing special about it: declare a variable of type QAtomicInteger and increment/decriment it when needed:

                        QAtomicInteger<int> atomicInt;
                        ...
                        --atomicInt;
                        

                        Looks easier to me than using InterlockedDecrement.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        VRoninV 1 Reply Last reply
                        4
                        • jsulmJ jsulm

                          @SherifOmran said in convert interlockedincrement to atomic:

                          for me the atomic is new to me

                          There is really nothing special about it: declare a variable of type QAtomicInteger and increment/decriment it when needed:

                          QAtomicInteger<int> atomicInt;
                          ...
                          --atomicInt;
                          

                          Looks easier to me than using InterlockedDecrement.

                          VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #12

                          @jsulm said in convert interlockedincrement to atomic:

                          There is really nothing special about it: declare a variable of type QAtomicInteger and increment/decriment it when needed

                          100% agree. The only sidenote is that QAtomicInteger is some overhead on top of std::atomic so to replicate basic operations like the above I'd just stick with the std version of the class

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          1 Reply Last reply
                          2

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved