Line data Source code
1 : #include "fd_capture_ctx.h" 2 : 3 : #include <time.h> 4 : 5 : void * 6 0 : fd_capture_ctx_new( void * mem ) { 7 0 : if( FD_UNLIKELY( !mem ) ) { 8 0 : FD_LOG_WARNING(( "NULL mem" )); 9 0 : return NULL; 10 0 : } 11 : 12 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)mem, FD_CAPTURE_CTX_ALIGN ) ) ) { 13 0 : FD_LOG_WARNING(( "misaligned mem" )); 14 0 : return NULL; 15 0 : } 16 : 17 0 : fd_memset(mem, 0, FD_CAPTURE_CTX_FOOTPRINT); 18 : 19 : /* TODO: use layout macros */ 20 0 : fd_capture_ctx_t * self = (fd_capture_ctx_t *) mem; 21 0 : self->capture = (fd_solcap_writer_t *)((uchar *)mem + sizeof(fd_capture_ctx_t)); 22 0 : fd_solcap_writer_new( self->capture ); 23 : 24 0 : self->account_updates_buffer = (uchar *)mem + sizeof(fd_capture_ctx_t) + fd_solcap_writer_footprint(); 25 0 : self->account_updates_buffer_ptr = self->account_updates_buffer; 26 0 : self->account_updates_len = 0UL; 27 : 28 0 : FD_COMPILER_MFENCE(); 29 0 : self->magic = FD_CAPTURE_CTX_MAGIC; 30 0 : FD_COMPILER_MFENCE(); 31 : 32 0 : return mem; 33 0 : } 34 : 35 : fd_capture_ctx_t * 36 0 : fd_capture_ctx_join( void * mem ) { 37 0 : if( FD_UNLIKELY( !mem ) ) { 38 0 : FD_LOG_WARNING(( "NULL block" )); 39 0 : return NULL; 40 0 : } 41 : 42 0 : fd_capture_ctx_t * ctx = (fd_capture_ctx_t *) mem; 43 : 44 0 : if( FD_UNLIKELY( ctx->magic!=FD_CAPTURE_CTX_MAGIC ) ) { 45 0 : FD_LOG_WARNING(( "bad magic" )); 46 0 : return NULL; 47 0 : } 48 : 49 0 : return ctx; 50 0 : } 51 : 52 : void * 53 0 : fd_capture_ctx_leave( fd_capture_ctx_t * ctx) { 54 0 : if( FD_UNLIKELY( !ctx ) ) { 55 0 : FD_LOG_WARNING(( "NULL block" )); 56 0 : return NULL; 57 0 : } 58 : 59 0 : if( FD_UNLIKELY( ctx->magic!=FD_CAPTURE_CTX_MAGIC ) ) { 60 0 : FD_LOG_WARNING(( "bad magic" )); 61 0 : return NULL; 62 0 : } 63 : 64 0 : return (void *) ctx; 65 0 : } 66 : 67 : void * 68 0 : fd_capture_ctx_delete( void * mem ) { 69 0 : if( FD_UNLIKELY( !mem ) ) { 70 0 : FD_LOG_WARNING(( "NULL mem" )); 71 0 : return NULL; 72 0 : } 73 : 74 0 : if( FD_UNLIKELY( !fd_ulong_is_aligned( (ulong)mem, FD_CAPTURE_CTX_ALIGN) ) ) { 75 0 : FD_LOG_WARNING(( "misaligned mem" )); 76 0 : return NULL; 77 0 : } 78 : 79 0 : fd_capture_ctx_t * hdr = (fd_capture_ctx_t *)mem; 80 0 : if( FD_UNLIKELY( hdr->magic!=FD_CAPTURE_CTX_MAGIC ) ) { 81 0 : FD_LOG_WARNING(( "bad magic" )); 82 0 : return NULL; 83 0 : } 84 : 85 0 : if( FD_UNLIKELY( fd_solcap_writer_delete( hdr->capture ) == NULL ) ) { 86 0 : FD_LOG_WARNING(( "failed deleting capture" )); 87 0 : return NULL; 88 0 : } 89 : 90 0 : FD_COMPILER_MFENCE(); 91 0 : FD_VOLATILE( hdr->magic ) = 0UL; 92 0 : FD_COMPILER_MFENCE(); 93 : 94 0 : return mem; 95 0 : } 96 : 97 : #include "../../fd_rwlock.h" 98 : static fd_rwlock_t txn_status_lock[ 1 ] = {0}; 99 : 100 : void 101 0 : fd_capture_ctx_txn_status_start_read( void ) { 102 0 : fd_rwlock_read( txn_status_lock ); 103 0 : } 104 : 105 : void 106 0 : fd_capture_ctx_txn_status_end_read( void ) { 107 0 : fd_rwlock_unread( txn_status_lock ); 108 0 : } 109 : 110 : void 111 0 : fd_capture_ctx_txn_status_start_write( void ) { 112 0 : fd_rwlock_write( txn_status_lock ); 113 0 : } 114 : 115 : void 116 0 : fd_capture_ctx_txn_status_end_write( void ) { 117 0 : fd_rwlock_unwrite( txn_status_lock ); 118 0 : }