summaryrefslogtreecommitdiffhomepage
path: root/src/sync
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-08-12 09:25:18 -0400
committermidipix <writeonce@midipix.org>2016-08-12 09:41:53 -0400
commitbbc71faf95a515f6e66ac12ed654d51a4d488782 (patch)
tree419657ecde29db764c7e2c9f633b086b315c8be6 /src/sync
parent563a1e17dcddd5b622d07d431a36e74b241993e1 (diff)
downloadntapi-bbc71faf95a515f6e66ac12ed654d51a4d488782.tar.bz2
ntapi-bbc71faf95a515f6e66ac12ed654d51a4d488782.tar.xz
sync block: remove validate/invalidate api, fix lock_tries logic, tidy up.
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/ntapi_tt_sync_block.c114
1 files changed, 45 insertions, 69 deletions
diff --git a/src/sync/ntapi_tt_sync_block.c b/src/sync/ntapi_tt_sync_block.c
index 0e2a9a4..e4e501a 100644
--- a/src/sync/ntapi_tt_sync_block.c
+++ b/src/sync/ntapi_tt_sync_block.c
@@ -5,9 +5,9 @@
/********************************************************/
#include <psxtypes/psxtypes.h>
+#include <ntapi/nt_atomic.h>
#include <ntapi/nt_object.h>
#include <ntapi/nt_sync.h>
-#include <ntapi/nt_atomic.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"
@@ -92,8 +92,8 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
return NT_STATUS_INVALID_HANDLE;
/* already owned? */
- tid = pe_get_current_thread_id();
- if (sync_block->tid == tid) return NT_STATUS_SUCCESS;
+ if ((tid = pe_get_current_thread_id()) == sync_block->tid)
+ return NT_STATUS_SUCCESS;
/* yield to server? */
if ((sync_block->flags & NT_SYNC_BLOCK_YIELD_TO_SERVER)
@@ -107,11 +107,10 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
/* wait */
status = __ntapi->zw_wait_for_multiple_objects(
- 2,
- hwait,
+ 2,hwait,
NT_WAIT_ANY,
NT_SYNC_NON_ALERTABLE,
- (nt_timeout *)0);
+ 0);
/* signal support */
if (sig_flag && *sig_flag)
@@ -119,17 +118,20 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
}
/* first try */
- lock = at_locked_cas_32(&sync_block->tid,0,tid);
- if (lock && !--lock_tries) return NT_STATUS_NOT_LOCKED;
+ lock = at_locked_cas_32(
+ &sync_block->tid,
+ 0,tid);
+
+ if (lock && (lock_tries == 1))
+ return NT_STATUS_NOT_LOCKED;
/* first-time contended case? */
if (lock && !sync_block->hwait) {
- status = __ntapi->tt_create_inheritable_event(
- &hwait[0],
- NT_NOTIFICATION_EVENT,
- NT_EVENT_NOT_SIGNALED);
-
- if (status) return status;
+ if ((status = __ntapi->tt_create_inheritable_event(
+ &hwait[0],
+ NT_NOTIFICATION_EVENT,
+ NT_EVENT_NOT_SIGNALED)))
+ return status;
lock = at_locked_cas(
(intptr_t *)&sync_block->hwait,
@@ -139,7 +141,9 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
__ntapi->zw_close(hwait);
/* try again without a wait */
- lock = at_locked_cas_32(&sync_block->tid,0,tid);
+ lock = at_locked_cas_32(
+ &sync_block->tid,
+ 0,tid);
}
/* contended case? */
@@ -162,14 +166,17 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
/* wait */
status = __ntapi->zw_wait_for_multiple_objects(
- 2,
- &sync_block->hwait,
+ 2,sync_block->hwait,
NT_WAIT_ANY,
NT_SYNC_NON_ALERTABLE,
&timeout);
/* check status */
- if ((status != NT_STATUS_TIMEOUT) && ((uint32_t)status >= NT_STATUS_WAIT_CAP))
+ if ((status >= NT_STATUS_WAIT_0) && (status < NT_STATUS_WAIT_CAP))
+ (void)0;
+ else if (status == NT_STATUS_TIMEOUT)
+ (void)0;
+ else
return status;
/* signal support */
@@ -177,11 +184,14 @@ int32_t __stdcall __ntapi_tt_sync_block_lock(
return NT_STATUS_ALERTED;
/* try again */
- lock = at_locked_cas_32(&sync_block->tid,0,tid);
+ lock = at_locked_cas_32(
+ &sync_block->tid,
+ 0,tid);
};
}
- if (lock) return NT_STATUS_NOT_LOCKED;
+ if (lock)
+ return NT_STATUS_NOT_LOCKED;
/* shared section support */
at_store_32(
@@ -201,7 +211,7 @@ int32_t __stdcall __ntapi_tt_sync_block_server_lock(
int32_t status;
/* validation */
- if (sync_block->invalid)
+ if (sync_block->invalid)
return NT_STATUS_INVALID_HANDLE;
else if (sync_block->srvtid != pe_get_current_thread_id())
@@ -210,8 +220,7 @@ int32_t __stdcall __ntapi_tt_sync_block_server_lock(
/* try once without yield request */
status = __ntapi_tt_sync_block_lock(
sync_block,
- 1,
- lock_wait,
+ 1,lock_wait,
sig_flag);
if (status == NT_STATUS_SUCCESS)
@@ -219,18 +228,15 @@ int32_t __stdcall __ntapi_tt_sync_block_server_lock(
/* hserver */
if (!sync_block->hserver) {
- status = __ntapi->tt_create_inheritable_event(
- &sync_block->hserver,
- NT_NOTIFICATION_EVENT,
- NT_EVENT_NOT_SIGNALED);
-
- if (status) return status;
+ if ((status = __ntapi->tt_create_inheritable_event(
+ &sync_block->hserver,
+ NT_NOTIFICATION_EVENT,
+ NT_EVENT_NOT_SIGNALED)))
+ return status;
} else {
- status = __ntapi->zw_reset_event(
- &sync_block->hserver,
- (int32_t *)0);
-
- if (status) return status;
+ if ((status = __ntapi->zw_reset_event(
+ &sync_block->hserver,0)))
+ return status;
}
/* yield request: set */
@@ -252,7 +258,7 @@ int32_t __stdcall __ntapi_tt_sync_block_server_lock(
__ntapi->zw_set_event(
sync_block->hserver,
- (int32_t *)0);
+ 0);
/* (locking not guaranteed) */
return status;
@@ -282,46 +288,16 @@ int32_t __stdcall __ntapi_tt_sync_block_unlock(
}
-void __stdcall __ntapi_tt_sync_block_validate(
- __in nt_sync_block * sync_block)
-{
- at_store_32(&sync_block->invalid,0);
-
- return;
-}
-
-
-int32_t __stdcall __ntapi_tt_sync_block_invalidate(
- __in nt_sync_block * sync_block)
-{
- int32_t invalid;
-
- if (!sync_block)
- return NT_STATUS_INVALID_PARAMETER;
-
- invalid = at_locked_cas_32(
- &sync_block->invalid,
- 0,
- 1);
-
- if (invalid)
- return NT_STATUS_INVALID_HANDLE;
-
- return NT_STATUS_SUCCESS;
-}
-
-
int32_t __stdcall __ntapi_tt_sync_block_discard(
__in nt_sync_block * sync_block)
{
- if (!sync_block)
- return NT_STATUS_INVALID_PARAMETER;
-
if (sync_block->hwait)
- __ntapi->zw_close(sync_block->hwait);
+ __ntapi->zw_close(
+ sync_block->hwait);
if (sync_block->hserver)
- __ntapi->zw_close(sync_block->hserver);
+ __ntapi->zw_close(
+ sync_block->hserver);
__sync_block_memset(
sync_block,-1);