LL_MAN.C 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. /**********************************************************************
  16. module: LL_MAN.C
  17. author: James R. Dose
  18. date: January 1, 1994
  19. Linked list management routines.
  20. (c) Copyright 1994 James R. Dose. All Rights Reserved.
  21. **********************************************************************/
  22. #define LOCKMEMORY
  23. #include <stddef.h>
  24. #include "ll_man.h"
  25. #ifdef LOCKMEMORY
  26. #include "dpmi.h"
  27. #endif
  28. #define OFFSET( structure, offset ) \
  29. ( *( ( char ** )&( structure )[ offset ] ) )
  30. /**********************************************************************
  31. Memory locked functions:
  32. **********************************************************************/
  33. #define LL_LockStart LL_AddNode
  34. void LL_AddNode
  35. (
  36. char *item,
  37. char **head,
  38. char **tail,
  39. int next,
  40. int prev
  41. )
  42. {
  43. OFFSET( item, prev ) = NULL;
  44. OFFSET( item, next ) = *head;
  45. if ( *head )
  46. {
  47. OFFSET( *head, prev ) = item;
  48. }
  49. else
  50. {
  51. *tail = item;
  52. }
  53. *head = item;
  54. }
  55. void LL_RemoveNode
  56. (
  57. char *item,
  58. char **head,
  59. char **tail,
  60. int next,
  61. int prev
  62. )
  63. {
  64. if ( OFFSET( item, prev ) == NULL )
  65. {
  66. *head = OFFSET( item, next );
  67. }
  68. else
  69. {
  70. OFFSET( OFFSET( item, prev ), next ) = OFFSET( item, next );
  71. }
  72. if ( OFFSET( item, next ) == NULL )
  73. {
  74. *tail = OFFSET( item, prev );
  75. }
  76. else
  77. {
  78. OFFSET( OFFSET( item, next ), prev ) = OFFSET( item, prev );
  79. }
  80. OFFSET( item, next ) = NULL;
  81. OFFSET( item, prev ) = NULL;
  82. }
  83. /*---------------------------------------------------------------------
  84. Function: LL_LockEnd
  85. Used for determining the length of the functions to lock in memory.
  86. ---------------------------------------------------------------------*/
  87. static void LL_LockEnd
  88. (
  89. void
  90. )
  91. {
  92. }
  93. /*---------------------------------------------------------------------
  94. Function: LL_UnlockMemory
  95. Unlocks all neccessary data.
  96. ---------------------------------------------------------------------*/
  97. void LL_UnlockMemory
  98. (
  99. void
  100. )
  101. {
  102. #ifdef LOCKMEMORY
  103. DPMI_UnlockMemoryRegion( LL_LockStart, LL_LockEnd );
  104. #endif
  105. }
  106. /*---------------------------------------------------------------------
  107. Function: LL_LockMemory
  108. Locks all neccessary data.
  109. ---------------------------------------------------------------------*/
  110. int LL_LockMemory
  111. (
  112. void
  113. )
  114. {
  115. #ifdef LOCKMEMORY
  116. int status;
  117. status = DPMI_LockMemoryRegion( LL_LockStart, LL_LockEnd );
  118. if ( status != DPMI_Ok )
  119. {
  120. return( LL_Error );
  121. }
  122. #endif
  123. return( LL_Ok );
  124. }