[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [qtcurve] /: [lib/utils, misc] clang warnings, replace thread_local with pthread + template
From:       Yichao Yu <yyc1992 () gmail ! com>
Date:       2015-03-20 22:14:59
Message-ID: E1YZ5Bz-0002Je-6a () scm ! kde ! org
[Download RAW message or body]

Git commit fda0450e706003719a410b566567f070058d2480 by Yichao Yu.
Committed on 20/03/2015 at 22:12.
Pushed by yuyichao into branch 'master'.

[lib/utils, misc] clang warnings, replace thread_local with pthread + template

M  +5    -1    CMakeLists.txt
M  +1    -1    lib/utils/number.h
C  +37   -43   lib/utils/thread.h [from: lib/utils/timer.cpp - 065% similarity]
M  +7    -6    lib/utils/timer.cpp
M  +2    -2    lib/utils/x11utils_p.h
M  +1    -1    qt4/config/qtcurveconfig.h

http://commits.kde.org/qtcurve/fda0450e706003719a410b566567f070058d2480

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e25120..bdbb9c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -191,8 +191,12 @@ cmake_c_add_flags(CMAKE_C_FLAGS -Wall -Wextra -Wno-cast-align
 # Register storage class is deprecated in C++11 but is still used in Qt.
 # Use compiler option (-Wno-deprecated-register) to suppress
 # the warning in clang++.
+# We use `override` in certain Qt Classes but the QObject macro does not use it
+# Use compiler option (-Wno-inconsistent-missing-override) to suppress
+# the warning in clang++ 3.6+.
 cmake_c_add_flags(CMAKE_CXX_FLAGS -Wall -Wextra
-  -Wno-deprecated-register -Wno-cast-align)
+  -Wno-deprecated-register -Wno-cast-align
+  -Wno-inconsistent-missing-override)
 if(NOT APPLE)
   # -std=c++0x is deprecated but gcc < 4.7 do not recognise c++11 ....
   cmake_c_add_flags(CMAKE_CXX_FLAGS -std=c++0x -D_DEFAULT_SOURCE)
diff --git a/lib/utils/number.h b/lib/utils/number.h
index fad2dc7..7e66b66 100644
--- a/lib/utils/number.h
+++ b/lib/utils/number.h
@@ -79,7 +79,7 @@ qtcSum(First &&first)
 
 template<typename First, typename... Rest>
 static inline auto
-qtcSum(First &&first, Rest &&...rest...)
+qtcSum(First &&first, Rest &&...rest)
     -> decltype(first + qtcSum(std::forward<Rest>(rest)...))
 {
     return first + qtcSum(std::forward<Rest>(rest)...);
diff --git a/lib/utils/timer.cpp b/lib/utils/thread.h
similarity index 65%
copy from lib/utils/timer.cpp
copy to lib/utils/thread.h
index ec2ffda..a9cb2be 100644
--- a/lib/utils/timer.cpp
+++ b/lib/utils/thread.h
@@ -1,5 +1,5 @@
 /*****************************************************************************
- *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
+ *   Copyright 2015 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
  *                                                                           *
  *   This program is free software; you can redistribute it and/or modify    *
  *   it under the terms of the GNU Lesser General Public License as          *
@@ -19,47 +19,41 @@
  *   see <http://www.gnu.org/licenses/>.                                     *
  *****************************************************************************/
 
-#include "timer.h"
-
-#include <chrono>
-#include <vector>
-
-namespace QtCurve {
-
-QTC_EXPORT uint64_t
-getTime()
-{
-    using namespace std::chrono;
-    return time_point_cast<nanoseconds>(high_resolution_clock::now())
-        .time_since_epoch().count();
-}
-
-QTC_EXPORT uint64_t
-getElapse(uint64_t prev)
-{
-    return getTime() - prev;
-}
-
-static thread_local std::vector<uint64_t> tics_list;
-
-QTC_EXPORT void
-tic()
-{
-    tics_list.push_back(0);
-    auto &back = tics_list.back();
-    back = getTime();
-}
-
-QTC_EXPORT uint64_t
-toc()
-{
-    uint64_t cur_time = getTime();
-    if (!tics_list.size()) {
-        return 0;
+#ifndef _QTC_UTILS_THREAD_H_
+#define _QTC_UTILS_THREAD_H_
+
+#include <pthread.h>
+
+// Replaces thread_local since clang on OSX doesn't really support it.
+template<typename T>
+class ThreadLocal {
+    pthread_key_t m_key;
+public:
+    ThreadLocal()
+    {
+        pthread_key_create(&m_key, [] (void *ptr) {
+                delete reinterpret_cast<T*>(ptr);
+            });
+    }
+    ~ThreadLocal()
+    {
+        pthread_key_delete(m_key);
+    }
+    T*
+    get() const
+    {
+        T *v = reinterpret_cast<T*>(pthread_getspecific(m_key));
+        if (!v) {
+            v = new T();
+            pthread_setspecific(m_key, reinterpret_cast<void*>(v));
+        }
+        return v;
+    }
+    T*
+    operator->() const
+    {
+        return get();
     }
-    uint64_t old_time = tics_list.back();
-    tics_list.pop_back();
-    return cur_time - old_time;
-}
+};
 
-}
+#endif
diff --git a/lib/utils/timer.cpp b/lib/utils/timer.cpp
index ec2ffda..60d410f 100644
--- a/lib/utils/timer.cpp
+++ b/lib/utils/timer.cpp
@@ -20,6 +20,7 @@
  *****************************************************************************/
 
 #include "timer.h"
+#include "thread.h"
 
 #include <chrono>
 #include <vector>
@@ -40,13 +41,13 @@ getElapse(uint64_t prev)
     return getTime() - prev;
 }
 
-static thread_local std::vector<uint64_t> tics_list;
+static ThreadLocal<std::vector<uint64_t> > tics_list;
 
 QTC_EXPORT void
 tic()
 {
-    tics_list.push_back(0);
-    auto &back = tics_list.back();
+    tics_list->push_back(0);
+    auto &back = tics_list->back();
     back = getTime();
 }
 
@@ -54,11 +55,11 @@ QTC_EXPORT uint64_t
 toc()
 {
     uint64_t cur_time = getTime();
-    if (!tics_list.size()) {
+    if (!tics_list->size()) {
         return 0;
     }
-    uint64_t old_time = tics_list.back();
-    tics_list.pop_back();
+    uint64_t old_time = tics_list->back();
+    tics_list->pop_back();
     return cur_time - old_time;
 }
 
diff --git a/lib/utils/x11utils_p.h b/lib/utils/x11utils_p.h
index 9e71be2..0ee3433 100644
--- a/lib/utils/x11utils_p.h
+++ b/lib/utils/x11utils_p.h
@@ -38,7 +38,7 @@ template <typename Ret, typename Cookie, typename... Args, typename... Args2>
 static inline Ret*
 _qtcX11Call(Cookie (*func)(xcb_connection_t*, Args...),
             Ret *(reply_func)(xcb_connection_t*, Cookie, xcb_generic_error_t**),
-            Args2... args...)
+            Args2... args)
 {
     xcb_connection_t *conn = qtc_xcb_conn;
     QTC_RET_IF_FAIL(conn, nullptr);
@@ -51,7 +51,7 @@ _qtcX11Call(Cookie (*func)(xcb_connection_t*, Args...),
 template <typename... Args, typename... Args2>
 static inline xcb_void_cookie_t
 _qtcX11CallVoid(xcb_void_cookie_t (*func)(xcb_connection_t*, Args...),
-                Args2... args...)
+                Args2... args)
 {
     xcb_connection_t *conn = qtc_xcb_conn;
     QTC_RET_IF_FAIL(conn, xcb_void_cookie_t());
diff --git a/qt4/config/qtcurveconfig.h b/qt4/config/qtcurveconfig.h
index 5ac87fd..7f954f1 100644
--- a/qt4/config/qtcurveconfig.h
+++ b/qt4/config/qtcurveconfig.h
@@ -105,7 +105,7 @@ public:
     QtCurveConfig(QWidget *parent);
     ~QtCurveConfig() override;
 
-    QSize sizeHint() const;
+    QSize sizeHint() const override;
     Shading currentShading() const
     {
         return (Shading)shading->currentIndex();
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic