Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.6 KiB

  1. #---------------------------------------------------------------------
  2. package Win32::Semaphore;
  3. #
  4. # Copyright 1998 Christopher J. Madsen
  5. #
  6. # Created: 3 Feb 1998 from the ActiveWare version
  7. # (c) 1995 Microsoft Corporation. All rights reserved.
  8. # Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
  9. #
  10. # Other modifications (c) 1997 by Gurusamy Sarathy <[email protected]>
  11. #
  12. # Author: Christopher J. Madsen <[email protected]>
  13. # Version: 1.00 (6-Feb-1998)
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the same terms as Perl itself.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
  21. # GNU General Public License or the Artistic License for more details.
  22. #
  23. # Use Win32 semaphore objects for synchronization
  24. #---------------------------------------------------------------------
  25. $VERSION = '1.02';
  26. use Win32::IPC 1.00 '/./'; # Import everything
  27. require Exporter;
  28. require DynaLoader;
  29. @ISA = qw(Exporter DynaLoader Win32::IPC);
  30. @EXPORT_OK = qw(
  31. wait_all wait_any
  32. );
  33. bootstrap Win32::Semaphore;
  34. sub Create { $_[0] = new('Win32::Semaphore',@_[1..3]) }
  35. sub Open { $_[0] = Win32::Semaphore->open($_[1]) }
  36. sub Release { &release }
  37. 1;
  38. __END__
  39. =head1 NAME
  40. Win32::Semaphore - Use Win32 semaphore objects from Perl
  41. =head1 SYNOPSIS
  42. require Win32::Semaphore;
  43. $sem = Win32::Semaphore->new($initial,$maximum,$name);
  44. $sem->wait;
  45. =head1 DESCRIPTION
  46. This module allows access to Win32 semaphore objects. The C<wait>
  47. method and C<wait_all> & C<wait_any> functions are inherited from the
  48. L<"Win32::IPC"> module.
  49. =head2 Methods
  50. =over 4
  51. =item $semaphore = Win32::Semaphore->new($initial, $maximum, [$name])
  52. Constructor for a new semaphore object. C<$initial> is the initial
  53. count, and C<$maximum> is the maximum count for the semaphore. If
  54. C<$name> is omitted, creates an unnamed semaphore object.
  55. If C<$name> signifies an existing semaphore object, then C<$initial>
  56. and C<$maximum> are ignored and the object is opened.
  57. =item $semaphore = Win32::Semaphore->open($name)
  58. Constructor for opening an existing semaphore object.
  59. =item $semaphore->release([$increment, [$previous]])
  60. Increment the count of C<$semaphore> by C<$increment> (default 1).
  61. If C<$increment> plus the semaphore's current count is more than its
  62. maximum count, the count is not changed. Returns true if the
  63. increment is successful.
  64. The semaphore's count (before incrementing) is stored in the second
  65. argument (if any).
  66. It is not necessary to wait on a semaphore before calling C<release>,
  67. but you'd better know what you're doing.
  68. =item $semaphore->wait([$timeout])
  69. Wait for C<$semaphore>'s count to be nonzero, then decrement it by 1.
  70. See L<"Win32::IPC">.
  71. =back
  72. =head2 Deprecated Functions and Methods
  73. B<Win32::Semaphore> still supports the ActiveWare syntax, but its use
  74. is deprecated.
  75. =over 4
  76. =item Win32::Semaphore::Create($SemObject,$Initial,$Max,$Name)
  77. Use C<$SemObject = Win32::Semaphore-E<gt>new($Initial,$Max,$Name)> instead.
  78. =item Win32::Semaphore::Open($SemObject, $Name)
  79. Use C<$SemObject = Win32::Semaphore-E<gt>open($Name)> instead.
  80. =item $SemObj->Release($Count,$LastVal)
  81. Use C<$SemObj-E<gt>release($Count,$LastVal)> instead.
  82. =back
  83. =head1 AUTHOR
  84. Christopher J. Madsen E<lt>F<[email protected]>E<gt>
  85. Loosely based on the original module by ActiveWare Internet Corp.,
  86. F<http://www.ActiveWare.com>
  87. =cut