parlib: Make uth mutex/CV initializers C++ safe (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 27 Apr 2017 19:11:53 +0000 (15:11 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 3 May 2017 16:16:08 +0000 (12:16 -0400)
GCC C++ can't handle { { .field = value } }.  It can handle one {}, but not
two.  C doesn't have this problem.  The issue comes up when someone does
something like:

struct my_struct {
uth_mutex_t foo;
}
#define MY_INITIALIZER {UTH_MUTEX_INIT}

icu does this with their umutex.h implementation.  There it is for
pthreads.

For us, we can get away with the non-specific initializers, so long as we
put the parlib_once_t first.

Rebuild your toolchain.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/uthread.h

index a5672d6..171f426 100644 (file)
@@ -226,38 +226,38 @@ typedef struct uth_cond_var uth_cond_var_t;
 typedef struct uth_rwlock uth_rwlock_t;
 
 struct uth_semaphore {
-       struct spin_pdr_lock            lock;
+       parlib_once_t                           once_ctl;
        unsigned int                            count;
+       struct spin_pdr_lock            lock;
        uth_sync_t                                      sync_obj;
-       parlib_once_t                           once_ctl;
 };
-#define UTH_SEMAPHORE_INIT(n) { .once_ctl = PARLIB_ONCE_INIT, .count = (n) }
-#define UTH_MUTEX_INIT { .once_ctl = PARLIB_ONCE_INIT }
+#define UTH_SEMAPHORE_INIT(n) { PARLIB_ONCE_INIT, (n) }
+#define UTH_MUTEX_INIT { PARLIB_ONCE_INIT }
 
 struct uth_recurse_mutex {
+       parlib_once_t                           once_ctl;
        uth_mutex_t                                     mtx;
        struct uthread                          *lockholder;
        unsigned int                            count;
-       parlib_once_t                           once_ctl;
 };
-#define UTH_RECURSE_MUTEX_INIT { .once_ctl = PARLIB_ONCE_INIT }
+#define UTH_RECURSE_MUTEX_INIT { PARLIB_ONCE_INIT }
 
 struct uth_cond_var {
+       parlib_once_t                           once_ctl;
        struct spin_pdr_lock            lock;
        uth_sync_t                                      sync_obj;
-       parlib_once_t                           once_ctl;
 };
-#define UTH_COND_VAR_INIT { .once_ctl = PARLIB_ONCE_INIT }
+#define UTH_COND_VAR_INIT { PARLIB_ONCE_INIT }
 
 struct uth_rwlock {
+       parlib_once_t                           once_ctl;
        struct spin_pdr_lock            lock;
        unsigned int                            nr_readers;
        bool                                            has_writer;
        uth_sync_t                                      readers;
        uth_sync_t                                      writers;
-       parlib_once_t                           once_ctl;
 };
-#define UTH_RWLOCK_INIT { .once_ctl = PARLIB_ONCE_INIT }
+#define UTH_RWLOCK_INIT { PARLIB_ONCE_INIT }
 
 void uth_semaphore_init(uth_semaphore_t *sem, unsigned int count);
 void uth_semaphore_destroy(uth_semaphore_t *sem);