SysHelper.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Author : Bruce Liang
  5. * Website : https://github.com/ldcsaa
  6. * Project : https://github.com/ldcsaa/HP-Socket
  7. * Blog : http://www.cnblogs.com/ldcsaa
  8. * Wiki : http://www.oschina.net/p/hp-socket
  9. * QQ Group : 44636872, 75375912
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. #include "SysHelper.h"
  24. #include <stdio.h>
  25. #include <sys/utsname.h>
  26. DWORD _GetKernelVersion()
  27. {
  28. utsname uts;
  29. if(uname(&uts) == RS_FAIL)
  30. return 0;
  31. char c;
  32. int major, minor, revise;
  33. if(sscanf(uts.release, "%d.%d.%d%c", &major, &minor, &revise, &c) < 3)
  34. return 0;
  35. return (DWORD)((major << 16) | (minor << 8) | revise);
  36. }
  37. DWORD GetSysPageSize()
  38. {
  39. static const DWORD _s_page_size = (DWORD)SysGetPageSize();
  40. return _s_page_size;
  41. }
  42. DWORD GetKernelVersion()
  43. {
  44. static const DWORD _s_kernel_version = _GetKernelVersion();
  45. return _s_kernel_version;
  46. }
  47. BOOL IsKernelVersionAbove(BYTE major, BYTE minor, BYTE revise)
  48. {
  49. return GetKernelVersion() >= (DWORD)((major << 16) | (minor << 8) | revise);
  50. }
  51. DWORD GetDefaultWorkerThreadCount()
  52. {
  53. static const DWORD _s_dwtc = MIN((PROCESSOR_COUNT * 2 + 2), MAX_WORKER_THREAD_COUNT);
  54. return _s_dwtc;
  55. }