globalmutexchild.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testglobalmutex.h"
  17. #include "fspr_pools.h"
  18. #include "fspr_file_io.h"
  19. #include "fspr_general.h"
  20. #include "fspr_global_mutex.h"
  21. #include "fspr_strings.h"
  22. #include "fspr.h"
  23. #if APR_HAVE_STDLIB_H
  24. #include <stdlib.h>
  25. #endif
  26. int main(int argc, const char * const argv[])
  27. {
  28. fspr_pool_t *p;
  29. int i = 0;
  30. fspr_lockmech_e mech;
  31. fspr_global_mutex_t *global_lock;
  32. fspr_status_t rv;
  33. fspr_initialize();
  34. atexit(fspr_terminate);
  35. fspr_pool_create(&p, NULL);
  36. if (argc >= 2) {
  37. mech = (fspr_lockmech_e)fspr_strtoi64(argv[1], NULL, 0);
  38. }
  39. else {
  40. mech = APR_LOCK_DEFAULT;
  41. }
  42. rv = fspr_global_mutex_create(&global_lock, LOCKNAME, mech, p);
  43. if (rv != APR_SUCCESS) {
  44. exit(-rv);
  45. }
  46. fspr_global_mutex_child_init(&global_lock, LOCKNAME, p);
  47. while (1) {
  48. fspr_global_mutex_lock(global_lock);
  49. if (i == MAX_ITER) {
  50. fspr_global_mutex_unlock(global_lock);
  51. exit(i);
  52. }
  53. i++;
  54. fspr_global_mutex_unlock(global_lock);
  55. }
  56. exit(0);
  57. }