Changeset 272 for trunk/src


Ignore:
Timestamp:
Oct 31, 2009, 2:00:20 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

3rdparty: os2/xsystray: Use shared memory pool instead of TLS for structures sent to the system tray server by the client-side API. The memory pool is big enough to hold ~64 simultaneous requests to the server (e.g. 64 parallel threads). This also fixes a potential bug when not all threads could re-give their per-thread memory blocks to the server process after it is stopped and restarted.

Location:
trunk/src/3rdparty/os2/xsystray
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/3rdparty/os2/xsystray/xsystray.h

    r256 r272  
    3939} SYSTRAYCMD;
    4040
    41 // NOTE: the idea is to fit SYSTRAYCTLDATA into a page (4K) since this is the
    42 // smallest piece DosAllocSharedMem() allocates anyway.
    4341typedef struct
    4442{
     
    6967        {
    7068            ULONG   ulId;
    71             CHAR    szText[4000]; // occupy as much of 4K page as we can
     69            CHAR    szText[
    7270        } tooltip;
    7371
  • trunk/src/3rdparty/os2/xsystray/xsystray_api.c

    r270 r272  
    1717#define INCL_DOSPROCESS
    1818#define INCL_WINWINDOWMGR
     19
    1920#define INCL_WINATOM
    2021#define INCL_WINPOINTERS
     
    2627#include <string.h>
    2728#include <sys/builtin.h>        // atomics
    28 #include <InnotekLIBC/thread.h> // TLS
    2929
    3030static HWND G_hwndSysTray = NULLHANDLE;
    31 static int G_itlsSysTrayCtlData = -1;
    32 
    33 static HWND FindSysTrayWindow()
     31            // window handle of the system tray server
     32
     33static PVOID G_pvMemoryPool = NULL;
     34             // memory pool for SYSTRAYCTLDATA structs used by WM_XST_CONTROL
     35             // messages. Note that once allocated, this memory is never freed:
     36             // it is intentional since the memory is assumed to be always in
     37             // need and that the system will free it when the application
     38             // terminates
     39
     40#define MEMORYPOOL_SIZE 65536
     41        // taking SYSTRAYCTLDATA size into account, this is enough for at least
     42        // 64 threads sending WM_XST_CONTROL simultaneously, which sounds sane
     43
     44// @todo to be on the safe side with casting in __atomic_cmpxchg32() we need
     45// compile-time assertions like this:
     46// AssertCompile(sizeof(uint32_t) == sizeof(HWND));
     47// AssertCompile(sizeof(uint32_t) == sizeof(PVOID));
     48
     49static HWND FindSysTrayServerWindow()
    3450{
    3551    char buf[sizeof(WNDCLASS_WIDGET_XSYSTRAY_SERVER) + 1];
     
    6278        {
    6379            bTriedFind = TRUE;
    64             HWND hwnd = FindSysTrayWindow();
     80            HWND hwnd = FindSysTrayWindow();
    6581            __atomic_cmpxchg32((uint32_t *)&G_hwndSysTray, hwnd, NULLHANDLE);
    6682            if (G_hwndSysTray == NULLHANDLE)
     
    7288            arc = ERROR_INVALID_HANDLE;
    7389            if (WinQueryWindowProcess(G_hwndSysTray, &pid, &tid))
    74                 arc = DosGiveSharedMem(__libc_TLSGet(G_itlsSysTrayCtlData),
     90                arc = DosGiveSharedMem(,
    7591                                       pid, PAG_READ | PAG_WRITE);
    7692            if (arc != NO_ERROR)