Ignore:
Timestamp:
Jul 28, 2014, 4:13:38 AM (7 years ago)
Author:
jordan
Message:

(trunk, libt) #4160 - the slow slog to catch trunk up to mike.dld's 4160 diff continues. This step applies 4160-03b-file.patch, which replaces native file operations with the tr_sys_file_*() portability wrappers added in r14321.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r14320 r14327  
    566566  return s;
    567567}
    568 
    569 
    570 #ifdef _WIN32
    571 
    572 /* The following mmap functions are by Joerg Walter, and were taken from
    573  * his paper at: http://www.genesys-e.de/jwalter/mix4win.htm */
    574 
    575 #if defined (_MSC_VER)
    576 __declspec (align (4)) static LONG volatile g_sl;
    577 #else
    578 static LONG volatile g_sl __attribute__((aligned (4)));
    579 #endif
    580 
    581 /* Wait for spin lock */
    582 static int
    583 slwait (LONG volatile *sl)
    584 {
    585   while (InterlockedCompareExchange (sl, 1, 0) != 0)
    586     Sleep (0);
    587 
    588   return 0;
    589 }
    590 
    591 /* Release spin lock */
    592 static int
    593 slrelease (LONG volatile *sl)
    594 {
    595   InterlockedExchange (sl, 0);
    596   return 0;
    597 }
    598 
    599 /* getpagesize for windows */
    600 static long
    601 getpagesize (void)
    602 {
    603   static long g_pagesize = 0;
    604 
    605   if (!g_pagesize)
    606     {
    607       SYSTEM_INFO system_info;
    608       GetSystemInfo (&system_info);
    609       g_pagesize = system_info.dwPageSize;
    610     }
    611 
    612   return g_pagesize;
    613 }
    614 
    615 static long
    616 getregionsize (void)
    617 {
    618   static long g_regionsize = 0;
    619 
    620   if (!g_regionsize)
    621     {
    622       SYSTEM_INFO system_info;
    623       GetSystemInfo (&system_info);
    624       g_regionsize = system_info.dwAllocationGranularity;
    625     }
    626 
    627   return g_regionsize;
    628 }
    629 
    630 void *
    631 mmap (void *ptr, long  size, long  prot, long  type, long  handle, long  arg)
    632 {
    633   static long g_pagesize;
    634   static long g_regionsize;
    635 
    636   /* Wait for spin lock */
    637   slwait (&g_sl);
    638 
    639   /* First time initialization */
    640   if (!g_pagesize)
    641     g_pagesize = getpagesize ();
    642   if (!g_regionsize)
    643     g_regionsize = getregionsize ();
    644 
    645   /* Allocate this */
    646   ptr = VirtualAlloc (ptr, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
    647   if (!ptr)
    648     {
    649       ptr = (void *) -1;
    650       goto mmap_exit;
    651     }
    652 
    653 mmap_exit:
    654   /* Release spin lock */
    655   slrelease (&g_sl);
    656   return ptr;
    657 }
    658 
    659 long
    660 munmap (void *ptr, long size)
    661 {
    662   static long g_pagesize;
    663   static long g_regionsize;
    664   int rc = -1;
    665 
    666   /* Wait for spin lock */
    667   slwait (&g_sl);
    668 
    669   /* First time initialization */
    670   if (!g_pagesize)
    671     g_pagesize = getpagesize ();
    672   if (!g_regionsize)
    673     g_regionsize = getregionsize ();
    674 
    675   /* Free this */
    676   if (!VirtualFree (ptr, 0, MEM_RELEASE))
    677     goto munmap_exit;
    678 
    679   rc = 0;
    680 
    681 munmap_exit:
    682   /* Release spin lock */
    683   slrelease (&g_sl);
    684   return rc;
    685 }
    686 
    687 #endif
Note: See TracChangeset for help on using the changeset viewer.