1. 11 Oct, 2020 4 commits
  2. 29 Nov, 2019 1 commit
    • global: convert to fiber-local storage to fix exit races · 5c6180b5
      On Windows platforms, we automatically clean up the thread-local storage
      upon detaching a thread via `DllMain()`. The thing is that this happens
      for every thread of applications that link against the libgit2 DLL, even
      those that don't have anything to do with libgit2 itself. As a result,
      we cannot assume that these unsuspecting threads make use of our
      `git_libgit2_init()` and `git_libgit2_shutdow()` reference counting,
      which may lead to racy situations:
      
          Thread 1                    Thread 2
      
          git_libgit2_shutdown()
                                      DllMain(DETACH_THREAD)
                                      git__free_tls_data()
          git_atomic_dec() == 0
          git__free_tls_data()
          TlsFree(_tls_index)
                                      TlsGetValue(_tls_index)
      
      Due to the second thread never having executed `git_libgit2_init()`, the
      first thread will clean up TLS data and as a result also free the
      `_tls_index` variable. When detaching the second thread, we
      unconditionally access the now-free'd `_tls_index` variable, which is
      obviously not going to work out well.
      
      Fix the issue by converting the code to use fiber-local storage instead
      of thread-local storage. While FLS will behave the exact same as TLS if
      no fibers are in use, it does allow us to specify a destructor similar
      to the one that is accepted by pthread_key_create(3P). Like this, we do
      not have to manually free indices anymore, but will let the FLS handle
      calling the destructor. This allows us to get rid of `DllMain()`
      completely, as we only used it to keep track of when threads were
      exiting and results in an overall simplification of TLS cleanup.
      Patrick Steinhardt committed
  3. 23 Oct, 2017 1 commit
  4. 03 Jul, 2017 1 commit
    • Make sure to always include "common.h" first · 0c7f49dd
      Next to including several files, our "common.h" header also declares
      various macros which are then used throughout the project. As such, we
      have to make sure to always include this file first in all
      implementation files. Otherwise, we might encounter problems or even
      silent behavioural differences due to macros or defines not being
      defined as they should be. So in fact, our header and implementation
      files should make sure to always include "common.h" first.
      
      This commit does so by establishing a common include pattern. Header
      files inside of "src" will now always include "common.h" as its first
      other file, separated by a newline from all the other includes to make
      it stand out as special. There are two cases for the implementation
      files. If they do have a matching header file, they will always include
      this one first, leading to "common.h" being transitively included as
      first file. If they do not have a matching header file, they instead
      include "common.h" as first file themselves.
      
      This fixes the outlined problems and will become our standard practice
      for header and source files inside of the "src/" from now on.
      Patrick Steinhardt committed
  5. 18 Nov, 2016 1 commit
    • threads: introduce `git_thread_exit` · 82f15896
      Introduce `git_thread_exit`, which will allow threads to terminate at an
      arbitrary time, returning a `void *`.  On Windows, this means that we
      need to store the current `git_thread` in TLS, so that we can set its
      `return` value when terminating.
      
      We cannot simply use `ExitThread`, since Win32 returns `DWORD`s from
      threads; we return `void *`.
      Edward Thomson committed
  6. 14 Mar, 2016 1 commit
  7. 12 Nov, 2015 1 commit
  8. 28 Jul, 2015 1 commit
  9. 23 Apr, 2015 1 commit
  10. 18 Apr, 2015 1 commit
  11. 17 Apr, 2015 1 commit
  12. 16 Sep, 2014 1 commit
  13. 18 Aug, 2014 1 commit
  14. 12 Jun, 2014 2 commits
  15. 11 Jun, 2014 1 commit
  16. 17 Sep, 2013 1 commit
    • Add simple global shutdown hooks · a3aa5f4d
      Increasingly there are a number of components that want to do some
      cleanup at global shutdown time (at least if there are not going
      to be memory leaks).  This creates a very simple system of shutdown
      hooks that will be invoked by git_threads_shutdown.  Right now, the
      maximum number of hooks is hardcoded, but since adding a hook is
      not a public API, it should be fine and I thought it was better to
      start off with really simple code.
      Russell Belfer committed
  17. 22 Apr, 2013 1 commit
  18. 08 Jan, 2013 1 commit
  19. 13 Nov, 2012 3 commits
  20. 20 Aug, 2012 1 commit
    • Make the memory-window conrol structures global · 8cef828d
      Up to now, the idea was that the user would do all the operations for
      one repository in the same thread. Thus we could have the
      memory-mapped window information thread-local and avoid any locking.
      
      This is not practical in a few environments, such as Apple's GCD which
      allocates threads arbitrarily or the .NET CLR, where the OS-level
      thread can change at any moment.
      
      Make the control structure global and protect it with a mutex so we
      don't depend on the thread currently executing the code.
      Carlos Martín Nieto committed
  21. 17 Jul, 2012 1 commit
  22. 05 Mar, 2012 1 commit
  23. 13 Feb, 2012 1 commit
  24. 16 Nov, 2011 1 commit