< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page




1951 #else
1952 typedef sem_t os_semaphore_t;
1953 
1954   #define SEM_INIT(sem, value)    sem_init(&sem, 0, value)
1955   #define SEM_WAIT(sem)           sem_wait(&sem)
1956   #define SEM_POST(sem)           sem_post(&sem)
1957   #define SEM_DESTROY(sem)        sem_destroy(&sem)
1958 #endif
1959 
1960 #ifdef __APPLE__
1961 // OS X doesn't support unamed POSIX semaphores, so the implementation in os_posix.cpp can't be used.
1962 
1963 static const char* sem_init_strerror(kern_return_t value) {
1964   switch (value) {
1965     case KERN_INVALID_ARGUMENT:  return "Invalid argument";
1966     case KERN_RESOURCE_SHORTAGE: return "Resource shortage";
1967     default:                     return "Unknown";
1968   }
1969 }
1970 
1971 OSXSemaphore::OSXSemaphore(uint value) : _semaphore(0) {
1972   kern_return_t ret = SEM_INIT(_semaphore, value);
1973 
1974   guarantee(ret == KERN_SUCCESS, err_msg("Failed to create semaphore: %s", sem_init_strerror(ret)));
1975 }
1976 
1977 OSXSemaphore::~OSXSemaphore() {
1978   SEM_DESTROY(_semaphore);
1979 }
1980 
1981 void OSXSemaphore::signal(uint count) {
1982   for (uint i = 0; i < count; i++) {
1983     kern_return_t ret = SEM_POST(_semaphore);
1984 
1985     assert(ret == KERN_SUCCESS, "Failed to signal semaphore");
1986   }
1987 }
1988 
1989 void OSXSemaphore::wait() {
1990   kern_return_t ret;
1991   while ((ret = SEM_WAIT(_semaphore)) == KERN_ABORTED) {




1951 #else
1952 typedef sem_t os_semaphore_t;
1953 
1954   #define SEM_INIT(sem, value)    sem_init(&sem, 0, value)
1955   #define SEM_WAIT(sem)           sem_wait(&sem)
1956   #define SEM_POST(sem)           sem_post(&sem)
1957   #define SEM_DESTROY(sem)        sem_destroy(&sem)
1958 #endif
1959 
1960 #ifdef __APPLE__
1961 // OS X doesn't support unamed POSIX semaphores, so the implementation in os_posix.cpp can't be used.
1962 
1963 static const char* sem_init_strerror(kern_return_t value) {
1964   switch (value) {
1965     case KERN_INVALID_ARGUMENT:  return "Invalid argument";
1966     case KERN_RESOURCE_SHORTAGE: return "Resource shortage";
1967     default:                     return "Unknown";
1968   }
1969 }
1970 
1971 OSXSemaphore::OSXSemaphore(uint value) {
1972   kern_return_t ret = SEM_INIT(_semaphore, value);
1973 
1974   guarantee(ret == KERN_SUCCESS, err_msg("Failed to create semaphore: %s", sem_init_strerror(ret)));
1975 }
1976 
1977 OSXSemaphore::~OSXSemaphore() {
1978   SEM_DESTROY(_semaphore);
1979 }
1980 
1981 void OSXSemaphore::signal(uint count) {
1982   for (uint i = 0; i < count; i++) {
1983     kern_return_t ret = SEM_POST(_semaphore);
1984 
1985     assert(ret == KERN_SUCCESS, "Failed to signal semaphore");
1986   }
1987 }
1988 
1989 void OSXSemaphore::wait() {
1990   kern_return_t ret;
1991   while ((ret = SEM_WAIT(_semaphore)) == KERN_ABORTED) {


< prev index next >