Commit 0e9680ab authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'menpo_try' into 'master'

Added menpo and dlib back in

See merge request !411
parents f65d041d befed77c
Pipeline #29436 passed with stage
in 25 minutes and 30 seconds
The images face.jpg/face.png are used under the Creative Commons 2.0 License,
which can be found here:
https://creativecommons.org/licenses/by/2.0/
The image was found on Flickr under the following URL:
https://flic.kr/p/x1TgvF
and was provided by user Jane Kostenko (layma1999):
https://www.flickr.com/photos/133533365@N06/
The "medium" version of the image was downloaded on 21/07/2016 and was modified
only via reencoding to png.
The intended use of this image is for testing purposes only.
@echo ON
mkdir build
cd build
rem The Python lib has no period in the version string, so we remove it here.
set PY_VER_NO_DOT=%PY_VER:.=%
rem Required as the png locator does some processing that chokes on \
set "PNG_LIBRARY=%LIBRARY_LIB%\libpng16.lib"
set "PNG_LIBRARY=%PNG_LIBRARY:\=/%"
rem There is a bug whereby linking to jpeg causes a link crash, so we allow
rem dlib to build it
cmake ..\tools\python -LAH -G"NMake Makefiles" ^
-DCMAKE_BUILD_TYPE="Release" ^
-DCMAKE_PREFIX_PATH="%LIBRARY_PREFIX%" ^
-DBoost_USE_STATIC_LIBS=0 ^
-DBoost_USE_STATIC_RUNTIME=0 ^
-DBOOST_ROOT="%LIBRARY_PREFIX%" ^
-DBOOST_INCLUDEDIR="%LIBRARY_INC%" ^
-DBOOST_LIBRARYDIR="%LIBRARY_LIB%" ^
-DPYTHON3=%PY3K% ^
-DPYTHON_LIBRARY="%PREFIX%\libs\python%PY_VER_NO_DOT%.lib" ^
-DPYTHON_INCLUDE_DIR="%PREFIX%\include" ^
-DDLIB_LINK_WITH_SQLITE3=0 ^
-DDLIB_PNG_SUPPORT=1 ^
-DPNG_INCLUDE_DIR="%LIBRARY_INC%" ^
-DPNG_PNG_INCLUDE_DIR="%LIBRARY_INC%" ^
-DPNG_LIBRARY="%PNG_LIBRARY%" ^
-DZLIB_INCLUDE_DIRS="%LIBRARY_INC%" ^
-DZLIB_LIBRARIES="%LIBRARY_BIN%\zlib.dll" ^
-DDLIB_JPEG_SUPPORT=1 ^
-DDLIB_USE_BLAS=0 ^
-DDLIB_USE_LAPACK=0 ^
-DUSE_SSE2_INSTRUCTIONS=1 ^
-DUSE_SSE4_INSTRUCTIONS=0 ^
-DUSE_AVX_INSTRUCTIONS=0 ^
-DDLIB_USE_CUDA=0 ^
-DDLIB_GIF_SUPPORT=0
if errorlevel 1 exit 1
cmake --build . --target INSTALL --config Release
if errorlevel 1 exit 1
rem Copy the dlib library to site packages
move "..\python_examples\dlib.pyd" "%SP_DIR%\dlib.pyd"
if errorlevel 1 exit 1
#!/bin/bash
set +x
rm -fr build
mkdir -p build
cd build
if [ $PY3K -eq 1 ]; then
export PY_STR="${PY_VER}m"
else
export PY_STR="${PY_VER}"
fi
# Make the probably sensible assumption that a 64-bit
# machine supports SSE4 instructions - if this becomes
# a problem we should turn this off.
if [ $ARCH -eq 64 ]; then
USE_SSE4=1
else
USE_SSE4=0
fi
PYTHON_LIBRARY_PATH="$PREFIX/lib/libpython$PY_STR$SHLIB_EXT"
cmake -LAH ../tools/python \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE="Release" \
-DBoost_USE_STATIC_LIBS=0 \
-DBoost_USE_STATIC_RUNTIME=0 \
-DBOOST_ROOT="$PREFIX" \
-DBOOST_INCLUDEDIR="$PREFIX/include" \
-DBOOST_LIBRARYDIR="$PREFIX/lib" \
-DPYTHON_LIBRARY="$PYTHON_LIBRARY_PATH" \
-DPYTHON_INCLUDE_DIR="$PREFIX/include/python$PY_STR" \
-DPYTHON3=$PY3K \
-DDLIB_PNG_SUPPORT=1 \
-DPNG_INCLUDE_DIR="$PREFIX/include" \
-DPNG_PNG_INCLUDE_DIR="$PREFIX/include" \
-DPNG_LIBRARY="$PREFIX/lib/libpng$SHLIB_EXT" \
-DZLIB_INCLUDE_DIRS="$PREFIX/include" \
-DZLIB_LIBRARIES="$PREFIX/lib/libz$SHLIB_EXT" \
-DDLIB_JPEG_SUPPORT=1 \
-DJPEG_INCLUDE_DIR="$PREFIX/include" \
-DJPEG_LIBRARY="$PREFIX/lib/libjpeg$SHLIB_EXT" \
-DDLIB_LINK_WITH_SQLITE3=1 \
-DDLIB_NO_GUI_SUPPORT=1 \
-DUSE_SSE2_INSTRUCTIONS=1 \
-DUSE_SSE4_INSTRUCTIONS=$USE_SSE4 \
-DUSE_AVX_INSTRUCTIONS=0 \
-DDLIB_USE_BLAS=1 \
-DDLIB_USE_LAPACK=1 \
-DDLIB_USE_CUDA=0 \
-DDLIB_GIF_SUPPORT=0
make -j$CPU_COUNT
# Non-standard installation - copy manually
cp dlib.so $SP_DIR
<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml-stylesheet type='text/xsl' href='image_metadata_stylesheet.xsl'?>
<dataset>
<name>Training faces</name>
<comment>See the FACE_LICENSE file for more information.</comment>
<images>
<image file='face.jpg'>
<box top='125' left='156' width='278' height='240'/>
</image>
<image file='face.png'>
<box top='125' left='156' width='278' height='240'/>
</image>
</images>
</dataset>
--- dlib/cmake_utils/cmake_find_blas.txt
+++ dlib/cmake_utils/cmake_find_blas.txt
@@ -156,15 +156,8 @@
set(blas_found 1)
message(STATUS "Found OpenBLAS library")
set(CMAKE_REQUIRED_LIBRARIES ${blas_libraries})
- # If you compiled OpenBLAS with LAPACK in it then it should have the
- # sgetrf_single function in it. So if we find that function in
- # OpenBLAS then just use OpenBLAS's LAPACK.
- CHECK_FUNCTION_EXISTS(sgetrf_single OPENBLAS_HAS_LAPACK)
- if (OPENBLAS_HAS_LAPACK)
- message(STATUS "Using OpenBLAS's built in LAPACK")
- # set(lapack_libraries gfortran)
- set(lapack_found 1)
- endif()
+ message(STATUS "Using OpenBLAS's built in LAPACK")
+ set(lapack_found 1)
endif()
mark_as_advanced( cblas_lib)
endif()
{% set name = "dlib" %}
{% set version = "19.7" %}
package:
name: {{ name }}
version: {{ version }}
source:
url: https://github.com/davisking/{{ name }}/archive/v{{ version }}.tar.gz
sha1: 6dfc0dfa1cd45baa39a9b03238b222cd59041194
patches:
- osx_jpeg.patch # [osx]
- lapack_sgetrf.patch # [unix]
- win_boost.patch # [win]
- win_jpeg_png.patch # [win]
- win_release_flags.patch # [win]
- win_thread_fix.patch # [win]
build:
number: 2
skip: True # [blas_impl == 'mkl' and win]
requires_features:
blas: {{ mkl }}
requirements:
build:
- cmake
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- pkg-config
host:
- python
- numpy {{ numpy }}
- py-boost {{ boost }}
- libpng {{ libpng }}
- mkl-devel {{ mkl }} # [blas_impl == 'mkl']
- jpeg {{ jpeg }} # [not win]
- sqlite {{ sqlite }} # [not win]
run:
- python
- {{ pin_compatible('numpy') }}
- py-boost {{ boost }}
test:
files:
- face.jpg
- face.png
- images.xml
requires:
- tqdm
- pillow
imports:
- dlib
commands:
- conda inspect linkages -p $PREFIX {{ name }} # [not win]
- conda inspect objects -p $PREFIX {{ name }} # [osx]
about:
home: http://dlib.net/
license: Boost 1.0
license_file: dlib/LICENSE.txt
summary: Modern C++ toolkit containing machine learning algorithms with Python bindings
extra:
recipe-maintainers:
- tiago.pereira
- anjos
- amohammadi
--- dlib/CMakeLists.txt
+++ dlib/CMakeLists.txt
@@ -403,7 +403,7 @@
set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARY})
CHECK_FUNCTION_EXISTS(jpeg_read_header LIBJPEG_IS_GOOD)
endif()
- if (JPEG_FOUND AND LIBJPEG_IS_GOOD AND NOT APPLE)
+ if (JPEG_FOUND AND LIBJPEG_IS_GOOD)
include_directories(${JPEG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY})
else()
import os
import sys
import bz2
import unittest
from functools import partial
import dlib
import numpy as np
from PIL import Image
from tqdm import tqdm
SHAPE_PREDICTOR_FNAME = 'shape_predictor_68_face_landmarks.dat'
SHAPE_PREDICTOR_BZ2_FNAME = SHAPE_PREDICTOR_FNAME + '.bz2'
SHAPE_PREDICTOR_URL = 'http://dlib.net/files/{}'.format(SHAPE_PREDICTOR_BZ2_FNAME)
def _download_file(url, out_path):
try:
from urllib import urlretrieve # Python 2
except ImportError:
from urllib.request import urlretrieve # Python 3
# Wrap tqdm instance with urlretrieve compatible function
# Abuse mutable [] argument to give function 'memory'
# First argument will be supplied using partial (an instance of tqdm)
def reporthook(t, b=1, bsize=1, tsize=None, last_b=[0]):
if tsize is not None:
t.total = tsize
t.update((b - last_b[0]) * bsize)
last_b[0] = b
with tqdm(unit='B', unit_scale=True, miniters=1, desc=out_path) as t:
urlretrieve(url, filename=out_path, reporthook=partial(reporthook, t))
def _bz2_decompress_inplace(path, out_path):
with open(path, 'rb') as source, open(out_path, 'wb') as dest:
dest.write(bz2.decompress(source.read()))
def _load_image_using_pillow(path):
return np.array(Image.open(path))
class TestDlib(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Get paths to test data
test_dir_path = os.path.dirname(os.path.abspath(__file__))
cls.face_jpg_path = os.path.join(test_dir_path, 'face.jpg')
cls.face_png_path = os.path.join(test_dir_path, 'face.png')
# Download shape_predictor model
print('Downloading {} to ./{}'.format(SHAPE_PREDICTOR_URL,
SHAPE_PREDICTOR_BZ2_FNAME))
_download_file(SHAPE_PREDICTOR_URL, SHAPE_PREDICTOR_BZ2_FNAME)
_bz2_decompress_inplace(SHAPE_PREDICTOR_BZ2_FNAME,
SHAPE_PREDICTOR_FNAME)
def test_builtin_frontal_face_detection(self):
detector = dlib.get_frontal_face_detector()
image = _load_image_using_pillow(self.face_jpg_path)
results = detector(image)
self.assertEqual(len(results), 1)
def test_shape_predictor(self):
predictor = dlib.shape_predictor(SHAPE_PREDICTOR_FNAME)
image = _load_image_using_pillow(self.face_jpg_path)
# This is the output of the detector, hardcoded
detection = dlib.rectangle(left=125, top=56, right=434, bottom=365)
shape = predictor(image, detection)
self.assertEqual(len(shape.parts()), 68)
for p in shape.parts():
self.assertGreater(p.x, 0)
self.assertGreater(p.y, 0)
def test_train_xml_detector(self):
# This effectively tests that we can successfully load images
options = dlib.simple_object_detector_training_options()
options.add_left_right_image_flips = True
options.C = 1
options.num_threads = 1
dlib.train_simple_object_detector('images.xml', "test.svm", options)
self.assertTrue(os.path.exists('./test.svm'))
if __name__ == '__main__':
unittest.main()
--- dlib/cmake_utils/add_python_module
+++ dlib/cmake_utils/add_python_module
@@ -35,45 +35,15 @@
list(APPEND CMAKE_PREFIX_PATH "${PYTHON_PATH}")
-# To avoid dll hell, always link everything statically when compiling in
-# visual studio. This way, the resulting library won't depend on a bunch
-# of other dll files and can be safely copied to someone elese's computer
-# and expected to run.
-if (MSVC)
- include(${CMAKE_CURRENT_LIST_DIR}/tell_visual_studio_to_use_static_runtime.cmake)
- add_definitions(-DBOOST_PYTHON_STATIC_LIB)
- SET(Boost_USE_STATIC_LIBS ON)
- SET(Boost_USE_MULTITHREADED ON)
- SET(Boost_USE_STATIC_RUNTIME ON)
-endif()
-
-set(Boost_NO_BOOST_CMAKE ON)
-
if (NOT WIN32)
set(BOOST_LIBRARYDIR ${BOOST_LIBRARYDIR} $ENV{BOOST_LIBRARYDIR}
/usr/lib/x86_64-linux-gnu/)
else()
link_directories($ENV{BOOST_LIBRARYDIR})
endif()
-if (PYTHON3)
- # On some systems the boost python3 module is called python-py34 so check
- # for that one first.
- FIND_PACKAGE(Boost 1.41.0 COMPONENTS python-py34 )
- if (NOT Boost_FOUND)
- FIND_PACKAGE(Boost 1.41.0 COMPONENTS python-py35)
- endif()
- if (NOT Boost_FOUND)
- FIND_PACKAGE(Boost 1.41.0 COMPONENTS python3)
- endif()
- if (NOT Boost_FOUND)
- FIND_PACKAGE(Boost 1.41.0 COMPONENTS python)
- endif()
- set(Python_ADDITIONAL_VERSIONS 3.5 3.6)
- FIND_PACKAGE(PythonLibs 3.4)
-else()
- FIND_PACKAGE(Boost 1.41.0 COMPONENTS python)
- FIND_PACKAGE(PythonLibs 2.6)
-endif()
+
+FIND_PACKAGE(Boost 1.41.0 COMPONENTS python3)
+FIND_PACKAGE(PythonLibs $ENV{PY_VER} REQUIRED)
if (CMAKE_COMPILER_IS_GNUCXX)
# Just setting CMAKE_POSITION_INDEPENDENT_CODE should be enough to set
--- dlib/CMakeLists.txt
+++ dlib/CMakeLists.txt
@@ -339,66 +339,11 @@
if (DLIB_PNG_SUPPORT)
# try to find libpng
- find_package(PNG QUIET)
- # Make sure there isn't something wrong with the version of LIBPNG
- # installed on this system.
- if (PNG_FOUND)
- set(CMAKE_REQUIRED_LIBRARIES ${PNG_LIBRARIES})
- CHECK_FUNCTION_EXISTS(png_create_read_struct LIBPNG_IS_GOOD)
- endif()
- if (PNG_FOUND AND LIBPNG_IS_GOOD)
+ find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
set (dlib_needed_libraries ${dlib_needed_libraries} ${PNG_LIBRARIES})
set(REQUIRES_LIBS " libpng")
- else()
- # If we can't find libpng then statically compile it in.
- include_directories(external/libpng external/zlib)
- set(source_files ${source_files}
- external/libpng/png.c
- external/libpng/pngerror.c
- external/libpng/pngget.c
- external/libpng/pngmem.c
- external/libpng/pngpread.c
- external/libpng/pngread.c
- external/libpng/pngrio.c
- external/libpng/pngrtran.c
- external/libpng/pngrutil.c
- external/libpng/pngset.c
- external/libpng/pngtrans.c
- external/libpng/pngwio.c
- external/libpng/pngwrite.c
- external/libpng/pngwtran.c
- external/libpng/pngwutil.c
- external/zlib/adler32.c
- external/zlib/compress.c
- external/zlib/crc32.c
- external/zlib/deflate.c
- external/zlib/gzclose.c
- external/zlib/gzlib.c
- external/zlib/gzread.c
- external/zlib/gzwrite.c
- external/zlib/infback.c
- external/zlib/inffast.c
- external/zlib/inflate.c
- external/zlib/inftrees.c
- external/zlib/trees.c
- external/zlib/uncompr.c
- external/zlib/zutil.c
- )
-
- include(cmake_utils/check_if_neon_available.cmake)
- if (ARM_NEON_IS_AVAILABLE)
- message (STATUS "NEON instructions will be used for libpng.")
- enable_language(ASM)
- set(source_files ${source_files}
- external/libpng/arm/arm_init.c
- external/libpng/arm/filter_neon_intrinsics.c
- external/libpng/arm/filter_neon.S
- )
- set_source_files_properties(external/libpng/arm/filter_neon.S PROPERTIES COMPILE_FLAGS "${CMAKE_ASM_FLAGS} ${CMAKE_CXX_FLAGS} -x assembler-with-cpp")
- endif()
- set(REQUIRES_LIBS "")
- endif()
+
set(source_files ${source_files}
image_loader/png_loader.cpp
image_saver/save_png.cpp
@@ -406,19 +351,6 @@
endif()
if (DLIB_JPEG_SUPPORT)
- # try to find libjpeg
- find_package(JPEG QUIET)
- # Make sure there isn't something wrong with the version of libjpeg
- # installed on this system. Also don't use the installed libjpeg
- # if this is an APPLE system because apparently it's broken (as of 2015/01/01).
- if (JPEG_FOUND)
- set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARY})
- CHECK_FUNCTION_EXISTS(jpeg_read_header LIBJPEG_IS_GOOD)
- endif()
- if (JPEG_FOUND AND LIBJPEG_IS_GOOD AND NOT APPLE)
- include_directories(${JPEG_INCLUDE_DIR})
- set (dlib_needed_libraries ${dlib_needed_libraries} ${JPEG_LIBRARY})
- else()
# If we can't find libjpeg then statically compile it in.
add_definitions(-DDLIB_JPEG_STATIC)
set(source_files ${source_files}
@@ -467,7 +399,6 @@
external/libjpeg/jfdctflt.cpp
external/libjpeg/jfdctfst.cpp
)
- endif()
set(source_files ${source_files}
image_loader/jpeg_loader.cpp
image_saver/save_jpeg.cpp
--- dlib/cmake_utils/add_global_compiler_switch.cmake
+++ dlib/cmake_utils/add_global_compiler_switch.cmake
@@ -7,18 +7,18 @@
macro ( add_global_compiler_switch switch_name )
# If removing the switch would change the flags then it's already present
# and we don't need to do anything.
- string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS}")
- if ("${CMAKE_CXX_FLAGS}" STREQUAL "${tempstr}" )
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${switch_name}"
+ string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS_RELEASE}")
+ if ("${CMAKE_CXX_FLAGS_RELEASE}" STREQUAL "${tempstr}" )
+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${switch_name}"
CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE)
endif ()
endmacro()
macro ( remove_global_compiler_switch switch_name )
- string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS}")
- if (NOT "${CMAKE_CXX_FLAGS}" STREQUAL "${tempstr}" )
- set (CMAKE_CXX_FLAGS "${tempstr}"
+ string(REPLACE "${switch_name}" "" tempstr "${CMAKE_CXX_FLAGS_RELEASE}")
+ if (NOT "${CMAKE_CXX_FLAGS_RELEASE}" STREQUAL "${tempstr}" )
+ set (CMAKE_CXX_FLAGS_RELEASE "${tempstr}"
CACHE STRING "Flags used by the compiler during all C++ builds."
FORCE)
endif ()
--- dlib/threads/threads_kernel_1.h
+++ dlib/threads/threads_kernel_1.h
@@ -12,6 +12,9 @@
#include "../windows_magic.h"
#include <windows.h>
#include "../algs.h"
+#include <condition_variable>
+#include <mutex>
+#include <chrono>
namespace dlib
@@ -43,21 +46,22 @@ namespace dlib
mutex (
)
{
- InitializeCriticalSection(&cs);
}
~mutex (
- ) { DeleteCriticalSection(&cs); }
+ ) { }
void lock (
- ) const { EnterCriticalSection(&cs); }
+ ) const { cs.lock(); }
void unlock (
- ) const { LeaveCriticalSection(&cs); }
+ ) const { cs.unlock(); }
private:
- mutable CRITICAL_SECTION cs;
+ friend class signaler;
+
+ mutable std::mutex cs;
// restricted functions
mutex(mutex&); // copy constructor
@@ -77,147 +81,40 @@ namespace dlib
signaler (
const mutex& associated_mutex
) :
- hSemaphore(CreateSemaphore (NULL, 0, 100000000, NULL)),
- waiters(0),
- hCountSema(CreateSemaphore (NULL,0,100000000,NULL)),
m(associated_mutex)
{
- if (hSemaphore == NULL || hCountSema == NULL)
- {
- if (hSemaphore != NULL)
- {
- CloseHandle(hSemaphore);
- }
-
- if (hCountSema != NULL)
- {
- CloseHandle(hCountSema);
- }
-
- throw dlib::thread_error(ECREATE_SIGNALER,
- "in function signaler::signaler() an error occurred making the signaler"
- );
- }
+
}
~signaler (
- ) { CloseHandle(hSemaphore); CloseHandle(hCountSema);}
+ ) { }
void wait (
) const
{
- // get a lock on the mutex for the waiters variable
- waiters_mutex.lock();
- // mark that one more thread will be waiting on this signaler
- ++waiters;
- // release the mutex for waiters
- waiters_mutex.unlock();
-
- // release the associated mutex
- m.unlock();
-
- // wait for the semaphore to be signaled
- WaitForSingleObject (hSemaphore,INFINITE);
-
- // signal that we are awake
- ReleaseSemaphore(hCountSema,(LONG)1,NULL);
-
- // relock the associated mutex
- m.lock();
+ std::unique_lock<std::mutex> cs(m.cs, std::defer_lock);
+ cv.wait(cs);
}
bool wait_or_timeout (
unsigned long milliseconds
) const
{
- // get a lock on the mutex for the waiters variable
- waiters_mutex.lock();
- // mark that one more thread will be waiting on this signaler
- ++waiters;
- // release the mutex for waiters
- waiters_mutex.unlock();
-
- // release the associated mutex
- m.unlock();
-
- bool value;
-
- // wait for the semaphore to be signaled
- if ( WaitForSingleObject (hSemaphore, milliseconds ) == WAIT_TIMEOUT )
- {
- // in this case we should decrement waiters because we are returning
- // due to a timeout rather than because someone called signal() or
- // broadcast().
- value = false;
-
- // signal that we are awake
- ReleaseSemaphore(hCountSema,(LONG)1,NULL);
-
- // get a lock on the mutex for the waiters variable
- waiters_mutex.lock();
- // mark that one less thread will be waiting on this signaler.
- if (waiters != 0)
- --waiters;
- // release the mutex for waiters
- waiters_mutex.unlock();
- }
- else
- {
- value = true;
-
- // signal that we are awake
- ReleaseSemaphore(hCountSema,(LONG)1,NULL);
- }
-
-
- // relock the associated mutex
- m.lock();
-
- return value;
+ std::unique_lock<std::mutex> cs(m.cs, std::defer_lock);
+ auto status = cv.wait_until(cs, std::chrono::system_clock::now() + std::chrono::milliseconds(milliseconds));
+ return status == std::cv_status::no_timeout;
}
void signal (
) const
{
- // get a lock on the mutex for the waiters variable
- waiters_mutex.lock();
-
- if (waiters > 0)
- {
- --waiters;
- // make the semaphore release one waiting thread
- ReleaseSemaphore(hSemaphore,1,NULL);
-
- // wait for signaled thread to wake up
- WaitForSingleObject(hCountSema,INFINITE);
- }
-
- // release the mutex for waiters
- waiters_mutex.unlock();
+ cv.notify_one();
}
void broadcast (
) const
{
- // get a lock on the mutex for the waiters variable
- waiters_mutex.lock();
-
- if (waiters > 0)
- {
- // make the semaphore release all the waiting threads
- ReleaseSemaphore(hSemaphore,(LONG)waiters,NULL);
-
- // wait for count to be zero
- for (unsigned long i = 0; i < waiters; ++i)
- {
- WaitForSingleObject(hCountSema,INFINITE);
- }
-
- waiters = 0;
- }
-
- // release the mutex for waiters
- waiters_mutex.unlock();
+ cv.notify_all();
}
const mutex& get_mutex (
@@ -225,13 +122,7 @@ namespace dlib
private:
- mutable HANDLE hSemaphore;
-
- mutable unsigned long waiters;
- mutex waiters_mutex;
-
-
- mutable HANDLE hCountSema;
+ mutable std::condition_variable cv;
const mutex& m;
--
2.14.2
[run]
branch=True
source=menpo
omit =
*/visualize/*
*/_version.*
[report]
exclude_lines =
raise NotImplementedError
ignore_errors=True