Changeset 2217 for pjproject/trunk/pjlib/src/pj/os_core_unix.c
- Timestamp:
- Aug 15, 2008 2:53:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_core_unix.c
r2159 r2217 89 89 struct pj_sem_t 90 90 { 91 sem_t 91 sem_t *sem; 92 92 char obj_name[PJ_MAX_OBJ_NAME]; 93 93 }; … … 1471 1471 PJ_ASSERT_RETURN(sem, PJ_ENOMEM); 1472 1472 1473 if (sem_init( &sem->sem, 0, initial) != 0) 1473 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 1474 /* MacOS X doesn't support anonymous semaphore */ 1475 { 1476 char sem_name[PJ_GUID_MAX_LENGTH+1]; 1477 pj_str_t nam; 1478 1479 /* We should use SEM_NAME_LEN, but this doesn't seem to be 1480 * declared anywhere? The value here is just from trial and error 1481 * to get the longest name supported. 1482 */ 1483 # define MAX_SEM_NAME_LEN 23 1484 1485 /* Create a unique name for the semaphore. */ 1486 if (PJ_GUID_STRING_LENGTH <= MAX_SEM_NAME_LEN) { 1487 nam.ptr = sem_name; 1488 pj_generate_unique_string(&nam); 1489 sem_name[nam.slen] = '\0'; 1490 } else { 1491 pj_create_random_string(sem_name, MAX_SEM_NAME_LEN); 1492 sem_name[MAX_SEM_NAME_LEN] = '\0'; 1493 } 1494 1495 /* Create semaphore */ 1496 sem->sem = sem_open(sem_name, O_CREAT|O_EXCL, S_IRUSR|S_IWUSR, 1497 initial); 1498 if (sem->sem == SEM_FAILED) 1499 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 1500 1501 /* And immediately release the name as we don't need it */ 1502 sem_unlink(sem_name); 1503 } 1504 #else 1505 sem->sem = PJ_POOL_ALLOC_T(pool, sem_t); 1506 if (sem_init( sem->sem, 0, initial) != 0) 1474 1507 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 1508 #endif 1475 1509 1476 1510 /* Set name. */ … … 1509 1543 pj_thread_this()->obj_name)); 1510 1544 1511 result = sem_wait( &sem->sem );1545 result = sem_wait( sem->sem ); 1512 1546 1513 1547 if (result == 0) { … … 1540 1574 PJ_ASSERT_RETURN(sem, PJ_EINVAL); 1541 1575 1542 result = sem_trywait( &sem->sem );1576 result = sem_trywait( sem->sem ); 1543 1577 1544 1578 if (result == 0) { … … 1565 1599 PJ_LOG(6, (sem->obj_name, "Semaphore released by thread %s", 1566 1600 pj_thread_this()->obj_name)); 1567 result = sem_post( &sem->sem );1601 result = sem_post( sem->sem ); 1568 1602 1569 1603 if (result == 0) … … 1590 1624 PJ_LOG(6, (sem->obj_name, "Semaphore destroyed by thread %s", 1591 1625 pj_thread_this()->obj_name)); 1592 result = sem_destroy( &sem->sem ); 1626 #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 1627 result = sem_close( sem->sem ); 1628 #else 1629 result = sem_destroy( sem->sem ); 1630 #endif 1593 1631 1594 1632 if (result == 0)
Note: See TracChangeset
for help on using the changeset viewer.