/* Unlock a mutex. A return value of 0 indicates success */ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp) { TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id())); #ifdef TSRM_WIN32 LeaveCriticalSection(mutexp); return 0; #elif defined(GNUPTH) if (pth_mutex_release(mutexp)) { return 0; } return -1; #elif defined(PTHREADS) return pthread_mutex_unlock(mutexp); #elif defined(NSAPI) crit_exit(mutexp); return 0; #elif defined(PI3WEB) return PISync_unlock(mutexp); #elif defined(TSRM_ST) return st_mutex_unlock(mutexp); #elif defined(BETHREADS) if (atomic_add(&mutexp->ben, -1) != 1) return release_sem(mutexp->sem); return 0; #endif }
CAMLprim value caml_mutex_unlock(value wrapper) /* ML */ { st_mutex mut = Mutex_val(wrapper); st_retcode retcode; /* PR#4351: no need to release and reacquire master lock */ retcode = st_mutex_unlock(mut); st_check_error(retcode, "Mutex.unlock"); return Val_unit; }
void task4(void* arg) { for (long i = 0; i < 100000; ++i) { int rc = 0; if ((rc = st_mutex_lock(test4_mutex)) != 0) { std::cout << "st_mutex_lock " << rc << " " << strerror(rc) << std::endl; exit(1); } if ((rc = st_mutex_unlock(test4_mutex)) != 0) { std::cout << "st_mutex_unlock " << rc << " " << strerror(rc) << std::endl; exit(1); } } }
/* Unlock a mutex. A return value of 0 indicates success */ TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp) {/*{{{*/ TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id())); #ifdef TSRM_WIN32 LeaveCriticalSection(mutexp); return 0; #elif defined(GNUPTH) if (pth_mutex_release(mutexp)) { return 0; } return -1; #elif defined(PTHREADS) return pthread_mutex_unlock(mutexp); #elif defined(TSRM_ST) return st_mutex_unlock(mutexp); #endif }/*}}}*/
void task15(void* arg) { st_netfd_t rfd = st_open("/Users/vss/projects/1.gz", O_RDONLY, S_IRUSR); st_netfd_t wfd = st_open("/Users/vss/projects/tmp.gz", O_WRONLY, S_IWUSR); for (long w = 0; w < 3; ++w) { char buffer[32096]; const char str[] = "Of course, take it!"; char response[1024 + sizeof(str)]; int rc = 0; int c = 0; while (c < sizeof(buffer)) { if ((rc = st_read(rfd, buffer + c, std::min<int>(4, sizeof(buffer) - c), -1)) <= 0) { std::cout << "st_read " << rc << " " << strerror(rc) << std::endl; exit(1); } c += rc; } if ((rc = st_mutex_lock(test4_mutex)) != 0) { std::cout << "st_mutex_lock " << rc << " " << strerror(rc) << std::endl; exit(1); } for (int i = 0; i < sizeof(response); i += sizeof(str)) { memcpy(response + i, str, sizeof(str)); } if ((rc = st_mutex_unlock(test4_mutex)) != 0) { std::cout << "st_mutex_unlock " << rc << " " << strerror(rc) << std::endl; exit(1); } if ((rc = st_write(wfd, response, sizeof(response), -1)) <= 0) { std::cout << "st_write " << rc << " " << strerror(rc) << std::endl; exit(1); } } st_netfd_close(rfd); st_netfd_close(wfd); }
static void caml_io_mutex_unlock(struct channel *chan) { st_mutex_unlock(chan->mutex); st_tls_set(last_channel_locked_key, NULL); }