Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / gmxlib / thread_mpi / once.c
index bee468ceea3fe522f374dbf7a0f633609eb369b8..5c659d095f64ab1ba555b0d711356a973172b7a1 100644 (file)
@@ -1,39 +1,39 @@
 /*
-This source code file is part of thread_mpi.  
-Written by Sander Pronk, Erik Lindahl, and possibly others. 
+   This source code file is part of thread_mpi.
+   Written by Sander Pronk, Erik Lindahl, and possibly others.
 
-Copyright (c) 2009, Sander Pronk, Erik Lindahl.
-All rights reserved.
+   Copyright (c) 2009, Sander Pronk, Erik Lindahl.
+   All rights reserved.
 
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-1) Redistributions of source code must retain the above copyright
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+   1) Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-2) Redistributions in binary form must reproduce the above copyright
+   2) Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-3) Neither the name of the copyright holders nor the
+   3) Neither the name of the copyright holders nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.
 
-THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-If you want to redistribute modifications, please consider that
-scientific software is very special. Version control is crucial -
-bugs must be traceable. We will be happy to consider code for
-inclusion in the official distribution, but derived work should not
-be called official thread_mpi. Details are found in the README & COPYING
-files.
-*/
+   THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
+   EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+   DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
+   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+   If you want to redistribute modifications, please consider that
+   scientific software is very special. Version control is crucial -
+   bugs must be traceable. We will be happy to consider code for
+   inclusion in the official distribution, but derived work should not
+   be called official thread_mpi. Details are found in the README & COPYING
+   files.
+ */
 
 #ifdef HAVE_TMPI_CONFIG_H
 #include "tmpi_config.h"
@@ -58,50 +58,52 @@ files.
 
 
 /* once */
-int tMPI_Once(tMPI_Comm comm, void (*function)(void*), void *param, 
-                int *was_first)
+int tMPI_Once(tMPI_Comm comm, void (*function)(void*), void *param,
+              int *was_first)
 {
-    int myrank;
-    int ret=TMPI_SUCCESS;
+    int               myrank;
+    int               ret = TMPI_SUCCESS;
     struct coll_sync *csync;
-    struct coll_env *cev;
-    int syncs;
+    struct coll_env  *cev;
+    int               syncs;
 
 
     if (!comm)
     {
         return tMPI_Error(TMPI_COMM_WORLD, TMPI_ERR_COMM);
     }
-    myrank=tMPI_Comm_seek_rank(comm, tMPI_Get_current());
+    myrank = tMPI_Comm_seek_rank(comm, tMPI_Get_current());
 
     /* we increase our counter, and determine which coll_env we get */
-    csync=&(comm->csync[myrank]);
+    csync = &(comm->csync[myrank]);
     csync->syncs++;
-    cev=&(comm->cev[csync->syncs % N_COLL_ENV]);
+    cev = &(comm->cev[csync->syncs % N_COLL_ENV]);
 
     /* now do a compare-and-swap on the current_syncc */
-    syncs=tMPI_Atomic_get( &(cev->coll.current_sync));
-    if ((csync->syncs - syncs > 0) && /* check if sync was an earlier number. 
-                                         If it is a later number, we can't 
+    syncs = tMPI_Atomic_get( &(cev->coll.current_sync));
+    if ((csync->syncs - syncs > 0) && /* check if sync was an earlier number.
+                                         If it is a later number, we can't
                                          have been the first to arrive here. */
         tMPI_Atomic_cas(&(cev->coll.current_sync), syncs, csync->syncs))
     {
         /* we're the first! */
         function(param);
         if (was_first)
-            *was_first=TRUE;
+        {
+            *was_first = TRUE;
+        }
     }
     return ret;
 }
 
-void* tMPI_Once_wait(tMPI_Comm comm, void* (*function)(void*), void *param, 
+void* tMPI_Once_wait(tMPI_Comm comm, void* (*function)(void*), void *param,
                      int *was_first)
 {
-    int myrank;
+    int               myrank;
     struct coll_sync *csync;
-    struct coll_env *cev;
-    int syncs;
-    void *ret;
+    struct coll_env  *cev;
+    int               syncs;
+    void             *ret;
 
 
     if (!comm)
@@ -109,31 +111,33 @@ void* tMPI_Once_wait(tMPI_Comm comm, void* (*function)(void*), void *param,
         tMPI_Error(TMPI_COMM_WORLD, TMPI_ERR_COMM);
         return NULL;
     }
-    myrank=tMPI_Comm_seek_rank(comm, tMPI_Get_current());
+    myrank = tMPI_Comm_seek_rank(comm, tMPI_Get_current());
 
     /* we increase our counter, and determine which coll_env we get */
-    csync=&(comm->csync[myrank]);
+    csync = &(comm->csync[myrank]);
     csync->syncs++;
-    cev=&(comm->cev[csync->syncs % N_COLL_ENV]);
+    cev = &(comm->cev[csync->syncs % N_COLL_ENV]);
 
     /* now do a compare-and-swap on the current_syncc */
-    syncs=tMPI_Atomic_get( &(cev->coll.current_sync));
+    syncs = tMPI_Atomic_get( &(cev->coll.current_sync));
     tMPI_Atomic_memory_barrier_acq();
-    if ((csync->syncs - syncs > 0) && /* check if sync was an earlier number. 
-                                         If it is a later number, we can't 
-                                         have been the first to arrive here. 
+    if ((csync->syncs - syncs > 0) && /* check if sync was an earlier number.
+                                         If it is a later number, we can't
+                                         have been the first to arrive here.
                                          Calculating the difference instead
-                                         of comparing directly avoids ABA 
+                                         of comparing directly avoids ABA
                                          problems. */
         tMPI_Atomic_cas(&(cev->coll.current_sync), syncs, csync->syncs))
     {
         /* we're the first! */
-        ret=function(param);
+        ret = function(param);
         if (was_first)
-            *was_first=TRUE;
+        {
+            *was_first = TRUE;
+        }
 
         /* broadcast the output data */
-        cev->coll.res=ret;
+        cev->coll.res = ret;
 
         tMPI_Atomic_memory_barrier_rel();
         /* signal that we're done */
@@ -148,11 +152,12 @@ void* tMPI_Once_wait(tMPI_Comm comm, void* (*function)(void*), void *param,
         do
         {
             /*tMPI_Atomic_memory_barrier();*/
-            syncs=tMPI_Atomic_get( &(cev->coll.current_sync) );
-        } while (csync->syncs - syncs > 0); /* difference again due to ABA 
+            syncs = tMPI_Atomic_get( &(cev->coll.current_sync) );
+        }
+        while (csync->syncs - syncs > 0);   /* difference again due to ABA
                                                problems */
         tMPI_Atomic_memory_barrier_acq();
-        ret=cev->coll.res;
+        ret = cev->coll.res;
     }
     return ret;
 }
@@ -160,7 +165,7 @@ void* tMPI_Once_wait(tMPI_Comm comm, void* (*function)(void*), void *param,
 
 static void *tMPI_Shmallocator(void *prm)
 {
-    size_t sz=*((size_t*)prm);
+    size_t sz = *((size_t*)prm);
     return malloc(sz);
 }
 
@@ -168,6 +173,3 @@ void *tMPI_Shmalloc(tMPI_Comm comm, size_t size)
 {
     return tMPI_Once_wait(comm, tMPI_Shmallocator, &size, NULL);
 }
-
-
-