Skip to content

Commit

Permalink
Merge pull request #1442 from fspindle/feat_ci
Browse files Browse the repository at this point in the history
Update macos ci
  • Loading branch information
fspindle authored Jul 17, 2024
2 parents 1e13553 + 2394054 commit 133df82
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 142 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/macos-linux-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ name: MacOS-Linux-conda-CI
on:
pull_request:
types: [opened, reopened, synchronize]

# https://stackoverflow.com/questions/66335225/how-to-cancel-previous-runs-in-the-pr-when-you-push-new-commitsupdate-the-curre#comment133398800_72408109
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ jobs:
# Openblas location is exported explicitly because openblas is keg-only,
# which means it was not symlinked into /usr/local/.
# qt@5 is as a requested dependency for vtk and thus for pcl 1.12.1
# qt@5 is keg-only, which means it was not symlinked into /usr/local that's why we need to set Qt5_DIR
- name: Configure CMake
run: |
export LDFLAGS="-L/usr/local/opt/openblas/lib"
export CPPFLAGS="-I/usr/local/opt/openblas/include"
export Qt5_DIR="$(brew --prefix qt5)/lib/cmake/Qt5"
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON -DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/usr/local -DCMAKE_VERBOSE_MAKEFILE=ON
cat ViSP-third-party.txt
- name: Compile
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"core": "cpp",
"dense": "cpp",
"stdvector": "cpp",
"numericaldiff": "cpp"
"numericaldiff": "cpp",
"source_location": "cpp"
},
"C_Cpp.vcFormat.indent.namespaceContents": false,
"editor.formatOnSave": true,
Expand Down
250 changes: 128 additions & 122 deletions 3rdparty/apriltag/common/workerpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ either expressed or implied, of the Regents of The University of Michigan.
*/
#include <errno.h>

// To avoid "__USE_GNU" redefined 29 | #define __USE_GNU | In file included from /usr/include/errno.h
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <pthread.h>
#include <sched.h>
#include <assert.h>
Expand All @@ -45,184 +48,187 @@ either expressed or implied, of the Regents of The University of Michigan.
#include "math_util.h"
#include "string_util.h"

struct workerpool {
int nthreads;
zarray_t *tasks;
int taskspos;
struct workerpool
{
int nthreads;
zarray_t *tasks;
int taskspos;

pthread_t *threads;
int *status;
pthread_t *threads;
int *status;

pthread_mutex_t mutex;
pthread_cond_t startcond; // used to signal the availability of work
bool start_predicate; // predicate that prevents spurious wakeups on startcond
pthread_cond_t endcond; // used to signal completion of all work
pthread_mutex_t mutex;
pthread_cond_t startcond; // used to signal the availability of work
bool start_predicate; // predicate that prevents spurious wakeups on startcond
pthread_cond_t endcond; // used to signal completion of all work

int end_count; // how many threads are done?
int end_count; // how many threads are done?
};

struct task
{
void (*f)(void *p);
void *p;
void (*f)(void *p);
void *p;
};

void *worker_thread(void *p)
{
workerpool_t *wp = (workerpool_t*) p;
workerpool_t *wp = (workerpool_t *)p;

while (1) {
struct task *task;
while (1) {
struct task *task;

pthread_mutex_lock(&wp->mutex);
while (wp->taskspos == zarray_size(wp->tasks) || !wp->start_predicate) {
wp->end_count++;
pthread_cond_broadcast(&wp->endcond);
pthread_cond_wait(&wp->startcond, &wp->mutex);
}
pthread_mutex_lock(&wp->mutex);
while (wp->taskspos == zarray_size(wp->tasks) || !wp->start_predicate) {
wp->end_count++;
pthread_cond_broadcast(&wp->endcond);
pthread_cond_wait(&wp->startcond, &wp->mutex);
}

zarray_get_volatile(wp->tasks, wp->taskspos, &task);
wp->taskspos++;
pthread_mutex_unlock(&wp->mutex);
sched_yield();
zarray_get_volatile(wp->tasks, wp->taskspos, &task);
wp->taskspos++;
pthread_mutex_unlock(&wp->mutex);
sched_yield();

// we've been asked to exit.
if (task->f == NULL)
return NULL;
// we've been asked to exit.
if (task->f == NULL)
return NULL;

task->f(task->p);
}
task->f(task->p);
}

return NULL;
return NULL;
}

workerpool_t *workerpool_create(int nthreads)
{
assert(nthreads > 0);

workerpool_t *wp = (workerpool_t *)calloc(1, sizeof(workerpool_t));
wp->nthreads = nthreads;
wp->tasks = zarray_create(sizeof(struct task));
wp->start_predicate = false;
assert(nthreads > 0);

workerpool_t *wp = (workerpool_t *)calloc(1, sizeof(workerpool_t));
wp->nthreads = nthreads;
wp->tasks = zarray_create(sizeof(struct task));
wp->start_predicate = false;

if (nthreads > 1) {
wp->threads = (pthread_t *)calloc(wp->nthreads, sizeof(pthread_t));

pthread_mutex_init(&wp->mutex, NULL);
pthread_cond_init(&wp->startcond, NULL);
pthread_cond_init(&wp->endcond, NULL);

for (int i = 0; i < nthreads; i++) {
int res = pthread_create(&wp->threads[i], NULL, worker_thread, wp);
if (res != 0) {
perror("pthread_create");
// errno already set to EAGAIN by pthread_create() failure
return NULL;
}
}

if (nthreads > 1) {
wp->threads = (pthread_t *)calloc(wp->nthreads, sizeof(pthread_t));

pthread_mutex_init(&wp->mutex, NULL);
pthread_cond_init(&wp->startcond, NULL);
pthread_cond_init(&wp->endcond, NULL);

for (int i = 0; i < nthreads; i++) {
int res = pthread_create(&wp->threads[i], NULL, worker_thread, wp);
if (res != 0) {
perror("pthread_create");
// errno already set to EAGAIN by pthread_create() failure
return NULL;
}
}

// Wait for the worker threads to be ready
pthread_mutex_lock(&wp->mutex);
while (wp->end_count < wp->nthreads) {
pthread_cond_wait(&wp->endcond, &wp->mutex);
}
pthread_mutex_unlock(&wp->mutex);
// Wait for the worker threads to be ready
pthread_mutex_lock(&wp->mutex);
while (wp->end_count < wp->nthreads) {
pthread_cond_wait(&wp->endcond, &wp->mutex);
}
pthread_mutex_unlock(&wp->mutex);
}

return wp;
return wp;
}

void workerpool_destroy(workerpool_t *wp)
{
if (wp == NULL)
return;

// force all worker threads to exit.
if (wp->nthreads > 1) {
for (int i = 0; i < wp->nthreads; i++)
workerpool_add_task(wp, NULL, NULL);

pthread_mutex_lock(&wp->mutex);
wp->start_predicate = true;
pthread_cond_broadcast(&wp->startcond);
pthread_mutex_unlock(&wp->mutex);

for (int i = 0; i < wp->nthreads; i++)
pthread_join(wp->threads[i], NULL);

pthread_mutex_destroy(&wp->mutex);
pthread_cond_destroy(&wp->startcond);
pthread_cond_destroy(&wp->endcond);
free(wp->threads);
}

zarray_destroy(wp->tasks);
free(wp);
if (wp == NULL)
return;

// force all worker threads to exit.
if (wp->nthreads > 1) {
for (int i = 0; i < wp->nthreads; i++)
workerpool_add_task(wp, NULL, NULL);

pthread_mutex_lock(&wp->mutex);
wp->start_predicate = true;
pthread_cond_broadcast(&wp->startcond);
pthread_mutex_unlock(&wp->mutex);

for (int i = 0; i < wp->nthreads; i++)
pthread_join(wp->threads[i], NULL);

pthread_mutex_destroy(&wp->mutex);
pthread_cond_destroy(&wp->startcond);
pthread_cond_destroy(&wp->endcond);
free(wp->threads);
}

zarray_destroy(wp->tasks);
free(wp);
}

int workerpool_get_nthreads(workerpool_t *wp)
{
return wp->nthreads;
return wp->nthreads;
}

void workerpool_add_task(workerpool_t *wp, void (*f)(void *p), void *p)
{
struct task t;
t.f = f;
t.p = p;

if (wp->nthreads > 1) {
pthread_mutex_lock(&wp->mutex);
zarray_add(wp->tasks, &t);
pthread_mutex_unlock(&wp->mutex);
} else {
zarray_add(wp->tasks, &t);
}
struct task t;
t.f = f;
t.p = p;

if (wp->nthreads > 1) {
pthread_mutex_lock(&wp->mutex);
zarray_add(wp->tasks, &t);
pthread_mutex_unlock(&wp->mutex);
}
else {
zarray_add(wp->tasks, &t);
}
}

void workerpool_run_single(workerpool_t *wp)
{
for (int i = 0; i < zarray_size(wp->tasks); i++) {
struct task *task;
zarray_get_volatile(wp->tasks, i, &task);
task->f(task->p);
}
for (int i = 0; i < zarray_size(wp->tasks); i++) {
struct task *task;
zarray_get_volatile(wp->tasks, i, &task);
task->f(task->p);
}

zarray_clear(wp->tasks);
zarray_clear(wp->tasks);
}

// runs all added tasks, waits for them to complete.
void workerpool_run(workerpool_t *wp)
{
if (wp->nthreads > 1) {
pthread_mutex_lock(&wp->mutex);
wp->end_count = 0;
wp->start_predicate = true;
pthread_cond_broadcast(&wp->startcond);
if (wp->nthreads > 1) {
pthread_mutex_lock(&wp->mutex);
wp->end_count = 0;
wp->start_predicate = true;
pthread_cond_broadcast(&wp->startcond);

while (wp->end_count < wp->nthreads) {
while (wp->end_count < wp->nthreads) {
// printf("caught %d\n", wp->end_count);
pthread_cond_wait(&wp->endcond, &wp->mutex);
}
pthread_cond_wait(&wp->endcond, &wp->mutex);
}

wp->taskspos = 0;
wp->start_predicate = false;
pthread_mutex_unlock(&wp->mutex);
wp->taskspos = 0;
wp->start_predicate = false;
pthread_mutex_unlock(&wp->mutex);

zarray_clear(wp->tasks);
zarray_clear(wp->tasks);

} else {
workerpool_run_single(wp);
}
}
else {
workerpool_run_single(wp);
}
}

int workerpool_get_nprocs()
{
#ifdef _WIN32
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#else
return sysconf (_SC_NPROCESSORS_ONLN);
return sysconf(_SC_NPROCESSORS_ONLN);
#endif
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Platform | Build Status |
-------- | ------------ |
Ubuntu 20.04, 22.04 (amd64)| [![ubuntu dep apt workflow](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-apt.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-apt.yml) [![ubuntu dep src workflow](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-src.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ubuntu-dep-src.yml)
macOS 11 and 12 | [![macos workflow](https://github.com/lagadic/visp/actions/workflows/macos.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/macos.yml)
macOS 13 and 14 | [![macos workflow](https://github.com/lagadic/visp/actions/workflows/macos.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/macos.yml)
iOS on macOS 11.0| [![ios workflow](https://github.com/lagadic/visp/actions/workflows/ios.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/ios.yml)
Windows 10 | [![Build status](https://ci.appveyor.com/api/projects/status/121dscdkryf5dbn0/branch/master?svg=true)](https://ci.appveyor.com/project/fspindle/visp/branch/master)
Other arch Ubuntu 22.04 (aarch64, s390x)| [![other arch workflow](https://github.com/lagadic/visp/actions/workflows/other-arch.yml/badge.svg)](https://github.com/lagadic/visp/actions/workflows/other-arch.yml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis
// Load config for tracker
std::string tracker_config_file = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml");

#if defined(VISP_HAVE_PUGYXML)
#if defined(VISP_HAVE_PUGIXML)
tracker.loadConfigFile(tracker_config_file);
tracker.getCameraParameters(cam);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis
// Load config for tracker
std::string tracker_config_file = vpIoTools::createFilePath(env_ipath, "mbt/cube.xml");

#if defined(VISP_HAVE_PUGYXML)
#if defined(VISP_HAVE_PUGIXML)
tracker.loadConfigFile(tracker_config_file);
tracker.getCameraParameters(cam);
#else
Expand Down
Loading

0 comments on commit 133df82

Please sign in to comment.