OLD | NEW |
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 else | 141 else |
142 { | 142 { |
143 while (notified->cv[index].times-- > 0) | 143 while (notified->cv[index].times-- > 0) |
144 { | 144 { |
145 rv = pthread_cond_signal(&cv->cv); | 145 rv = pthread_cond_signal(&cv->cv); |
146 PR_ASSERT(0 == rv); | 146 PR_ASSERT(0 == rv); |
147 } | 147 } |
148 } | 148 } |
149 #if defined(DEBUG) | 149 #if defined(DEBUG) |
150 pt_debug.cvars_notified += 1; | 150 pt_debug.cvars_notified += 1; |
151 if (0 > PR_AtomicDecrement(&cv->notify_pending)) | 151 if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending)) |
152 { | 152 { |
153 pt_debug.delayed_cv_deletes += 1; | 153 pt_debug.delayed_cv_deletes += 1; |
154 PR_DestroyCondVar(cv); | 154 PR_DestroyCondVar(cv); |
155 } | 155 } |
156 #else /* defined(DEBUG) */ | 156 #else /* defined(DEBUG) */ |
157 if (0 > PR_AtomicDecrement(&cv->notify_pending)) | 157 if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending)) |
158 PR_DestroyCondVar(cv); | 158 PR_DestroyCondVar(cv); |
159 #endif /* defined(DEBUG) */ | 159 #endif /* defined(DEBUG) */ |
160 } | 160 } |
161 prev = notified; | 161 prev = notified; |
162 notified = notified->link; | 162 notified = notified->link; |
163 if (&post != prev) PR_DELETE(prev); | 163 if (&post != prev) PR_DELETE(prev); |
164 } while (NULL != notified); | 164 } while (NULL != notified); |
165 } /* pt_PostNotifies */ | 165 } /* pt_PostNotifies */ |
166 | 166 |
167 PR_IMPLEMENT(PRLock*) PR_NewLock(void) | 167 PR_IMPLEMENT(PRLock*) PR_NewLock(void) |
(...skipping 21 matching lines...) Expand all Loading... |
189 PR_ASSERT(NULL != lock); | 189 PR_ASSERT(NULL != lock); |
190 PR_ASSERT(PR_FALSE == lock->locked); | 190 PR_ASSERT(PR_FALSE == lock->locked); |
191 PR_ASSERT(0 == lock->notified.length); | 191 PR_ASSERT(0 == lock->notified.length); |
192 PR_ASSERT(NULL == lock->notified.link); | 192 PR_ASSERT(NULL == lock->notified.link); |
193 rv = pthread_mutex_destroy(&lock->mutex); | 193 rv = pthread_mutex_destroy(&lock->mutex); |
194 PR_ASSERT(0 == rv); | 194 PR_ASSERT(0 == rv); |
195 #if defined(DEBUG) | 195 #if defined(DEBUG) |
196 memset(lock, 0xaf, sizeof(PRLock)); | 196 memset(lock, 0xaf, sizeof(PRLock)); |
197 pt_debug.locks_destroyed += 1; | 197 pt_debug.locks_destroyed += 1; |
198 #endif | 198 #endif |
199 PR_DELETE(lock); | 199 PR_Free(lock); |
200 } /* PR_DestroyLock */ | 200 } /* PR_DestroyLock */ |
201 | 201 |
202 PR_IMPLEMENT(void) PR_Lock(PRLock *lock) | 202 PR_IMPLEMENT(void) PR_Lock(PRLock *lock) |
203 { | 203 { |
204 PRIntn rv; | 204 PRIntn rv; |
205 PR_ASSERT(lock != NULL); | 205 PR_ASSERT(lock != NULL); |
206 rv = pthread_mutex_lock(&lock->mutex); | 206 rv = pthread_mutex_lock(&lock->mutex); |
207 PR_ASSERT(0 == rv); | 207 PR_ASSERT(0 == rv); |
208 PR_ASSERT(0 == lock->notified.length); | 208 PR_ASSERT(0 == lock->notified.length); |
209 PR_ASSERT(NULL == lock->notified.link); | 209 PR_ASSERT(NULL == lock->notified.link); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 /* if not full, enter new CV in this array */ | 331 /* if not full, enter new CV in this array */ |
332 if (notified->length < PT_CV_NOTIFIED_LENGTH) break; | 332 if (notified->length < PT_CV_NOTIFIED_LENGTH) break; |
333 | 333 |
334 /* if there's no link, create an empty array and link it */ | 334 /* if there's no link, create an empty array and link it */ |
335 if (NULL == notified->link) | 335 if (NULL == notified->link) |
336 notified->link = PR_NEWZAP(_PT_Notified); | 336 notified->link = PR_NEWZAP(_PT_Notified); |
337 notified = notified->link; | 337 notified = notified->link; |
338 } | 338 } |
339 | 339 |
340 /* A brand new entry in the array */ | 340 /* A brand new entry in the array */ |
341 (void)PR_AtomicIncrement(&cvar->notify_pending); | 341 (void)PR_ATOMIC_INCREMENT(&cvar->notify_pending); |
342 notified->cv[index].times = (broadcast) ? -1 : 1; | 342 notified->cv[index].times = (broadcast) ? -1 : 1; |
343 notified->cv[index].cv = cvar; | 343 notified->cv[index].cv = cvar; |
344 notified->length += 1; | 344 notified->length += 1; |
345 | 345 |
346 finished: | 346 finished: |
347 PR_ASSERT(PR_TRUE == cvar->lock->locked); | 347 PR_ASSERT(PR_TRUE == cvar->lock->locked); |
348 PR_ASSERT(pthread_equal(cvar->lock->owner, pthread_self())); | 348 PR_ASSERT(pthread_equal(cvar->lock->owner, pthread_self())); |
349 } /* pt_PostNotifyToCvar */ | 349 } /* pt_PostNotifyToCvar */ |
350 | 350 |
351 PR_IMPLEMENT(PRCondVar*) PR_NewCondVar(PRLock *lock) | 351 PR_IMPLEMENT(PRCondVar*) PR_NewCondVar(PRLock *lock) |
352 { | 352 { |
353 PRCondVar *cv = PR_NEW(PRCondVar); | 353 PRCondVar *cv = PR_NEW(PRCondVar); |
354 PR_ASSERT(lock != NULL); | 354 PR_ASSERT(lock != NULL); |
355 if (cv != NULL) | 355 if (cv != NULL) |
356 { | 356 { |
357 int rv = _PT_PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); | 357 int rv = _PT_PTHREAD_COND_INIT(cv->cv, _pt_cvar_attr); |
358 PR_ASSERT(0 == rv); | 358 PR_ASSERT(0 == rv); |
359 cv->lock = lock; | 359 cv->lock = lock; |
360 cv->notify_pending = 0; | 360 cv->notify_pending = 0; |
361 #if defined(DEBUG) | 361 #if defined(DEBUG) |
362 pt_debug.cvars_created += 1; | 362 pt_debug.cvars_created += 1; |
363 #endif | 363 #endif |
364 } | 364 } |
365 return cv; | 365 return cv; |
366 } /* PR_NewCondVar */ | 366 } /* PR_NewCondVar */ |
367 | 367 |
368 PR_IMPLEMENT(void) PR_DestroyCondVar(PRCondVar *cvar) | 368 PR_IMPLEMENT(void) PR_DestroyCondVar(PRCondVar *cvar) |
369 { | 369 { |
370 if (0 > PR_AtomicDecrement(&cvar->notify_pending)) | 370 if (0 > PR_ATOMIC_DECREMENT(&cvar->notify_pending)) |
371 { | 371 { |
372 PRIntn rv = pthread_cond_destroy(&cvar->cv); PR_ASSERT(0 == rv); | 372 PRIntn rv = pthread_cond_destroy(&cvar->cv); PR_ASSERT(0 == rv); |
373 #if defined(DEBUG) | 373 #if defined(DEBUG) |
374 memset(cvar, 0xaf, sizeof(PRCondVar)); | 374 memset(cvar, 0xaf, sizeof(PRCondVar)); |
375 pt_debug.cvars_destroyed += 1; | 375 pt_debug.cvars_destroyed += 1; |
376 #endif | 376 #endif |
377 PR_DELETE(cvar); | 377 PR_Free(cvar); |
378 } | 378 } |
379 } /* PR_DestroyCondVar */ | 379 } /* PR_DestroyCondVar */ |
380 | 380 |
381 PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout) | 381 PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout) |
382 { | 382 { |
383 PRIntn rv; | 383 PRIntn rv; |
384 PRThread *thred = PR_GetCurrentThread(); | 384 PRThread *thred = PR_GetCurrentThread(); |
385 | 385 |
386 PR_ASSERT(cvar != NULL); | 386 PR_ASSERT(cvar != NULL); |
387 /* We'd better be locked */ | 387 /* We'd better be locked */ |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 /**************************************************************/ | 456 /**************************************************************/ |
457 /**************************************************************/ | 457 /**************************************************************/ |
458 /***************************MONITORS***************************/ | 458 /***************************MONITORS***************************/ |
459 /**************************************************************/ | 459 /**************************************************************/ |
460 /**************************************************************/ | 460 /**************************************************************/ |
461 | 461 |
462 PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(void) | 462 PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(void) |
463 { | 463 { |
464 PRMonitor *mon; | 464 PRMonitor *mon; |
465 PRCondVar *cvar; | 465 PRCondVar *cvar; |
| 466 int rv; |
466 | 467 |
467 if (!_pr_initialized) _PR_ImplicitInitialization(); | 468 if (!_pr_initialized) _PR_ImplicitInitialization(); |
468 | 469 |
469 cvar = PR_NEWZAP(PRCondVar); | 470 cvar = PR_NEWZAP(PRCondVar); |
470 if (NULL == cvar) | 471 if (NULL == cvar) |
471 { | 472 { |
472 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); | 473 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
473 return NULL; | 474 return NULL; |
474 } | 475 } |
475 mon = PR_NEWZAP(PRMonitor); | 476 mon = PR_NEWZAP(PRMonitor); |
476 if (mon != NULL) | 477 if (mon == NULL) |
477 { | 478 { |
478 int rv; | 479 PR_Free(cvar); |
479 rv = _PT_PTHREAD_MUTEX_INIT(mon->lock.mutex, _pt_mattr); | 480 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
480 PR_ASSERT(0 == rv); | 481 return NULL; |
| 482 } |
481 | 483 |
482 _PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner); | 484 rv = _PT_PTHREAD_MUTEX_INIT(mon->lock.mutex, _pt_mattr); |
| 485 PR_ASSERT(0 == rv); |
| 486 if (0 != rv) |
| 487 { |
| 488 PR_Free(mon); |
| 489 PR_Free(cvar); |
| 490 PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, 0); |
| 491 return NULL; |
| 492 } |
483 | 493 |
484 mon->cvar = cvar; | 494 _PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner); |
485 rv = _PT_PTHREAD_COND_INIT(mon->cvar->cv, _pt_cvar_attr); | 495 |
486 PR_ASSERT(0 == rv); | 496 mon->cvar = cvar; |
487 mon->entryCount = 0; | 497 rv = _PT_PTHREAD_COND_INIT(mon->cvar->cv, _pt_cvar_attr); |
488 mon->cvar->lock = &mon->lock; | 498 PR_ASSERT(0 == rv); |
489 if (0 != rv) | 499 mon->entryCount = 0; |
490 { | 500 mon->cvar->lock = &mon->lock; |
491 PR_DELETE(mon); | 501 if (0 != rv) |
492 PR_DELETE(cvar); | 502 { |
493 mon = NULL; | 503 pthread_mutex_destroy(&mon->lock.mutex); |
494 } | 504 PR_Free(mon); |
| 505 PR_Free(cvar); |
| 506 PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, 0); |
| 507 return NULL; |
495 } | 508 } |
496 return mon; | 509 return mon; |
497 } /* PR_NewMonitor */ | 510 } /* PR_NewMonitor */ |
498 | 511 |
499 PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name) | 512 PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name) |
500 { | 513 { |
501 PRMonitor* mon = PR_NewMonitor(); | 514 PRMonitor* mon = PR_NewMonitor(); |
502 if (mon) | 515 if (mon) |
503 mon->name = name; | 516 mon->name = name; |
504 return mon; | 517 return mon; |
505 } | 518 } |
506 | 519 |
507 PR_IMPLEMENT(void) PR_DestroyMonitor(PRMonitor *mon) | 520 PR_IMPLEMENT(void) PR_DestroyMonitor(PRMonitor *mon) |
508 { | 521 { |
509 int rv; | 522 int rv; |
510 PR_ASSERT(mon != NULL); | 523 PR_ASSERT(mon != NULL); |
511 PR_DestroyCondVar(mon->cvar); | 524 PR_DestroyCondVar(mon->cvar); |
512 rv = pthread_mutex_destroy(&mon->lock.mutex); PR_ASSERT(0 == rv); | 525 rv = pthread_mutex_destroy(&mon->lock.mutex); PR_ASSERT(0 == rv); |
513 #if defined(DEBUG) | 526 #if defined(DEBUG) |
514 memset(mon, 0xaf, sizeof(PRMonitor)); | 527 memset(mon, 0xaf, sizeof(PRMonitor)); |
515 #endif | 528 #endif |
516 PR_DELETE(mon); | 529 PR_Free(mon); |
517 } /* PR_DestroyMonitor */ | 530 } /* PR_DestroyMonitor */ |
518 | 531 |
519 | 532 |
520 /* The GC uses this; it is quite arguably a bad interface. I'm just | 533 /* The GC uses this; it is quite arguably a bad interface. I'm just |
521 * duplicating it for now - XXXMB | 534 * duplicating it for now - XXXMB |
522 */ | 535 */ |
523 PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon) | 536 PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon) |
524 { | 537 { |
525 pthread_t self = pthread_self(); | 538 pthread_t self = pthread_self(); |
526 if (pthread_equal(mon->owner, self)) | 539 if (pthread_equal(mon->owner, self)) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 return status; | 680 return status; |
668 } /* PR_WaitSem */ | 681 } /* PR_WaitSem */ |
669 | 682 |
670 PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *semaphore) | 683 PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *semaphore) |
671 { | 684 { |
672 static PRBool unwarned = PR_TRUE; | 685 static PRBool unwarned = PR_TRUE; |
673 if (unwarned) unwarned = _PR_Obsolete( | 686 if (unwarned) unwarned = _PR_Obsolete( |
674 "PR_DestroySem", "locks & condition variables"); | 687 "PR_DestroySem", "locks & condition variables"); |
675 PR_DestroyLock(semaphore->cvar->lock); | 688 PR_DestroyLock(semaphore->cvar->lock); |
676 PR_DestroyCondVar(semaphore->cvar); | 689 PR_DestroyCondVar(semaphore->cvar); |
677 PR_DELETE(semaphore); | 690 PR_Free(semaphore); |
678 } /* PR_DestroySem */ | 691 } /* PR_DestroySem */ |
679 | 692 |
680 PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value) | 693 PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value) |
681 { | 694 { |
682 PRSemaphore *semaphore; | 695 PRSemaphore *semaphore; |
683 static PRBool unwarned = PR_TRUE; | 696 static PRBool unwarned = PR_TRUE; |
684 if (!_pr_initialized) _PR_ImplicitInitialization(); | 697 if (!_pr_initialized) _PR_ImplicitInitialization(); |
685 | 698 |
686 if (unwarned) unwarned = _PR_Obsolete( | 699 if (unwarned) unwarned = _PR_Obsolete( |
687 "PR_NewSem", "locks & condition variables"); | 700 "PR_NewSem", "locks & condition variables"); |
688 | 701 |
689 semaphore = PR_NEWZAP(PRSemaphore); | 702 semaphore = PR_NEWZAP(PRSemaphore); |
690 if (NULL != semaphore) | 703 if (NULL != semaphore) |
691 { | 704 { |
692 PRLock *lock = PR_NewLock(); | 705 PRLock *lock = PR_NewLock(); |
693 if (NULL != lock) | 706 if (NULL != lock) |
694 { | 707 { |
695 semaphore->cvar = PR_NewCondVar(lock); | 708 semaphore->cvar = PR_NewCondVar(lock); |
696 if (NULL != semaphore->cvar) | 709 if (NULL != semaphore->cvar) |
697 { | 710 { |
698 semaphore->count = value; | 711 semaphore->count = value; |
699 return semaphore; | 712 return semaphore; |
700 } | 713 } |
701 PR_DestroyLock(lock); | 714 PR_DestroyLock(lock); |
702 } | 715 } |
703 PR_DELETE(semaphore); | 716 PR_Free(semaphore); |
704 } | 717 } |
705 return NULL; | 718 return NULL; |
706 } | 719 } |
707 | 720 |
708 /* | 721 /* |
709 * Define the interprocess named semaphore functions. | 722 * Define the interprocess named semaphore functions. |
710 * There are three implementations: | 723 * There are three implementations: |
711 * 1. POSIX semaphore based; | 724 * 1. POSIX semaphore based; |
712 * 2. System V semaphore based; | 725 * 2. System V semaphore based; |
713 * 3. unsupported (fails with PR_NOT_IMPLEMENTED_ERROR). | 726 * 3. unsupported (fails with PR_NOT_IMPLEMENTED_ERROR). |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 #ifdef HPUX | 763 #ifdef HPUX |
751 /* Pass 0 as the mode and value arguments to work around a bug. */ | 764 /* Pass 0 as the mode and value arguments to work around a bug. */ |
752 sem->sem = sem_open(osname, 0, 0, 0); | 765 sem->sem = sem_open(osname, 0, 0, 0); |
753 #else | 766 #else |
754 sem->sem = sem_open(osname, 0); | 767 sem->sem = sem_open(osname, 0); |
755 #endif | 768 #endif |
756 } | 769 } |
757 if ((sem_t *) -1 == sem->sem) | 770 if ((sem_t *) -1 == sem->sem) |
758 { | 771 { |
759 _PR_MD_MAP_DEFAULT_ERROR(errno); | 772 _PR_MD_MAP_DEFAULT_ERROR(errno); |
760 PR_DELETE(sem); | 773 PR_Free(sem); |
761 return NULL; | 774 return NULL; |
762 } | 775 } |
763 return sem; | 776 return sem; |
764 } | 777 } |
765 | 778 |
766 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem) | 779 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem) |
767 { | 780 { |
768 int rv; | 781 int rv; |
769 rv = sem_wait(sem->sem); | 782 rv = sem_wait(sem->sem); |
770 if (0 != rv) | 783 if (0 != rv) |
(...skipping 18 matching lines...) Expand all Loading... |
789 | 802 |
790 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem) | 803 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem) |
791 { | 804 { |
792 int rv; | 805 int rv; |
793 rv = sem_close(sem->sem); | 806 rv = sem_close(sem->sem); |
794 if (0 != rv) | 807 if (0 != rv) |
795 { | 808 { |
796 _PR_MD_MAP_DEFAULT_ERROR(errno); | 809 _PR_MD_MAP_DEFAULT_ERROR(errno); |
797 return PR_FAILURE; | 810 return PR_FAILURE; |
798 } | 811 } |
799 PR_DELETE(sem); | 812 PR_Free(sem); |
800 return PR_SUCCESS; | 813 return PR_SUCCESS; |
801 } | 814 } |
802 | 815 |
803 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name) | 816 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name) |
804 { | 817 { |
805 int rv; | 818 int rv; |
806 char osname[PR_IPC_NAME_SIZE]; | 819 char osname[PR_IPC_NAME_SIZE]; |
807 | 820 |
808 if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem) | 821 if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem) |
809 == PR_FAILURE) | 822 == PR_FAILURE) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 if (flags & PR_SEM_CREATE) | 913 if (flags & PR_SEM_CREATE) |
901 { | 914 { |
902 sem->semid = semget(key, 1, mode|IPC_CREAT|IPC_EXCL); | 915 sem->semid = semget(key, 1, mode|IPC_CREAT|IPC_EXCL); |
903 if (sem->semid >= 0) | 916 if (sem->semid >= 0) |
904 { | 917 { |
905 /* creator of a semaphore is responsible for initializing it */ | 918 /* creator of a semaphore is responsible for initializing it */ |
906 arg.val = 0; | 919 arg.val = 0; |
907 if (semctl(sem->semid, 0, SETVAL, arg) == -1) | 920 if (semctl(sem->semid, 0, SETVAL, arg) == -1) |
908 { | 921 { |
909 _PR_MD_MAP_DEFAULT_ERROR(errno); | 922 _PR_MD_MAP_DEFAULT_ERROR(errno); |
910 PR_DELETE(sem); | 923 PR_Free(sem); |
911 return NULL; | 924 return NULL; |
912 } | 925 } |
913 /* call semop to set sem_otime to nonzero */ | 926 /* call semop to set sem_otime to nonzero */ |
914 sop.sem_num = 0; | 927 sop.sem_num = 0; |
915 sop.sem_op = value; | 928 sop.sem_op = value; |
916 sop.sem_flg = 0; | 929 sop.sem_flg = 0; |
917 if (semop(sem->semid, &sop, 1) == -1) | 930 if (semop(sem->semid, &sop, 1) == -1) |
918 { | 931 { |
919 _PR_MD_MAP_DEFAULT_ERROR(errno); | 932 _PR_MD_MAP_DEFAULT_ERROR(errno); |
920 PR_DELETE(sem); | 933 PR_Free(sem); |
921 return NULL; | 934 return NULL; |
922 } | 935 } |
923 return sem; | 936 return sem; |
924 } | 937 } |
925 | 938 |
926 if (errno != EEXIST || flags & PR_SEM_EXCL) | 939 if (errno != EEXIST || flags & PR_SEM_EXCL) |
927 { | 940 { |
928 _PR_MD_MAP_DEFAULT_ERROR(errno); | 941 _PR_MD_MAP_DEFAULT_ERROR(errno); |
929 PR_DELETE(sem); | 942 PR_Free(sem); |
930 return NULL; | 943 return NULL; |
931 } | 944 } |
932 } | 945 } |
933 | 946 |
934 sem->semid = semget(key, 1, NSPR_SEM_MODE); | 947 sem->semid = semget(key, 1, NSPR_SEM_MODE); |
935 if (sem->semid == -1) | 948 if (sem->semid == -1) |
936 { | 949 { |
937 _PR_MD_MAP_DEFAULT_ERROR(errno); | 950 _PR_MD_MAP_DEFAULT_ERROR(errno); |
938 PR_DELETE(sem); | 951 PR_Free(sem); |
939 return NULL; | 952 return NULL; |
940 } | 953 } |
941 for (i = 0; i < MAX_TRIES; i++) | 954 for (i = 0; i < MAX_TRIES; i++) |
942 { | 955 { |
943 arg.buf = &seminfo; | 956 arg.buf = &seminfo; |
944 semctl(sem->semid, 0, IPC_STAT, arg); | 957 semctl(sem->semid, 0, IPC_STAT, arg); |
945 if (seminfo.sem_otime != 0) break; | 958 if (seminfo.sem_otime != 0) break; |
946 sleep(1); | 959 sleep(1); |
947 } | 960 } |
948 if (i == MAX_TRIES) | 961 if (i == MAX_TRIES) |
949 { | 962 { |
950 PR_SetError(PR_IO_TIMEOUT_ERROR, 0); | 963 PR_SetError(PR_IO_TIMEOUT_ERROR, 0); |
951 PR_DELETE(sem); | 964 PR_Free(sem); |
952 return NULL; | 965 return NULL; |
953 } | 966 } |
954 return sem; | 967 return sem; |
955 } | 968 } |
956 | 969 |
957 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem) | 970 PR_IMPLEMENT(PRStatus) PR_WaitSemaphore(PRSem *sem) |
958 { | 971 { |
959 struct sembuf sop; | 972 struct sembuf sop; |
960 | 973 |
961 sop.sem_num = 0; | 974 sop.sem_num = 0; |
(...skipping 17 matching lines...) Expand all Loading... |
979 if (semop(sem->semid, &sop, 1) == -1) | 992 if (semop(sem->semid, &sop, 1) == -1) |
980 { | 993 { |
981 _PR_MD_MAP_DEFAULT_ERROR(errno); | 994 _PR_MD_MAP_DEFAULT_ERROR(errno); |
982 return PR_FAILURE; | 995 return PR_FAILURE; |
983 } | 996 } |
984 return PR_SUCCESS; | 997 return PR_SUCCESS; |
985 } | 998 } |
986 | 999 |
987 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem) | 1000 PR_IMPLEMENT(PRStatus) PR_CloseSemaphore(PRSem *sem) |
988 { | 1001 { |
989 PR_DELETE(sem); | 1002 PR_Free(sem); |
990 return PR_SUCCESS; | 1003 return PR_SUCCESS; |
991 } | 1004 } |
992 | 1005 |
993 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name) | 1006 PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name) |
994 { | 1007 { |
995 key_t key; | 1008 key_t key; |
996 int semid; | 1009 int semid; |
997 /* On some systems (e.g., glibc 2.0) semctl requires a fourth argument */ | 1010 /* On some systems (e.g., glibc 2.0) semctl requires a fourth argument */ |
998 union semun unused; | 1011 union semun unused; |
999 char osname[PR_IPC_NAME_SIZE]; | 1012 char osname[PR_IPC_NAME_SIZE]; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 return cv; | 1118 return cv; |
1106 } /* PRP_NewNakedCondVar */ | 1119 } /* PRP_NewNakedCondVar */ |
1107 | 1120 |
1108 PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar) | 1121 PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar) |
1109 { | 1122 { |
1110 int rv; | 1123 int rv; |
1111 rv = pthread_cond_destroy(&cvar->cv); PR_ASSERT(0 == rv); | 1124 rv = pthread_cond_destroy(&cvar->cv); PR_ASSERT(0 == rv); |
1112 #if defined(DEBUG) | 1125 #if defined(DEBUG) |
1113 memset(cvar, 0xaf, sizeof(PRCondVar)); | 1126 memset(cvar, 0xaf, sizeof(PRCondVar)); |
1114 #endif | 1127 #endif |
1115 PR_DELETE(cvar); | 1128 PR_Free(cvar); |
1116 } /* PRP_DestroyNakedCondVar */ | 1129 } /* PRP_DestroyNakedCondVar */ |
1117 | 1130 |
1118 PR_IMPLEMENT(PRStatus) PRP_NakedWait( | 1131 PR_IMPLEMENT(PRStatus) PRP_NakedWait( |
1119 PRCondVar *cvar, PRLock *ml, PRIntervalTime timeout) | 1132 PRCondVar *cvar, PRLock *ml, PRIntervalTime timeout) |
1120 { | 1133 { |
1121 PRIntn rv; | 1134 PRIntn rv; |
1122 PR_ASSERT(cvar != NULL); | 1135 PR_ASSERT(cvar != NULL); |
1123 /* XXX do we really want to assert this in a naked wait? */ | 1136 /* XXX do we really want to assert this in a naked wait? */ |
1124 PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(ml->mutex)); | 1137 PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(ml->mutex)); |
1125 if (timeout == PR_INTERVAL_NO_TIMEOUT) | 1138 if (timeout == PR_INTERVAL_NO_TIMEOUT) |
(...skipping 22 matching lines...) Expand all Loading... |
1148 int rv; | 1161 int rv; |
1149 PR_ASSERT(cvar != NULL); | 1162 PR_ASSERT(cvar != NULL); |
1150 rv = pthread_cond_broadcast(&cvar->cv); | 1163 rv = pthread_cond_broadcast(&cvar->cv); |
1151 PR_ASSERT(0 == rv); | 1164 PR_ASSERT(0 == rv); |
1152 return PR_SUCCESS; | 1165 return PR_SUCCESS; |
1153 } /* PRP_NakedBroadcast */ | 1166 } /* PRP_NakedBroadcast */ |
1154 | 1167 |
1155 #endif /* defined(_PR_PTHREADS) */ | 1168 #endif /* defined(_PR_PTHREADS) */ |
1156 | 1169 |
1157 /* ptsynch.c */ | 1170 /* ptsynch.c */ |
OLD | NEW |