Changeset 7318 for trunk/src


Ignore:
Timestamp:
Nov 10, 2001, 1:47:48 PM (24 years ago)
Author:
sandervl
Message:

Implemented Get/SetProcessAffinityMask & SetThreadAffinityMask

Location:
trunk/src/kernel32
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/initkernel32.cpp

    r6646 r7318  
    1 /* $Id: initkernel32.cpp,v 1.7 2001-09-05 12:57:58 bird Exp $
     1/* $Id: initkernel32.cpp,v 1.8 2001-11-10 12:47:46 sandervl Exp $
    22 *
    33 * KERNEL32 DLL entry point
     
    3939#include "initterm.h"
    4040#include <win32type.h>
     41#include <win32api.h>
    4142#include <odinlx.h>
    4243#include "oslibmisc.h"
     
    179180            //keys that affect windows version)
    180181            InitDynamicRegistry();
     182
     183            //Set the process affinity mask to the system affinity mask
     184            DWORD dwProcessAffinityMask, dwSystemAffinityMask;
     185            GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask);
     186            SetProcessAffinityMask(GetCurrentProcess(), dwSystemAffinityMask);
    181187            break;
    182188        }
  • trunk/src/kernel32/oslibdos.cpp

    r7286 r7318  
    1 /* $Id: oslibdos.cpp,v 1.83 2001-11-05 15:00:36 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.84 2001-11-10 12:47:46 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    28152815//******************************************************************************
    28162816//******************************************************************************
     2817BOOL OSLibDosSetThreadAffinity(DWORD dwThreadAffinityMask)
     2818{
     2819  static PROC_DosSetThreadAffinity pfnDosSetThreadAffinity = NULL;
     2820  static BOOL fInit = FALSE;
     2821  MPAFFINITY mask;
     2822
     2823    if(fInit == FALSE && pfnDosSetThreadAffinity == NULL) {
     2824        HMODULE hDoscalls;
     2825        if(DosQueryModuleHandle("DOSCALLS", &hDoscalls) == NO_ERROR) {
     2826            DosQueryProcAddr(hDoscalls, 564, NULL, (PFN *)&pfnDosSetThreadAffinity);
     2827        }
     2828        fInit = TRUE;
     2829    }
     2830    if(fInit && pfnDosSetThreadAffinity == NULL) {
     2831        SetLastError(ERROR_SUCCESS_W);
     2832        return TRUE;
     2833    }
     2834    APIRET rc;
     2835    USHORT sel = RestoreOS2FS();
     2836
     2837    mask.mask[0] = dwThreadAffinityMask;
     2838    mask.mask[1] = 0; //TODO: this might not be a good idea, but then again, not many people have > 32 cpus
     2839
     2840    rc = pfnDosSetThreadAffinity(&mask);
     2841    SetFS(sel);
     2842
     2843    SetLastError(error2WinError(rc,ERROR_INVALID_PARAMETER));
     2844    return (rc == NO_ERROR);
     2845}
     2846//******************************************************************************
     2847//******************************************************************************
     2848BOOL OSLibDosQueryAffinity(DWORD fMaskType, DWORD *pdwThreadAffinityMask)
     2849{
     2850  static PROC_DosQueryThreadAffinity pfnDosQueryThreadAffinity = NULL;
     2851  static BOOL fInit = FALSE;
     2852  MPAFFINITY mask;
     2853
     2854    if(fInit == FALSE && pfnDosQueryThreadAffinity == NULL) {
     2855        HMODULE hDoscalls;
     2856        if(DosQueryModuleHandle("DOSCALLS", &hDoscalls) == NO_ERROR) {
     2857            DosQueryProcAddr(hDoscalls, 563, NULL, (PFN *)&pfnDosQueryThreadAffinity);
     2858        }
     2859        fInit = TRUE;
     2860    }
     2861    if(fInit && pfnDosQueryThreadAffinity == NULL) {
     2862        *pdwThreadAffinityMask = 1;
     2863        SetLastError(ERROR_SUCCESS_W);
     2864        return TRUE;
     2865    }
     2866
     2867    ULONG scope = (fMaskType == MASK_SYSTEM) ? AFNTY_SYSTEM : AFNTY_THREAD;
     2868
     2869    APIRET rc;
     2870    USHORT sel = RestoreOS2FS();
     2871
     2872    rc = pfnDosQueryThreadAffinity(scope, &mask);
     2873    SetFS(sel);
     2874
     2875    if(rc == NO_ERROR) {
     2876        *pdwThreadAffinityMask = mask.mask[0];
     2877    }
     2878    SetLastError(error2WinError(rc,ERROR_INVALID_PARAMETER));
     2879    return (rc == NO_ERROR);
     2880}
     2881//******************************************************************************
     2882//******************************************************************************
  • trunk/src/kernel32/oslibdos.h

    r7275 r7318  
    1 /* $Id: oslibdos.h,v 1.37 2001-10-30 18:46:46 sandervl Exp $ */
     1/* $Id: oslibdos.h,v 1.38 2001-11-10 12:47:47 sandervl Exp $ */
    22
    33/*
     
    320320                                PEAOP2 peaop2);
    321321
    322 #endif
     322
     323   typedef struct _MPAFFINITY { /* afnty */
     324      ULONG          mask[2]; /* CPUs 0 thru 31 in [0], CPUs 32 thru 63 in [1] */
     325   } MPAFFINITY;
     326   typedef MPAFFINITY *PMPAFFINITY;
     327
     328   typedef APIRET (* APIENTRY PROC_DosQueryThreadAffinity)(ULONG scope,
     329                                                           PMPAFFINITY pAffinity);
     330
     331   /* scope values for QueryThreadAffinity */
     332
     333   #define AFNTY_THREAD       0
     334   #define AFNTY_SYSTEM       1
     335
     336   typedef APIRET (* APIENTRY PROC_DosSetThreadAffinity)(PMPAFFINITY pAffinity);
    323337
    324338#endif
     
    333347BOOL  OSLibDosBeep(DWORD ulFreq, DWORD ulDuration);
    334348ULONG OSLibDosGetProcAddress(HMODULE hModule, LPCSTR lpszProc);
     349
     350BOOL  OSLibDosSetThreadAffinity(DWORD dwThreadAffinityMask);
     351
     352#define MASK_SYSTEM     0
     353#define MASK_THREAD     1
     354BOOL  OSLibDosQueryAffinity(DWORD fMaskType, DWORD *pdwThreadAffinityMask);
     355
     356#endif //__OSLIBDOS_H__
     357
  • trunk/src/kernel32/process.cpp

    r4658 r7318  
    1 /* $Id: process.cpp,v 1.8 2000-11-21 11:35:09 sandervl Exp $ */
     1/* $Id: process.cpp,v 1.9 2001-11-10 12:47:47 sandervl Exp $ */
    22
    33/*
     
    125125{
    126126    ProcessAffinityMask = affmask;
     127    //TODO: should update all threads, but that doesn't seem possible in OS/2
     128    SetThreadAffinityMask(GetCurrentThread(), ProcessAffinityMask);
    127129    return TRUE;
    128130}
     
    137139    if(lpProcessAffinityMask)
    138140        *lpProcessAffinityMask=ProcessAffinityMask;
    139     if(lpSystemAffinityMask)
    140         *lpSystemAffinityMask=1;
     141
     142    if(lpSystemAffinityMask) {
     143        OSLibDosQueryAffinity(MASK_SYSTEM, lpSystemAffinityMask);
     144    }
    141145    return TRUE;
    142146}
  • trunk/src/kernel32/stubs.cpp

    r6646 r7318  
    1 /* $Id: stubs.cpp,v 1.32 2001-09-05 12:58:00 bird Exp $
     1/* $Id: stubs.cpp,v 1.33 2001-11-10 12:47:47 sandervl Exp $
    22 *
    33 * Win32 KERNEL32 Subsystem for OS/2
     
    17891789
    17901790
    1791 /*****************************************************************************
    1792  * Name      : DWORD SetThreadAffinityMask
    1793  * Purpose   : The SetThreadAffinityMask function sets a processor affinity
    1794  *             mask for a specified thread.
    1795  *             A thread affinity mask is a bit vector in which each bit
    1796  *             represents the processors that a thread is allowed to run on.
    1797  *             A thread affinity mask must be a proper subset of the process
    1798  *             affinity mask for the containing process of a thread. A thread
    1799  *             is only allowed to run on the processors its process is allowed to run on.
    1800  * Parameters: HANDLE hThread              handle to the thread of interest
    1801  *             DWORD  dwThreadAffinityMask a thread affinity mask
    1802  * Variables :
    1803  * Result    : TRUE / FALSE
    1804  * Remark    :
    1805  * Status    : UNTESTED STUB
    1806  *
    1807  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    1808  *****************************************************************************/
    1809 
    1810 DWORD WIN32API SetThreadAffinityMask(HANDLE hThread,
    1811                                         DWORD  dwThreadAffinityMask)
    1812 {
    1813   dprintf(("KERNEL32: SetThreadAffinityMask(%08xh,%08xh) not implemented.\n",
    1814            hThread,
    1815            dwThreadAffinityMask));
    1816 
    1817   return (0);
    1818 }
    1819 
    18201791
    18211792
  • trunk/src/kernel32/thread.cpp

    r6829 r7318  
    1 /* $Id: thread.cpp,v 1.32 2001-09-26 15:29:39 phaller Exp $ */
     1/* $Id: thread.cpp,v 1.33 2001-11-10 12:47:48 sandervl Exp $ */
    22
    33/*
     
    3131#include "exceptutil.h"
    3232#include "oslibmisc.h"
     33#include "oslibdos.h"
    3334#include <handlemanager.h>
    3435
     
    126127  O32_ExitThread(exitcode);
    127128}
     129/*****************************************************************************
     130 * Name      : DWORD SetThreadAffinityMask
     131 * Purpose   : The SetThreadAffinityMask function sets a processor affinity
     132 *             mask for a specified thread.
     133 *             A thread affinity mask is a bit vector in which each bit
     134 *             represents the processors that a thread is allowed to run on.
     135 *             A thread affinity mask must be a proper subset of the process
     136 *             affinity mask for the containing process of a thread. A thread
     137 *             is only allowed to run on the processors its process is allowed to run on.
     138 * Parameters: HANDLE hThread              handle to the thread of interest
     139 *             DWORD  dwThreadAffinityMask a thread affinity mask
     140 * Variables :
     141 * Result    : TRUE / FALSE
     142 * Remark    :
     143 * Status    : UNTESTED STUB
     144 *
     145 * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
     146 *****************************************************************************/
     147
     148DWORD WIN32API SetThreadAffinityMask(HANDLE hThread,
     149                                     DWORD  dwThreadAffinityMask)
     150{
     151  dprintf(("KERNEL32: SetThreadAffinityMask(%08xh,%08xh)",
     152           hThread, dwThreadAffinityMask));
     153
     154  if(hThread != GetCurrentThread()) {
     155      dprintf(("WARNING: Setting the affinity mask for another thread than the current one is not supported!!"));
     156      return FALSE;
     157  }
     158  return OSLibDosSetThreadAffinity(dwThreadAffinityMask);
     159}
    128160//******************************************************************************
    129161//******************************************************************************
     
    171203
    172204  SetWin32TIB();
     205
     206  DWORD dwProcessAffinityMask, dwSystemAffinityMask;
     207
     208  //Change the affinity mask of this thread to the mask for the whole process
     209  if(GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask) == TRUE) {
     210      SetThreadAffinityMask(GetCurrentThread(), dwProcessAffinityMask);
     211  }
     212
    173213  WinExe->tlsAttachThread();              //setup TLS structure of main exe
    174214  Win32DllBase::tlsAttachThreadToAllDlls(); //setup TLS structures of all dlls
Note: See TracChangeset for help on using the changeset viewer.