diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/fsmonitor/fsm-darwin-gcc.h | 4 | ||||
-rw-r--r-- | compat/fsmonitor/fsm-listen-darwin.c | 35 | ||||
-rw-r--r-- | compat/mingw.c | 12 | ||||
-rw-r--r-- | compat/regcomp_enhanced.c | 9 | ||||
-rw-r--r-- | compat/win32/pthread.c | 25 | ||||
-rw-r--r-- | compat/win32/pthread.h | 2 |
6 files changed, 53 insertions, 34 deletions
diff --git a/compat/fsmonitor/fsm-darwin-gcc.h b/compat/fsmonitor/fsm-darwin-gcc.h index 1c75c3d48e..3496e29b3a 100644 --- a/compat/fsmonitor/fsm-darwin-gcc.h +++ b/compat/fsmonitor/fsm-darwin-gcc.h @@ -80,9 +80,7 @@ void CFRunLoopRun(void); void CFRunLoopStop(CFRunLoopRef run_loop); CFRunLoopRef CFRunLoopGetCurrent(void); extern CFStringRef kCFRunLoopDefaultMode; -void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream, - CFRunLoopRef run_loop, - CFStringRef run_loop_mode); +void FSEventStreamSetDispatchQueue(FSEventStreamRef stream, dispatch_queue_t q); unsigned char FSEventStreamStart(FSEventStreamRef stream); void FSEventStreamStop(FSEventStreamRef stream); void FSEventStreamInvalidate(FSEventStreamRef stream); diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index cc9af1e3cb..97a55a6f0a 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -1,4 +1,5 @@ #ifndef __clang__ +#include <dispatch/dispatch.h> #include "fsm-darwin-gcc.h" #else #include <CoreFoundation/CoreFoundation.h> @@ -38,7 +39,9 @@ struct fsm_listen_data FSEventStreamRef stream; - CFRunLoopRef rl; + dispatch_queue_t dq; + pthread_cond_t dq_finished; + pthread_mutex_t dq_lock; enum shutdown_style { SHUTDOWN_EVENT = 0, @@ -379,8 +382,11 @@ force_shutdown: fsmonitor_batch__free_list(batch); string_list_clear(&cookie_list, 0); + pthread_mutex_lock(&data->dq_lock); data->shutdown_style = FORCE_SHUTDOWN; - CFRunLoopStop(data->rl); + pthread_cond_broadcast(&data->dq_finished); + pthread_mutex_unlock(&data->dq_lock); + strbuf_release(&tmp); return; } @@ -441,10 +447,6 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state) if (!data->stream) goto failed; - /* - * `data->rl` needs to be set inside the listener thread. - */ - return 0; failed: @@ -471,6 +473,11 @@ void fsm_listen__dtor(struct fsmonitor_daemon_state *state) FSEventStreamRelease(data->stream); } + if (data->dq) + dispatch_release(data->dq); + pthread_cond_destroy(&data->dq_finished); + pthread_mutex_destroy(&data->dq_lock); + FREE_AND_NULL(state->listen_data); } @@ -479,9 +486,11 @@ void fsm_listen__stop_async(struct fsmonitor_daemon_state *state) struct fsm_listen_data *data; data = state->listen_data; - data->shutdown_style = SHUTDOWN_EVENT; - CFRunLoopStop(data->rl); + pthread_mutex_lock(&data->dq_lock); + data->shutdown_style = SHUTDOWN_EVENT; + pthread_cond_broadcast(&data->dq_finished); + pthread_mutex_unlock(&data->dq_lock); } void fsm_listen__loop(struct fsmonitor_daemon_state *state) @@ -490,9 +499,11 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state) data = state->listen_data; - data->rl = CFRunLoopGetCurrent(); + pthread_mutex_init(&data->dq_lock, NULL); + pthread_cond_init(&data->dq_finished, NULL); + data->dq = dispatch_queue_create("FSMonitor", NULL); - FSEventStreamScheduleWithRunLoop(data->stream, data->rl, kCFRunLoopDefaultMode); + FSEventStreamSetDispatchQueue(data->stream, data->dq); data->stream_scheduled = 1; if (!FSEventStreamStart(data->stream)) { @@ -501,7 +512,9 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state) } data->stream_started = 1; - CFRunLoopRun(); + pthread_mutex_lock(&data->dq_lock); + pthread_cond_wait(&data->dq_finished, &data->dq_lock); + pthread_mutex_unlock(&data->dq_lock); switch (data->shutdown_style) { case FORCE_ERROR_STOP: diff --git a/compat/mingw.c b/compat/mingw.c index d614f156df..e433740381 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1396,8 +1396,7 @@ static wchar_t *make_environment_block(char **deltaenv) p += s; } - ALLOC_ARRAY(result, size); - COPY_ARRAY(result, wenv, size); + DUP_ARRAY(result, wenv, size); FreeEnvironmentStringsW(wenv); return result; } @@ -1839,16 +1838,13 @@ static int try_shell_exec(const char *cmd, char *const *argv) if (prog) { int exec_id; int argc = 0; -#ifndef _MSC_VER - const -#endif char **argv2; while (argv[argc]) argc++; ALLOC_ARRAY(argv2, argc + 1); argv2[0] = (char *)cmd; /* full path to the script file */ COPY_ARRAY(&argv2[1], &argv[1], argc); - exec_id = trace2_exec(prog, argv2); - pid = mingw_spawnv(prog, argv2, 1); + exec_id = trace2_exec(prog, (const char **)argv2); + pid = mingw_spawnv(prog, (const char **)argv2, 1); if (pid >= 0) { int status; if (waitpid(pid, &status, 0) < 0) @@ -2752,7 +2748,7 @@ int is_path_owned_by_current_sid(const char *path, struct strbuf *report) /* * On FAT32 volumes, ownership is not actually recorded. */ - strbuf_addf(report, "'%s' is on a file system that does" + strbuf_addf(report, "'%s' is on a file system that does " "not record ownership\n", path); } else if (report) { LPSTR str1, str2, to_free1 = NULL, to_free2 = NULL; diff --git a/compat/regcomp_enhanced.c b/compat/regcomp_enhanced.c new file mode 100644 index 0000000000..84193ce53b --- /dev/null +++ b/compat/regcomp_enhanced.c @@ -0,0 +1,9 @@ +#include "../git-compat-util.h" +#undef regcomp + +int git_regcomp(regex_t *preg, const char *pattern, int cflags) +{ + if (!(cflags & REG_EXTENDED)) + cflags |= REG_ENHANCED; + return regcomp(preg, pattern, cflags); +} diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c index 2e7eead42c..85f8f7920c 100644 --- a/compat/win32/pthread.c +++ b/compat/win32/pthread.c @@ -22,12 +22,12 @@ static unsigned __stdcall win32_start_routine(void *arg) } int pthread_create(pthread_t *thread, const void *unused, - void *(*start_routine)(void*), void *arg) + void *(*start_routine)(void *), void *arg) { thread->arg = arg; thread->start_routine = start_routine; - thread->handle = (HANDLE) - _beginthreadex(NULL, 0, win32_start_routine, thread, 0, NULL); + thread->handle = (HANDLE)_beginthreadex(NULL, 0, win32_start_routine, + thread, 0, NULL); if (!thread->handle) return errno; @@ -39,14 +39,17 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr) { DWORD result = WaitForSingleObject(thread->handle, INFINITE); switch (result) { - case WAIT_OBJECT_0: - if (value_ptr) - *value_ptr = thread->arg; - return 0; - case WAIT_ABANDONED: - return EINVAL; - default: - return err_win_to_posix(GetLastError()); + case WAIT_OBJECT_0: + if (value_ptr) + *value_ptr = thread->arg; + CloseHandle(thread->handle); + return 0; + case WAIT_ABANDONED: + CloseHandle(thread->handle); + return EINVAL; + default: + /* the wait failed, so do not detach */ + return err_win_to_posix(GetLastError()); } } diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h index 737983d00b..cc3221cb2c 100644 --- a/compat/win32/pthread.h +++ b/compat/win32/pthread.h @@ -66,7 +66,7 @@ pthread_t pthread_self(void); static inline void NORETURN pthread_exit(void *ret) { - ExitThread((DWORD)(intptr_t)ret); + _endthreadex((unsigned)(uintptr_t)ret); } typedef DWORD pthread_key_t; |