00001 /* SVN FILE INFO 00002 * $Revision: 400 $ : Last Committed Revision 00003 * $Date: 2009-08-23 13:23:47 -0700 (Sun, 23 Aug 2009) $ : Last Committed Date */ 00004 /*[ 00005 * Copyright (c) 2007 Integration Engineering Laboratory 00006 University of California, Davis 00007 * 00008 * Permission to use, copy, and distribute this software and its 00009 * documentation for any purpose with or without fee is hereby granted, 00010 * provided that the above copyright notice appear in all copies and 00011 * that both that copyright notice and this permission notice appear 00012 * in supporting documentation. 00013 * 00014 * Permission to modify the software is granted, but not the right to 00015 * distribute the complete modified source code. Modifications are to 00016 * be distributed as patches to the released version. Permission to 00017 * distribute binaries produced by compiling modified sources is granted, 00018 * provided you 00019 * 1. distribute the corresponding source modifications from the 00020 * released version in the form of a patch file along with the binaries, 00021 * 2. add special version identification to distinguish your version 00022 * in addition to the base release version number, 00023 * 3. provide your name and address as the primary contact for the 00024 * support of your modified version, and 00025 * 4. retain our contact information in regard to use of the base 00026 * software. 00027 * Permission to distribute the released version of the source code along 00028 * with corresponding source modifications in the form of a patch file is 00029 * granted with same provisions 2 through 4 for binary distributions. 00030 * 00031 * This software is provided "as is" without express or implied warranty 00032 * to the extent permitted by applicable law. 00033 ]*/ 00034 #ifndef _WIN32 00035 #include "config.h" 00036 #else 00037 #include "winconfig.h" 00038 #endif 00039 00040 #include "include/barrier.h" 00041 #include "include/mc_error.h" 00042 00043 /* Node Funcs */ 00044 barrier_node_p 00045 barrier_node_Initialize(int id, int num_registered) 00046 { 00047 barrier_node_p node; 00048 00049 /* Memory Allocation */ 00050 node = (barrier_node_p)malloc(sizeof(barrier_node_t)); 00051 CHECK_NULL(node, return NULL;); 00052 node->lock = (MUTEX_T*)malloc(sizeof(MUTEX_T)); 00053 CHECK_NULL(node->lock, return NULL;); 00054 node->cond = (COND_T*)malloc(sizeof(COND_T)); 00055 CHECK_NULL(node->cond, return NULL;); 00056 00057 /* Sync Init */ 00058 MUTEX_INIT(node->lock); 00059 COND_INIT(node->cond); 00060 00061 /* Initial values */ 00062 node->id = id; 00063 node->num_registered = num_registered; 00064 node->num_waiting = 0; 00065 00066 return node; 00067 } 00068 00069 int 00070 barrier_node_Destroy(barrier_node_p node) 00071 { 00072 /* Sync Destroy */ 00073 MUTEX_DESTROY(node->lock); 00074 COND_DESTROY(node->cond); 00075 00076 /* Free Memory */ 00077 free(node->cond); 00078 free(node->lock); 00079 free(node); 00080 00081 return MC_SUCCESS; 00082 } 00083 00084 /* List Funcs */ 00085 00086 int barrier_node_CmpID (const void* key, void* element) 00087 { 00088 int ret; 00089 barrier_node_p e = (barrier_node_p)element; 00090 int k = *(int*)key; 00091 MUTEX_LOCK(e->lock); 00092 if(k == e->id) { 00093 ret = 0; 00094 } else { 00095 ret = 1; 00096 } 00097 MUTEX_UNLOCK(e->lock); 00098 return ret; 00099 } 00100