00001 // cache-line padded simple spin lock -*- C++ -*- 00002 /* 00003 Galois, a framework to exploit amorphous data-parallelism in irregular 00004 programs. 00005 00006 Copyright (C) 2011, The University of Texas at Austin. All rights reserved. 00007 UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS SOFTWARE 00008 AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR ANY 00009 PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF PERFORMANCE, AND ANY 00010 WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF DEALING OR USAGE OF TRADE. 00011 NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH RESPECT TO THE USE OF THE 00012 SOFTWARE OR DOCUMENTATION. Under no circumstances shall University be liable 00013 for incidental, special, indirect, direct or consequential damages or loss of 00014 profits, interruption of business, or related expenses which may arise from use 00015 of Software or Documentation, including but not limited to those resulting from 00016 defects in Software and/or Documentation, or loss or inaccuracy of data of any 00017 kind. 00018 */ 00019 00020 #ifndef _PADDED_LOCK_H 00021 #define _PADDED_LOCK_H 00022 00023 #include "SimpleLock.h" 00024 #include "CacheLineStorage.h" 00025 00026 namespace GaloisRuntime { 00027 00028 template<bool concurrent> 00029 class PaddedLock; 00030 00031 template<> 00032 class PaddedLock<true> { 00033 mutable cache_line_storage<SimpleLock<int, true> > Lock; 00034 00035 public: 00036 void lock() const { Lock.data.lock(); } 00037 bool try_lock() const { return Lock.data.try_lock(); } 00038 void unlock() const { Lock.data.unlock(); } 00039 }; 00040 00041 template<> 00042 class PaddedLock<false> { 00043 public: 00044 void lock() const {} 00045 bool try_lock() const { return true; } 00046 void unlock() const {} 00047 }; 00048 00049 } 00050 00051 #endif