Skip to content

Commit

Permalink
Merge pull request #18148 from jenshannoschwalm/dt_pthreads_52
Browse files Browse the repository at this point in the history
pthreads 5.2 update
  • Loading branch information
TurboGit authored Jan 21, 2025
2 parents 5fbe1da + 578487f commit e30bfc3
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/common/camera_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void dt_camctl_camera_stop_live_view(const dt_camctl_t *c)
}
dt_print(DT_DEBUG_CAMCTL, "[camera_control] Stopping live view");
cam->is_live_viewing = FALSE;
pthread_join(cam->live_view_thread, NULL);
dt_pthread_join(cam->live_view_thread);
// tell camera to get back to normal state (close mirror)
dt_camctl_camera_set_property_int(camctl, NULL, "eosviewfinder", 0);
dt_camctl_camera_set_property_int(camctl, NULL, "viewfinder", 0);
Expand Down
47 changes: 29 additions & 18 deletions src/common/dtpthread.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of darktable,
Copyright (C) 2016-2023 darktable developers.
Copyright (C) 2016-2024 darktable developers.
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,48 +31,61 @@
#include "win/dtwin.h"
#endif // _WIN32

#include "common/dtpthread.h"

int dt_pthread_create(pthread_t *thread, void *(*start_routine)(void *), void *arg)
{
int ret = 0;

pthread_attr_t attr;

ret = pthread_attr_init(&attr);
if(ret != 0)
{
fprintf(stderr, "[dt_pthread_create] error: pthread_attr_init() returned %i\n", ret);
return ret;
printf("[dt_pthread_create] error: pthread_attr_init() returned %s\n", _pthread_ret_mess(ret));
fflush(stdout);
}
assert(ret == 0);

size_t stacksize;

ret = pthread_attr_getstacksize(&attr, &stacksize);

if(ret != 0)
{
fprintf(stderr, "[dt_pthread_create] error: pthread_attr_getstacksize() returned %i\n", ret);
}

if(ret != 0 || stacksize < WANTED_THREADS_STACK_SIZE)
{
// looks like we need to bump/set it...
ret = pthread_attr_setstacksize(&attr, WANTED_THREADS_STACK_SIZE);
if(ret != 0)
{
fprintf(stderr, "[dt_pthread_create] error: pthread_attr_setstacksize() returned %i\n", ret);
printf("[dt_pthread_create] error: pthread_attr_setstacksize() returned %s\n", _pthread_ret_mess(ret));
fflush(stdout);
}
}
assert(ret == 0);

if(ret == 0)
ret = pthread_create(thread, &attr, start_routine, arg);

ret = pthread_create(thread, &attr, start_routine, arg);
if(ret != 0)
{
fprintf(stderr, "[dt_pthread_create] error: pthread_create() returned %i\n", ret);
printf("[dt_pthread_create] error: pthread_create() returned %s\n", _pthread_ret_mess(ret));
fflush(stdout);
}

pthread_attr_destroy(&attr);
assert(ret == 0);
return ret;
}

int dt_pthread_join(pthread_t thread)
{
#if defined(MUTEX_REPORTING) && ( defined(__linux__) || defined(__APPLE__) )
char name[256] = { "???" };
pthread_getname_np(thread, name, sizeof(name));
const int ret = pthread_join(thread, NULL);
printf("[dt_pthread_join] '%s' returned %s\n",
name, _pthread_ret_mess(ret));
fflush(stdout);
#else
const int ret = pthread_join(thread, NULL);
#endif

assert(ret == 0);
return ret;
}

Expand All @@ -94,8 +107,6 @@ void dt_pthread_setname(const char *name)
dtwin_set_thread_name((DWORD)-1, name);
#endif
}


// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Expand Down
Loading

0 comments on commit e30bfc3

Please sign in to comment.