From bbc71faf95a515f6e66ac12ed654d51a4d488782 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 12 Aug 2016 09:25:18 -0400 Subject: sync block: remove validate/invalidate api, fix lock_tries logic, tidy up. --- src/internal/ntapi.c | 5 +- src/internal/ntapi_fnapi.h | 5 +- src/sync/ntapi_tt_sync_block.c | 114 ++++++++++++++++------------------------- 3 files changed, 49 insertions(+), 75 deletions(-) (limited to 'src') 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 +#include #include #include -#include #include #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); -- cgit v1.2.3