1
0

Skip unknown cflag for Apple clang & remove cSemaphore

This commit is contained in:
Cengiz Can 2015-06-02 01:26:57 +03:00
parent d871c47505
commit c967698b2d
8 changed files with 12 additions and 135 deletions

View File

@ -72,6 +72,7 @@ if(${BUILD_UNSTABLE_TOOLS})
add_subdirectory(Tools/GeneratorPerformanceTest/)
endif()
include(CheckCXXCompilerFlag)
include(SetFlags.cmake)
set_flags()
set_lib_flags()
@ -174,3 +175,4 @@ if (MSVC)
set_target_properties(arraystocoords-exe coordinates-exe copies-exe copyblocks-exe creatable-exe EchoServer Google-exe ChunkBuffer NameLookup PROPERTIES FOLDER Tests)
endif()
endif()

View File

@ -23,7 +23,7 @@ Here are the conventions:
- This helps prevent mistakes such as `if (a & 1 == 0)`
*
* Use the provided wrappers for OS stuff:
- Threading is done by inheriting from `cIsThread`, thread synchronization through `cCriticalSection`, `cSemaphore` and `cEvent`, file access and filesystem operations through the `cFile` class, high-precision timers through `cTimer`, high-precision sleep through `cSleep`
- Threading is done by inheriting from `cIsThread`, thread synchronization through `cCriticalSection` and `cEvent`, file access and filesystem operations through the `cFile` class, high-precision timers through `cTimer`, high-precision sleep through `cSleep`
* No magic numbers, use named constants:
- `E_ITEM_XXX`, `E_BLOCK_XXX` and `E_META_XXX` for items and blocks
- `cEntity::etXXX` for entity types, `cMonster::mtXXX` for mob types

View File

@ -63,7 +63,7 @@ macro(set_flags)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG")
elseif(APPLE)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION)
@ -262,8 +262,11 @@ macro(set_exe_flags)
add_flags_cxx("-Wno-documentation")
endif()
if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
# Use this flag to ignore error for a reserved macro problem in sqlite 3
add_flags_cxx("-Wno-reserved-id-macro")
check_cxx_compiler_flag(-Wno-reserved-id-macro HAS_NO_RESERVED_ID_MACRO)
if (HAS_NO_RESERVED_ID_MACRO)
# Use this flag to ignore error for a reserved macro problem in sqlite 3
add_flags_cxx("-Wno-reserved-id-macro")
endif()
endif()
endif()
endif()
@ -277,7 +280,7 @@ endmacro()
# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=missing-prototypes -Wno-error=deprecated")
# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=shadow -Wno-error=old-style-cast -Wno-error=switch-enum -Wno-error=switch")
# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=float-equal -Wno-error=global-constructors")
# if ("${CLANG_VERSION}" VERSION_GREATER 3.0)
# # flags that are not present in 3.0
# set_source_files_properties(${FILENAME} PROPERTIES COMPILE_FLAGS "-Wno-error=covered-switch-default ")
@ -286,4 +289,3 @@ endmacro()
# endif()
# endforeach()
# endif()

View File

@ -265,7 +265,6 @@ template class SizeChecker<UInt8, 1>;
// Common headers (part 1, without macros):
#include "StringUtils.h"
#include "OSSupport/CriticalSection.h"
#include "OSSupport/Semaphore.h"
#include "OSSupport/Event.h"
#include "OSSupport/File.h"
#include "Logger.h"

View File

@ -15,7 +15,6 @@ SET (SRCS
IsThread.cpp
NetworkInterfaceEnum.cpp
NetworkSingleton.cpp
Semaphore.cpp
ServerHandleImpl.cpp
StackTrace.cpp
TCPLinkImpl.cpp
@ -34,7 +33,6 @@ SET (HDRS
Network.h
NetworkSingleton.h
Queue.h
Semaphore.h
ServerHandleImpl.h
StackTrace.h
TCPLinkImpl.h

View File

@ -1,8 +1,8 @@
// Event.cpp
// Implements the cEvent object representing an OS-specific synchronization primitive that can be waited-for
// Implemented as an Event on Win and as a 1-semaphore on *nix
// Interfaces to the cEvent object representing a synchronization primitive that can be waited-for
// Implemented using C++11 condition variable and mutex
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules

View File

@ -1,107 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */)
#ifndef _WIN32
: m_bNamed( false)
#endif
{
#ifndef _WIN32
(void)a_MaxCount;
m_Handle = new sem_t;
if (sem_init( (sem_t*)m_Handle, 0, 0))
{
LOG("WARNING cSemaphore: Could not create unnamed semaphore, fallback to named.");
delete (sem_t*)m_Handle; // named semaphores return their own address
m_bNamed = true;
AString Name;
Printf(Name, "cSemaphore%p", this);
m_Handle = sem_open(Name.c_str(), O_CREAT, 777, a_InitialCount);
if (m_Handle == SEM_FAILED)
{
LOG("ERROR: Could not create Semaphore. (%i)", errno);
}
else
{
if (sem_unlink(Name.c_str()) != 0)
{
LOG("ERROR: Could not unlink cSemaphore. (%i)", errno);
}
}
}
#else
m_Handle = CreateSemaphore(
nullptr, // security attribute
a_InitialCount, // initial count
a_MaxCount, // maximum count
0 // name (optional)
);
#endif
}
cSemaphore::~cSemaphore()
{
#ifdef _WIN32
CloseHandle( m_Handle);
#else
if (m_bNamed)
{
if (sem_close( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not close cSemaphore. (%i)", errno);
}
}
else
{
sem_destroy( (sem_t*)m_Handle);
delete (sem_t*)m_Handle;
}
m_Handle = 0;
#endif
}
void cSemaphore::Wait()
{
#ifndef _WIN32
if (sem_wait( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not wait for cSemaphore. (%i)", errno);
}
#else
WaitForSingleObject( m_Handle, INFINITE);
#endif
}
void cSemaphore::Signal()
{
#ifndef _WIN32
if (sem_post( (sem_t*)m_Handle) != 0)
{
LOG("ERROR: Could not signal cSemaphore. (%i)", errno);
}
#else
ReleaseSemaphore( m_Handle, 1, nullptr);
#endif
}

View File

@ -1,17 +0,0 @@
#pragma once
class cSemaphore
{
public:
cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount = 0);
~cSemaphore();
void Wait();
void Signal();
private:
void * m_Handle; // HANDLE pointer
#ifndef _WIN32
bool m_bNamed;
#endif
};