"Fossies" - the Fresh Open Source Software Archive

Member "openpa-1.0.4/src/opa_primitives.c" (5 Dec 2012, 1284 Bytes) of package /linux/misc/openpa-1.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "opa_primitives.c" see the Fossies "Dox" file reference documentation.

    1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
    2 /*  
    3  *  (C) 2008 by Argonne National Laboratory.
    4  *      See COPYRIGHT in top-level directory.
    5  */
    6 
    7 #include "opa_config.h"
    8 
    9 /* FIXME For now we rely on pthreads for our IPC locks.  This is fairly
   10    portable, although it is obviously not 100% portable.  We need to
   11    figure out how to support other threading packages and lock
   12    implementations, such as the BG/P lockbox. */
   13 #if defined(OPA_HAVE_PTHREAD_H)
   14 #include <pthread.h>
   15 #include <opa_primitives.h>
   16 
   17 pthread_mutex_t *OPA_emulation_lock = NULL;
   18 
   19 int OPA_Interprocess_lock_init(OPA_emulation_ipl_t *shm_lock, int isLeader)
   20 {
   21     int mpi_errno = 0; /*MPI_SUCCESS*/
   22     pthread_mutexattr_t attr;
   23     OPA_emulation_lock = shm_lock;
   24 
   25     if (isLeader) {
   26         /* Set the mutex attributes to work correctly on inter-process
   27          * shared memory as well. This is required for some compilers
   28          * (such as SUN Studio) that don't enable it by default. */
   29         if (pthread_mutexattr_init(&attr) ||
   30             pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED) ||
   31             pthread_mutex_init(OPA_emulation_lock, &attr))
   32             mpi_errno = 16; /* MPI_ERR_INTERN */
   33     }
   34 
   35     return mpi_errno;
   36 }
   37 #endif /* defined(OPA_HAVE_PTHREAD_H) */
   38