home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / semaph / sema.doc < prev    next >
Text File  |  1988-08-10  |  5KB  |  230 lines

  1.                     Novell NetWare Semaphore Routine
  2.                         Written by Tom Scribner
  3.  
  4. INTRODUCTION:
  5.  
  6. Novell's NetWare provides semaphore capability for a variety of
  7. uses.  Several of these uses are in an exclusion mechanism where
  8. record locking cannot be used, multiuser applications, and
  9. program to program notification.   The server maintains a table
  10. where semaphores are placed.  Applications can place a semaphore
  11. onto the table, increment the semaphore count and close the 
  12. semaphore.  
  13.  
  14. A good example of semaphores are in a record locking capacity.
  15. Currently DOS does not provide a means of locking a record with
  16. read access; therefore, with several B-Tree, ISAM file management
  17. packages, if a user locked a record (and the index record), then
  18. when another user wished to only read that record, they would be
  19. denied until the lock was freed.  Semaphores can provide the
  20. capability for read-through locks.  The application opens a semaphore
  21. when its intentions are to update a record.  Once the record is
  22. updated, the semaphore is closed.  (NOTE: in order to use this
  23. method effectively, the application must first check to see if this
  24. semaphore is already active).  If the application only wishes to
  25. read the record with no update, no semaphore should be opened.
  26.  
  27. Semaphores can also provide limited access to programs for multi-
  28. user capability.  If an application is designed for only a 5 station
  29. access, an application can open a semaphore, check its open count,
  30. and if greater than the maximum number of allocated users, can 
  31. notify the user and abort.   Several packages on the market today
  32. use this method of limiting the number of users.
  33.  
  34. If you have a problem, need assistance, or have suggestions, please
  35. contact me via CompuServe.  
  36.  
  37.      Tom Scribner
  38.      CompuServer ID <76154,1265>
  39.  
  40.  
  41. NOTE:   These routines were developed with Microsoft V5 C Compiler.
  42.         If you use another version or cannot use functional 
  43.         prototypes, remove the definition of MSC5 in the make file.
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.                                   Page -1-
  61.  
  62.  
  63. NetWare Semaphore Function Call's                       OpenSemaphore
  64. ---------------------------------------------------------------------
  65.  
  66. SUMMARY:
  67.  
  68. #include <sema.h>
  69.  
  70. long OpenSemaphore( SemaphoreName, InitValue, &OpenCount)
  71. char *SemaphoreName;          /* Character Name for Sema */
  72. int InitValue;                /* Initial Open Value */
  73. int *OpenCount;               /* Return for open count */
  74.  
  75. DESCRIPTION:
  76.  
  77. The OpenSemaphore function places the SemaphoreName in the Server's
  78. semaphore table.  The InitValue is only set the first time the
  79. semaphore is opened.  OpenCount provides the ability to obtain the
  80. number of similarly named semaphores currently open.
  81.  
  82. RETURN VALUE:
  83.  
  84. The OpenSemphore returns the semaphore handle used for the other
  85. semaphore functions.  A return value of -1 (ERROR) indicates a
  86. error, and the actual error code is placed into NetError.
  87.  
  88. EXAMPLE
  89.  
  90. char *SNAME = {"NET_ISAM"};
  91. int  counter;
  92.  
  93. long ret_handle;
  94.  
  95. ret_handle = OpenSemaphore(SNAME,1,&counter);
  96. printf("There are %d users currently in %s\n",counter,SNAME);
  97.  
  98.  
  99.       
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.                                 Page -2-
  119.  
  120. NetWare Semaphore Function Call's                    ExamineSemaphore
  121. ---------------------------------------------------------------------
  122.  
  123. SUMMARY:
  124.  
  125. #include <sema.h>
  126.  
  127. int ExamineSemaphore( handle )
  128. long handle;            /* Handle returned from OpenSemaphore */
  129.  
  130.  
  131. DESCRIPTION:
  132.  
  133. The ExamineSemaphore function obtains the open count of the named
  134. handle.   The handle used is returned from the OpenSemaphore
  135. function.
  136.  
  137. RETURN VALUE:
  138.  
  139. The ExamineSemaphore returns the number of open semaphores. A
  140. return value of -1 (ERROR) indicates a error, with the error
  141. number in NetError;
  142.  
  143. EXAMPLE:
  144.  
  145. long shandle;   /* already contains the handle from open semaphore */
  146. int open_users;
  147.  
  148. open_users = ExamineSemaphore( shandle );
  149. printf("There are %d users in application\n",open_users);
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.                                 Page -3-
  177.  
  178.  
  179. NetWare Semaphore Function Calls                      CloseSemaphore
  180. ---------------------------------------------------------------------
  181.  
  182. SUMMARY:
  183.  
  184. #include <sema.h>
  185.  
  186. int CloseSemaphore( handle )
  187. long handle;              /* handle from OpenSemaphore */
  188.  
  189. DESCRIPTION:
  190.  
  191. The CloseSemaphore closes the opened semaphore.
  192.  
  193. EXAMPLE:
  194.  
  195. long shandle;        /* contains the handle from open semaphore */
  196.  
  197. if( CloseSemaphore( shandle ) == 0)
  198.         printf("Semaphore closed successfully\n");
  199. else
  200.         printf("Error during closing of semaphore, Error no %d\n",
  201.            NetError);
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.                                 Page -4-
  228.  
  229.  
  230.