parent
53619a79b4
commit
0a4b6fc056
@ -1,31 +0,0 @@
|
||||
include(ExternalProject)
|
||||
|
||||
set(ROBIN_MAP_SOURCE_DIR ${THIRD_PARTY_PATH}/robin_map)
|
||||
set(ROBIN_MAP_INCLUDE_DIR ${ROBIN_MAP_SOURCE_DIR}/src/extern_robin_map/include)
|
||||
|
||||
include_directories(${ROBIN_MAP_INCLUDE_DIR})
|
||||
|
||||
ExternalProject_Add(
|
||||
extern_robin_map
|
||||
${EXTERNAL_PROJECT_LOG_ARGS}
|
||||
GIT_REPOSITORY "https://github.com/Tessil/robin-map.git"
|
||||
GIT_TAG "v0.5.0"
|
||||
PREFIX ${ROBIN_MAP_SOURCE_DIR}
|
||||
UPDATE_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.3.0")
|
||||
set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/robin_map_dummy.c)
|
||||
file(WRITE ${dummyfile} "const char *dummy = \"${dummyfile}\";")
|
||||
add_library(robin_map STATIC ${dummyfile})
|
||||
else()
|
||||
add_library(robin_map INTERFACE)
|
||||
endif()
|
||||
|
||||
add_dependencies(robin_map extern_robin_map)
|
||||
|
||||
LIST(APPEND externl_project_dependencies robin_map)
|
@ -1,71 +0,0 @@
|
||||
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <mutex> // NOLINT
|
||||
#endif // !_WIN32
|
||||
|
||||
#include "paddle/fluid/platform/enforce.h"
|
||||
|
||||
namespace paddle {
|
||||
namespace framework {
|
||||
|
||||
#if !defined(_WIN32)
|
||||
struct SpinLock {
|
||||
SpinLock() { pthread_spin_init(&lock_, PTHREAD_PROCESS_PRIVATE); }
|
||||
|
||||
~SpinLock() { pthread_spin_destroy(&lock_); }
|
||||
|
||||
void Lock() {
|
||||
PADDLE_ENFORCE_EQ(pthread_spin_lock(&lock_), 0, "acquire spin lock failed");
|
||||
}
|
||||
|
||||
void Unlock() {
|
||||
PADDLE_ENFORCE_EQ(pthread_spin_unlock(&lock_), 0,
|
||||
"release spin lock failed");
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_spinlock_t lock_;
|
||||
};
|
||||
#else
|
||||
// FIXME(minqiyang): use mutex here to do fake spin lock
|
||||
struct SpinLock {
|
||||
void Lock() { mutex_.lock(); }
|
||||
|
||||
void Unlock() { mutex_.lock(); }
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
};
|
||||
#endif
|
||||
|
||||
class AutoSpinLock {
|
||||
public:
|
||||
explicit SpinLockGuard(SpinLock* spin_lock) : lock_(spin_lock) {
|
||||
lock_->Lock();
|
||||
}
|
||||
|
||||
~SpinLockGuard() { lock_->Unlock(); }
|
||||
|
||||
private:
|
||||
SpinLock* lock_;
|
||||
};
|
||||
|
||||
} // namespace framework
|
||||
} // namespace paddle
|
Loading…
Reference in new issue