You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/20 20:05:29 UTC
svn commit: r806279 -
/commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c
Author: mturk
Date: Thu Aug 20 18:05:28 2009
New Revision: 806279
URL: http://svn.apache.org/viewvc?rev=806279&view=rev
Log:
Allow named mutexes
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c
Modified: commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c?rev=806279&r1=806278&r2=806279&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/darwin/pmutex.c Thu Aug 20 18:05:28 2009
@@ -66,8 +66,11 @@
}
if (m->filedes > 0)
- close(m->filedes);
- free(m->fname);
+ close(m->filedes);
+ if (m->fname) {
+ unlink(m->fname);
+ free(m->fname);
+ }
free(m);
return rc;
}
@@ -100,12 +103,11 @@
if (m->filedes < 0) {
rc = ACR_GET_OS_ERROR();
- goto cleanup;
+ goto finally;
}
m->locked = 0;
- unlink(m->fname);
-cleanup:
+finally:
if (rc) {
free(m->fname);
free(m);
@@ -120,7 +122,35 @@
ACR_DECLARE(int) ACR_ProcMutexAttach(JNIEnv *_E, const acr_pchar_t *fname)
{
- ACR_SET_OS_ERROR(ACR_ENOTIMPL);
+ int rc = 0;
+ acr_pmutex_t *m;
+
+ if (!fname) {
+ /* Cannot attach to unnamed mutex */
+ ACR_THROW_IO_IF_ERR(ACR_EINVAL);
+ return -1;
+ }
+ m = ACR_Calloc(_E, THROW_FMARK, sizeof(acr_pmutex_t));
+ if (!m)
+ return -1;
+ m->filedes = open(fname, O_WRONLY);
+ if (m->filedes < 0) {
+ rc = ACR_GET_OS_ERROR();
+ goto finally;
+ }
+ m->locked = 0;
+
+finally:
+ if (rc) {
+ free(m->fname);
+ free(m);
+ ACR_THROW_IO_IF_ERR(rc);
+ return -1;
+ }
+ else {
+ rc = acr_ioh_open(m, ACR_DT_MUTEX, 1, mutex_cleanup);
+ return rc;
+ }
return -1;
}