Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011 The LevelDB Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file. See the AUTHORS file for names of contributors.4//5// This file contains the specification, but not the implementations,6// of the types/operations/etc. that should be defined by a platform7// specific port_<platform>.h file. Use this file as a reference for8// how to port this package to a new platform.10#ifndef STORAGE_LEVELDB_PORT_PORT_EXAMPLE_H_11#define STORAGE_LEVELDB_PORT_PORT_EXAMPLE_H_13#include "port/thread_annotations.h"15namespace leveldb {16namespace port {18// TODO(jorlow): Many of these belong more in the environment class rather than19// here. We should try moving them and see if it affects perf.21// ------------------ Threading -------------------23// A Mutex represents an exclusive lock.24class LOCKABLE Mutex {25public:26Mutex();27~Mutex();29// Lock the mutex. Waits until other lockers have exited.30// Will deadlock if the mutex is already locked by this thread.31void Lock() EXCLUSIVE_LOCK_FUNCTION();33// Unlock the mutex.34// REQUIRES: This mutex was locked by this thread.35void Unlock() UNLOCK_FUNCTION();37// Optionally crash if this thread does not hold this mutex.38// The implementation must be fast, especially if NDEBUG is39// defined. The implementation is allowed to skip all checks.40void AssertHeld() ASSERT_EXCLUSIVE_LOCK();41};43class CondVar {44public:45explicit CondVar(Mutex* mu);46~CondVar();48// Atomically release *mu and block on this condition variable until49// either a call to SignalAll(), or a call to Signal() that picks50// this thread to wakeup.51// REQUIRES: this thread holds *mu52void Wait();54// If there are some threads waiting, wake up at least one of them.55void Signal();57// Wake up all waiting threads.58void SignallAll();59};61// ------------------ Compression -------------------63// Store the snappy compression of "input[0,input_length-1]" in *output.64// Returns false if snappy is not supported by this port.65bool Snappy_Compress(const char* input, size_t input_length,66std::string* output);68// If input[0,input_length-1] looks like a valid snappy compressed69// buffer, store the size of the uncompressed data in *result and70// return true. Else return false.71bool Snappy_GetUncompressedLength(const char* input, size_t length,72size_t* result);74// Attempt to snappy uncompress input[0,input_length-1] into *output.75// Returns true if successful, false if the input is invalid lightweight76// compressed data.77//78// REQUIRES: at least the first "n" bytes of output[] must be writable79// where "n" is the result of a successful call to80// Snappy_GetUncompressedLength.81bool Snappy_Uncompress(const char* input_data, size_t input_length,82char* output);84// ------------------ Miscellaneous -------------------86// If heap profiling is not supported, returns false.87// Else repeatedly calls (*func)(arg, data, n) and then returns true.88// The concatenation of all "data[0,n-1]" fragments is the heap profile.89bool GetHeapProfile(void (*func)(void*, const char*, int), void* arg);91// Extend the CRC to include the first n bytes of buf.92//93// Returns zero if the CRC cannot be extended using acceleration, else returns94// the newly extended CRC value (which may also be zero).95uint32_t AcceleratedCRC32C(uint32_t crc, const char* buf, size_t size);97} // namespace port98} // namespace leveldb100#endif // STORAGE_LEVELDB_PORT_PORT_EXAMPLE_H_
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.