diff options
author | midipix <writeonce@midipix.org> | 2016-08-12 09:25:18 -0400 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-08-12 09:41:53 -0400 |
commit | bbc71faf95a515f6e66ac12ed654d51a4d488782 (patch) | |
tree | 419657ecde29db764c7e2c9f633b086b315c8be6 | |
parent | 563a1e17dcddd5b622d07d431a36e74b241993e1 (diff) | |
download | ntapi-bbc71faf95a515f6e66ac12ed654d51a4d488782.tar.bz2 ntapi-bbc71faf95a515f6e66ac12ed654d51a4d488782.tar.xz |
sync block: remove validate/invalidate api, fix lock_tries logic, tidy up.
-rw-r--r-- | include/ntapi/nt_sync.h | 24 | ||||
-rw-r--r-- | include/ntapi/ntapi.h | 5 | ||||
-rw-r--r-- | src/internal/ntapi.c | 5 | ||||
-rw-r--r-- | src/internal/ntapi_fnapi.h | 5 | ||||
-rw-r--r-- | src/sync/ntapi_tt_sync_block.c | 114 |
5 files changed, 59 insertions, 94 deletions
diff --git a/include/ntapi/nt_sync.h b/include/ntapi/nt_sync.h index 99508dd..38d304b 100644 --- a/include/ntapi/nt_sync.h +++ b/include/ntapi/nt_sync.h @@ -393,14 +393,11 @@ typedef void __stdcall ntapi_tt_sync_block_init( __in void * hsignal __optional); -typedef int32_t __stdcall ntapi_tt_sync_block_lock( - __in nt_sync_block * sync_block, - __in int32_t lock_tries __optional, - __in int64_t lock_wait __optional, - __in uint32_t * sig_flag __optional); +typedef int32_t __stdcall ntapi_tt_sync_block_discard( + __in nt_sync_block * sync_block); -typedef int32_t __stdcall ntapi_tt_sync_block_server_lock( +typedef int32_t __stdcall ntapi_tt_sync_block_lock( __in nt_sync_block * sync_block, __in int32_t lock_tries __optional, __in int64_t lock_wait __optional, @@ -411,16 +408,11 @@ typedef int32_t __stdcall ntapi_tt_sync_block_unlock( __in nt_sync_block * sync_block); -typedef void __stdcall ntapi_tt_sync_block_validate( - __in nt_sync_block * sync_block); - - -typedef int32_t __stdcall ntapi_tt_sync_block_invalidate( - __in nt_sync_block * sync_block); - - -typedef int32_t __stdcall ntapi_tt_sync_block_discard( - __in nt_sync_block * sync_block); +typedef int32_t __stdcall ntapi_tt_sync_block_server_lock( + __in nt_sync_block * sync_block, + __in int32_t lock_tries __optional, + __in int64_t lock_wait __optional, + __in uint32_t * sig_flag __optional); typedef int32_t __stdcall ntapi_tt_wait_for_dummy_event(void); diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h index f330283..0af598a 100644 --- a/include/ntapi/ntapi.h +++ b/include/ntapi/ntapi.h @@ -466,11 +466,10 @@ typedef struct _ntapi_vtbl { ntapi_tt_create_inheritable_event * tt_create_inheritable_event; ntapi_tt_create_private_event * tt_create_private_event; ntapi_tt_sync_block_init * tt_sync_block_init; + ntapi_tt_sync_block_discard * tt_sync_block_discard; ntapi_tt_sync_block_lock * tt_sync_block_lock; - ntapi_tt_sync_block_server_lock * tt_sync_block_server_lock; ntapi_tt_sync_block_unlock * tt_sync_block_unlock; - ntapi_tt_sync_block_invalidate * tt_sync_block_invalidate; - ntapi_tt_sync_block_discard * tt_sync_block_discard; + ntapi_tt_sync_block_server_lock * tt_sync_block_server_lock; ntapi_tt_wait_for_dummy_event * tt_wait_for_dummy_event; /* nt_port.h */ diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c index cf04ddc..7080089 100644 --- a/src/internal/ntapi.c +++ b/src/internal/ntapi.c @@ -231,11 +231,10 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl) __ntapi->tt_create_private_event = __ntapi_tt_create_private_event; __ntapi->tt_wait_for_dummy_event = __ntapi_tt_wait_for_dummy_event; __ntapi->tt_sync_block_init = __ntapi_tt_sync_block_init; + __ntapi->tt_sync_block_discard = __ntapi_tt_sync_block_discard; __ntapi->tt_sync_block_lock = __ntapi_tt_sync_block_lock; - __ntapi->tt_sync_block_server_lock = __ntapi_tt_sync_block_server_lock; __ntapi->tt_sync_block_unlock = __ntapi_tt_sync_block_unlock; - __ntapi->tt_sync_block_invalidate = __ntapi_tt_sync_block_invalidate; - __ntapi->tt_sync_block_discard = __ntapi_tt_sync_block_discard; + __ntapi->tt_sync_block_server_lock = __ntapi_tt_sync_block_server_lock; /* nt_port.h */ __ntapi->csr_port_handle = __ntapi_csr_port_handle; diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h index 6a087f2..9db0560 100644 --- a/src/internal/ntapi_fnapi.h +++ b/src/internal/ntapi_fnapi.h @@ -119,11 +119,10 @@ ntapi_tt_create_inheritable_event __ntapi_tt_create_inheritable_event; ntapi_tt_create_private_event __ntapi_tt_create_private_event; ntapi_tt_wait_for_dummy_event __ntapi_tt_wait_for_dummy_event; ntapi_tt_sync_block_init __ntapi_tt_sync_block_init; +ntapi_tt_sync_block_discard __ntapi_tt_sync_block_discard; ntapi_tt_sync_block_lock __ntapi_tt_sync_block_lock; -ntapi_tt_sync_block_server_lock __ntapi_tt_sync_block_server_lock; ntapi_tt_sync_block_unlock __ntapi_tt_sync_block_unlock; -ntapi_tt_sync_block_invalidate __ntapi_tt_sync_block_invalidate; -ntapi_tt_sync_block_discard __ntapi_tt_sync_block_discard; +ntapi_tt_sync_block_server_lock __ntapi_tt_sync_block_server_lock; /* nt_port.h */ ntapi_tt_port_guid_from_type __ntapi_tt_port_guid_from_type; 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); |