All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Sixt <j.sixt@viscovery.net>
To: "Andrzej K. Haczewski" <ahaczewski@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/1] MSVC: port pthread code to native Windows threads
Date: Wed, 04 Nov 2009 09:15:21 +0100	[thread overview]
Message-ID: <4AF13819.7050306@viscovery.net> (raw)
In-Reply-To: <1257283802-29726-2-git-send-email-ahaczewski@gmail.com>

Andrzej K. Haczewski schrieb:
> ---

You should sign-off your patches.

>  #ifdef THREADED_DELTA_SEARCH
> -#include "thread-utils.h"
> -#include <pthread.h>
> +# include "thread-utils.h"
> +# ifndef _WIN32
> +#  include <pthread.h>
> +# else
> +#  include <winthread.h>
> +# endif
>  #endif

Can't you just use the pthread package that is included in msysgit?

> +#ifndef _WIN32
>  static void *threaded_find_deltas(void *arg)
> +#else
> +static DWORD WINAPI threaded_find_deltas(LPVOID arg)
> +#endif
> ...
> +#ifndef _WIN32
>  	return NULL;
> +#else
> +	return 0;
> +#endif
> etc ...

You have far too many #ifdef in the generic code. There must be a better
way to hide the implementation details of this emulation.

> +#ifdef _WIN32
> +	/*
> +	 * Windows require initialization of mutex (CRITICAL_SECTION)
> +	 * and conditional variable.
> +	 */
> +	pthread_mutex_init(&read_mutex);
> +	pthread_mutex_init(&cache_mutex);
> +	pthread_mutex_init(&progress_mutex);
> +	win32_cond_init(&progress_cond);
> +#endif

*If* we are going to use this minimal pthreads implementation, then I
think it will be OK to call pthread_*_init even on non-Windows.

> +static __inline int win32_cond_init(win32_cond_t *cond)
> +{
> +	cond->waiters = 0;
> +
> +	InitializeCriticalSection(&cond->waiters_lock);
> +
> +	cond->sema = CreateSemaphore(NULL, 0, LONG_MAX, NULL);

Wouldn't an Event object be lighter-weight? (I'm only guessing.)

> +	if (NULL == cond->sema)
> +		return -1;
> +	return 0;
> +}
> +
> +static __inline int win32_cond_destroy(win32_cond_t *cond)
> +{
> +	CloseHandle(cond->sema);
> +	cond->sema = NULL;
> +
> +	DeleteCriticalSection(&cond->waiters_lock);
> +
> +	return 0;
> +}
> +
> +static __inline int win32_cond_wait(win32_cond_t *cond, CRITICAL_SECTION *mutex)

And the reason that this is not pthread_cond_wait, is...?

> +{
> +	DWORD result;
> +	int ret = 0;
> +
> +	/* we're waiting... */
> +	EnterCriticalSection(&cond->waiters_lock);
> +	++cond->waiters;
> +	LeaveCriticalSection(&cond->waiters_lock);
> +
> +	/* unlock external mutex and wait for signal */
> +	LeaveCriticalSection(mutex);
> +	result = WaitForSingleObject(cond->sema, INFINITE);

Releasing the mutex and entering the wait state as well as leaving the
wait state and reacquiring the mutex should be atomic. Neither are in this
implementation. You are not mentioning why you are implementing things
like this and why this would be acceptable.

> +
> +	if (0 != result)
> +		ret = -1;
> +
> +	/* one waiter less */
> +	EnterCriticalSection(&cond->waiters_lock);
> +	--cond->waiters;
> +	LeaveCriticalSection(&cond->waiters_lock);
> +
> +	/* lock external mutex again */
> +	EnterCriticalSection(mutex);

> +/* almost copy-paste code of mingw.c */
> +static int err_win_to_posix()
> +{

There must be a better way than to just copy & paste this huge piece of code.

-- Hannes

  parent reply	other threads:[~2009-11-04  8:15 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-03 21:30 [PATCH 0/1] Port of pthreads to Windows API threads Andrzej K. Haczewski
2009-11-03 21:30 ` [PATCH 1/1] MSVC: port pthread code to native Windows threads Andrzej K. Haczewski
2009-11-03 23:38   ` Johannes Schindelin
2009-11-04  2:34     ` Joshua Jensen
2009-11-04  7:44       ` Andrzej K. Haczewski
2009-11-04  8:24         ` Johannes Sixt
2009-11-04 11:02       ` Johannes Schindelin
2009-11-04  8:17     ` Andrzej K. Haczewski
2009-11-04  8:15   ` Johannes Sixt [this message]
2009-11-04  8:48     ` Michael Wookey
2009-11-04 10:53     ` Andrzej K. Haczewski
2009-11-04 10:37 ` [PATCH] " Andrzej K. Haczewski
2009-11-04 10:50   ` Erik Faye-Lund
2009-11-04 10:56     ` Andrzej K. Haczewski
2009-11-04 11:14     ` Paolo Bonzini
2009-11-04 11:23   ` Paolo Bonzini
2009-11-04 12:39   ` Johannes Sixt
2009-11-04 13:47     ` Andrzej K. Haczewski
2009-11-04 14:34       ` Johannes Sixt
2009-11-04 14:50         ` Andrzej K. Haczewski
2009-11-04 20:43           ` Daniel Barkalow
2009-11-04 21:17             ` Nicolas Pitre
2009-11-04 22:22               ` Daniel Barkalow
2009-11-05  0:27                 ` Nicolas Pitre
2009-11-05 13:48       ` Dmitry Potapov
2009-11-04 14:14     ` Andrzej K. Haczewski
2009-11-04 14:19       ` Erik Faye-Lund
2009-11-04 14:04   ` Johannes Schindelin
2009-11-04 15:55   ` [PATCH] MSVC: Windows-native implementation for subset of Pthreads API Andrzej K. Haczewski
2009-11-04 18:10     ` Nicolas Pitre
2009-11-04 21:16       ` Andrzej K. Haczewski
2009-11-04 21:32         ` [PATCH] pack-objects: move thread autodetection closer to relevant code Nicolas Pitre
2009-11-06  7:20           ` Junio C Hamano
2009-11-04 21:41         ` [PATCH] MSVC: Windows-native implementation for subset of Pthreads API Erik Faye-Lund
2009-11-04 22:50           ` Andrzej K. Haczewski
2009-11-05  2:47             ` Nicolas Pitre
2009-11-05  9:00               ` Andrzej K. Haczewski
2009-11-05  9:41                 ` Erik Faye-Lund
2009-11-05 10:18                 ` Andrzej K. Haczewski
2009-11-05 12:27                   ` Johannes Sixt
2009-11-05 12:53                     ` Andrzej K. Haczewski
2009-11-05 19:25                 ` Nicolas Pitre
2009-11-05 20:38                   ` Andrzej K. Haczewski
2009-11-05 22:15                     ` Nicolas Pitre
2009-11-04 21:52         ` Nicolas Pitre
2009-11-04 23:47         ` Andrzej K. Haczewski
2009-11-04 23:57           ` Andrzej K. Haczewski
2009-11-05  0:22             ` Nicolas Pitre
2009-11-05  8:51               ` Andrzej K. Haczewski
2009-11-05 19:22                 ` Nicolas Pitre
2009-11-05  2:10             ` Nicolas Pitre
2009-11-05  8:45               ` Andrzej K. Haczewski
2009-11-05 19:17                 ` Nicolas Pitre
2009-11-05  7:33             ` Johannes Sixt
2009-11-04 23:58       ` Junio C Hamano
2009-11-05 16:45 ` Andrzej K. Haczewski
2009-11-05 17:31   ` Johannes Sixt
2009-11-05 19:39   ` Nicolas Pitre
2009-11-05 20:09     ` Andrzej K. Haczewski
2009-11-05 20:36       ` Nicolas Pitre
2009-11-06  8:10 ` Andrzej K. Haczewski
2009-11-06  8:25   ` Johannes Sixt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AF13819.7050306@viscovery.net \
    --to=j.sixt@viscovery.net \
    --cc=ahaczewski@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.