comm_os.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Linux 2.6.32 and later Kernel module for VMware MVP PVTCP Server
  3. *
  4. * Copyright (C) 2010-2013 VMware, Inc. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; see the file COPYING. If not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #line 5
  20. /**
  21. * @file
  22. *
  23. * @brief Cross-platform base type definitions and function declarations.
  24. * Includes OS-specific base type definitions and function declarations.
  25. */
  26. #ifndef _COMM_OS_H_
  27. #define _COMM_OS_H_
  28. /* For-ever timeout constant (in milliseconds). */
  29. #define COMM_OS_4EVER_TO ((unsigned long long)(~0UL >> 1))
  30. /* Condition function prototype. Returns 1: true, 0: false, < 0: error code. */
  31. typedef int (*CommOSWaitConditionFunc)(void *arg1, void *arg2);
  32. /* Dispatch function prototype. Called by input (dispatch) kernel threads. */
  33. typedef unsigned int (*CommOSDispatchFunc)(void);
  34. /* Module initialization and exit callback functions. */
  35. extern int (*commOSModInit)(void *args);
  36. extern void (*commOSModExit)(void);
  37. /* Macro to assign Init and Exit callbacks. */
  38. #define COMM_OS_MOD_INIT(init, exit) \
  39. int (*commOSModInit)(void *args) = init; \
  40. void (*commOSModExit)(void) = exit
  41. /*
  42. * OS-specific implementations must provide the following:
  43. * 1. Types:
  44. * CommOSAtomic
  45. * CommOSSpinlock
  46. * CommOSMutex
  47. * CommOSWaitQueue
  48. * CommOSWork
  49. * CommOSWorkFunc
  50. * CommOSList
  51. * CommOSModule
  52. * struct kvec
  53. *
  54. * 2. Definition, initializers:
  55. * CommOSSpinlock_Define()
  56. *
  57. * 3. Functions:
  58. * void CommOS_Debug(const char *format, ...);
  59. * void CommOS_Log(const char *format, ...);
  60. * void CommOS_WriteAtomic(CommOSAtomic *atomic, int val);
  61. * int CommOS_ReadAtomic(CommOSAtomic *atomic);
  62. * int CommOS_AddReturnAtomic(CommOSAtomic *atomic, int val);
  63. * int CommOS_SubReturnAtomic(CommOSAtomic *atomic, int val);
  64. * void CommOS_SpinlockInit(CommOSSpinlock *lock);
  65. * void CommOS_SpinLockBH(CommOSSpinlock *lock);
  66. * int CommOS_SpinTrylockBH(CommOSSpinlock *lock);
  67. * void CommOS_SpinUnlockBH(CommOSSpinlock *lock);
  68. * void CommOS_SpinLock(CommOSSpinlock *lock);
  69. * int CommOS_SpinTrylock(CommOSSpinlock *lock);
  70. * void CommOS_SpinUnlock(CommOSSpinlock *lock);
  71. * void CommOS_MutexInit(CommOSMutex *mutex);
  72. * void CommOS_MutexLock(CommOSMutex *mutex);
  73. * int CommOS_MutexLockUninterruptible(CommOSMutex *mutex);
  74. * int CommOS_MutexTrylock(CommOSMutex *mutex);
  75. * void CommOS_MutexUnlock(CommOSMutex *mutex);
  76. * void CommOS_WaitQueueInit(CommOSWaitQueue *wq);
  77. * CommOS_DoWait(CommOSWaitQueue *wq,
  78. * CommOSWaitConditionFunc cond,
  79. * void *condArg1,
  80. * void *condArg2,
  81. * unsigned long long *timeoutMillis,
  82. * int interruptible);
  83. * int CommOS_Wait(CommOSWaitQueue *wq,
  84. * CommOSWaitConditionFunc func,
  85. * void *funcArg1,
  86. * void *funcArg2,
  87. * unsigned long long *timeoutMillis);
  88. * int CommOS_WaitUninterruptible(CommOSWaitQueue *wq,
  89. * CommOSWaitConditionFunc func,
  90. * void *funcArg1,
  91. * void *funcArg2,
  92. * unsigned long long *timeoutMillis);
  93. * void CommOS_WakeUp(CommOSWaitQueue *wq);
  94. * void *CommOS_KmallocNoSleep(unsigned int size);
  95. * void *CommOS_Kmalloc(unsigned int size);
  96. * void CommOS_Kfree(void *arg);
  97. * void CommOS_Yield(void);
  98. * unsigned long long CommOS_GetCurrentMillis(void);
  99. * void CommOS_ListInit(CommOSList *list);
  100. * int CommOS_ListEmpty(CommOSList *list);
  101. * void CommOS_ListAdd(CommOSList *list, CommOSList *listElem);
  102. * void CommOS_ListAddTail(CommOSList *list, CommOSList *listElem);
  103. * void int CommOS_ListDel(CommOSList *listElem);
  104. * Macros:
  105. * CommOS_ListForEach(*list, *item, itemListFieldName);
  106. * CommOS_ListForEachSafe(*list, *item, *tmp, itemListFieldName);
  107. * void CommOS_ListSplice(CommOSList *list, CommOSList *listToAdd);
  108. * void CommOS_ListSpliceTail(CommOSList *list, CommOSList *listToAdd);
  109. * CommOSModule CommOS_ModuleSelf(void);
  110. * int CommOS_ModuleGet(CommOSModule module);
  111. * void CommOS_ModulePut(CommOSModule module);
  112. * void CommOS_MemBarrier(void);
  113. *
  114. * These cannot be defined here: a) non-pointer type definitions need size
  115. * information, and b) functions may or may not be inlined, or macros may
  116. * be used instead.
  117. */
  118. #ifdef __linux__
  119. #include "comm_os_linux.h"
  120. #else
  121. #error "Unsupported OS"
  122. #endif
  123. /* Functions to start and stop the dispatch and aio kernel threads. */
  124. void CommOS_StopIO(void);
  125. void CommOS_ScheduleDisp(void);
  126. void CommOS_InitWork(CommOSWork *work, CommOSWorkFunc func);
  127. int CommOS_ScheduleAIOWork(CommOSWork *work);
  128. void CommOS_FlushAIOWork(CommOSWork *work);
  129. int
  130. CommOS_StartIO(const char *dispatchTaskName,
  131. CommOSDispatchFunc dispatchHandler,
  132. unsigned int interval,
  133. unsigned int maxCycles,
  134. const char *aioTaskName);
  135. #endif /* _COMM_OS_H_ */