From 7e7f82793b14739f6727c012f4ee10858287f9bc Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 17 Sep 2016 14:22:23 +0200 Subject: [PATCH] Review naming --- kernel/include/conc/int_lock.hpp | 8 ++++---- kernel/include/conc/mutex.hpp | 14 +++++++------- kernel/include/conc/semaphore.hpp | 16 ++++++++-------- kernel/include/conc/spinlock.hpp | 10 +++++----- kernel/include/net/network.hpp | 2 +- kernel/src/conc/condition_variable.cpp | 12 ++++++------ kernel/src/drivers/ata.cpp | 8 ++++---- kernel/src/drivers/loopback.cpp | 2 +- kernel/src/drivers/rtl8139.cpp | 6 +++--- kernel/src/fs/fat32.cpp | 4 ++-- kernel/src/net/network.cpp | 4 ++-- kernel/src/thor_acpi.cpp | 10 +++++----- tstl/include/array.hpp | 6 +++--- tstl/include/lock_guard.hpp | 4 ++-- tstl/include/unique_ptr.hpp | 12 ++++++------ 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/kernel/include/conc/int_lock.hpp b/kernel/include/conc/int_lock.hpp index 4a3a6272..d6f8c1c3 100644 --- a/kernel/include/conc/int_lock.hpp +++ b/kernel/include/conc/int_lock.hpp @@ -19,14 +19,14 @@ struct int_lock { /*! * \brief Acquire the lock. This will disable preemption. */ - void acquire(){ + void lock(){ arch::disable_hwint(rflags); } /*! * \brief Release the lock. This will enable preemption. */ - void release(){ + void unlock(){ arch::enable_hwint(rflags); } @@ -45,14 +45,14 @@ struct direct_int_lock { * \brief Construct a new direct_int_lock and acquire the lock. */ direct_int_lock(){ - lock.acquire(); + lock.lock(); } /*! * \brief Destruct a direct_int_lock and release the lock. */ ~direct_int_lock(){ - lock.release(); + lock.unlock(); } private: diff --git a/kernel/include/conc/mutex.hpp b/kernel/include/conc/mutex.hpp index cc2b5abd..750383c7 100644 --- a/kernel/include/conc/mutex.hpp +++ b/kernel/include/conc/mutex.hpp @@ -38,19 +38,19 @@ struct mutex { /*! * \brief Acquire the lock */ - void acquire(){ - lock.acquire(); + void lock(){ + value_lock.lock(); if(value > 0){ value = 0; - lock.release(); + value_lock.unlock(); } else { auto pid = scheduler::get_pid(); queue.push(pid); scheduler::block_process_light(pid); - lock.release(); + value_lock.unlock(); scheduler::reschedule(); } } @@ -58,8 +58,8 @@ struct mutex { /*! * \brief Acquire the lock */ - void release(){ - std::lock_guard l(lock); + void unlock(){ + std::lock_guard l(value_lock); if(queue.empty()){ value = 1; @@ -73,7 +73,7 @@ struct mutex { } private: - mutable spinlock lock; ///< The spin protecting the value + mutable spinlock value_lock; ///< The spin protecting the value volatile size_t value; ///< The value of the mutex circular_buffer queue; ///< The sleep queue }; diff --git a/kernel/include/conc/semaphore.hpp b/kernel/include/conc/semaphore.hpp index aea23aac..bbcdc2eb 100644 --- a/kernel/include/conc/semaphore.hpp +++ b/kernel/include/conc/semaphore.hpp @@ -34,18 +34,18 @@ struct semaphore { * This will effectively decrease the current counter by 1 once the critical * section is entered. */ - void acquire(){ - lock.acquire(); + void lock(){ + value_lock.lock(); if(value > 0){ --value; - lock.release(); + value_lock.unlock(); } else { auto pid = scheduler::get_pid(); queue.push(pid); scheduler::block_process_light(pid); - lock.release(); + value_lock.unlock(); scheduler::reschedule(); } } @@ -56,8 +56,8 @@ struct semaphore { * This will effectively increase the current counter by 1 once the critical * section is left. */ - void release(){ - std::lock_guard l(lock); + void unlock(){ + std::lock_guard l(value_lock); if(queue.empty()){ ++value; @@ -78,7 +78,7 @@ struct semaphore { * section is left. */ void release(size_t n){ - std::lock_guard l(lock); + std::lock_guard l(value_lock); if(queue.empty()){ value += n; @@ -96,7 +96,7 @@ struct semaphore { } private: - mutable spinlock lock; ///< The spin lock protecting the counter + mutable spinlock value_lock; ///< The spin lock protecting the counter volatile size_t value; ///< The value of the counter circular_buffer queue; ///< The sleep queue }; diff --git a/kernel/include/conc/spinlock.hpp b/kernel/include/conc/spinlock.hpp index da7c1733..e2c87fc8 100644 --- a/kernel/include/conc/spinlock.hpp +++ b/kernel/include/conc/spinlock.hpp @@ -19,8 +19,8 @@ struct spinlock { * * This will wait indefinitely. */ - void acquire(){ - while(!__sync_bool_compare_and_swap(&lock, 0, 1)); + void lock(){ + while(!__sync_bool_compare_and_swap(&value, 0, 1)); __sync_synchronize(); //TODO The last synchronize is probably not necessary } @@ -28,13 +28,13 @@ struct spinlock { /*! * \brief Release the lock */ - void release(){ + void unlock(){ __sync_synchronize(); - lock = 0; + value = 0; } private: - volatile size_t lock = 0; ///< The value of the lock + volatile size_t value = 0; ///< The value of the lock }; #endif diff --git a/kernel/include/net/network.hpp b/kernel/include/net/network.hpp index 0f9aa293..ac9e127a 100644 --- a/kernel/include/net/network.hpp +++ b/kernel/include/net/network.hpp @@ -52,7 +52,7 @@ struct interface_descriptor { void send(ethernet::packet& p){ std::lock_guard l(tx_lock); tx_queue.push(p); - tx_sem.release(); + tx_sem.unlock(); } bool is_loopback() const { diff --git a/kernel/src/conc/condition_variable.cpp b/kernel/src/conc/condition_variable.cpp index 13e87610..9e0ccdd0 100644 --- a/kernel/src/conc/condition_variable.cpp +++ b/kernel/src/conc/condition_variable.cpp @@ -70,7 +70,7 @@ void condition_variable::wake_up_all() { } void condition_variable::sleep() { - lock.acquire(); + lock.lock(); //Get the current process information auto pid = scheduler::get_pid(); @@ -85,7 +85,7 @@ void condition_variable::sleep() { //This process will sleep scheduler::block_process_light(pid); - lock.release(); + lock.unlock(); scheduler::reschedule(); } @@ -95,7 +95,7 @@ bool condition_variable::sleep(size_t ms) { return false; } - lock.acquire(); + lock.lock(); //Get the current process information auto pid = scheduler::get_pid(); @@ -110,12 +110,12 @@ bool condition_variable::sleep(size_t ms) { //This process will sleep scheduler::block_process_timeout_light(pid, ms); - lock.release(); + lock.unlock(); scheduler::reschedule(); // At this point we need the lock again to check the queue - lock.acquire(); + lock.lock(); bool obtained = true; @@ -137,7 +137,7 @@ bool condition_variable::sleep(size_t ms) { } // Final release of the lock - lock.release(); + lock.unlock(); return obtained; } diff --git a/kernel/src/drivers/ata.cpp b/kernel/src/drivers/ata.cpp index f845cdf2..423e97b0 100644 --- a/kernel/src/drivers/ata.cpp +++ b/kernel/src/drivers/ata.cpp @@ -40,7 +40,7 @@ volatile bool secondary_invoked = false; void primary_controller_handler(interrupt::syscall_regs*, void*){ if(scheduler::is_started()){ - primary_lock.release(); + primary_lock.unlock(); } else { primary_invoked = true; } @@ -48,7 +48,7 @@ void primary_controller_handler(interrupt::syscall_regs*, void*){ void secondary_controller_handler(interrupt::syscall_regs*, void*){ if(scheduler::is_started()){ - secondary_lock.release(); + secondary_lock.unlock(); } else { secondary_invoked = true; } @@ -56,7 +56,7 @@ void secondary_controller_handler(interrupt::syscall_regs*, void*){ void ata_wait_irq_primary(){ if(scheduler::is_started()){ - primary_lock.acquire(); + primary_lock.lock(); } else { while(!primary_invoked){ asm volatile ("nop"); @@ -72,7 +72,7 @@ void ata_wait_irq_primary(){ void ata_wait_irq_secondary(){ if(scheduler::is_started()){ - secondary_lock.acquire(); + secondary_lock.lock(); } else { while(!secondary_invoked){ asm volatile ("nop"); diff --git a/kernel/src/drivers/loopback.cpp b/kernel/src/drivers/loopback.cpp index 6b00bda8..3e279454 100644 --- a/kernel/src/drivers/loopback.cpp +++ b/kernel/src/drivers/loopback.cpp @@ -30,7 +30,7 @@ void send_packet(network::interface_descriptor& interface, network::ethernet::pa std::copy_n(packet.payload, packet.payload_size, packet_buffer); interface.rx_queue.emplace_push(packet_buffer, packet.payload_size); - interface.rx_sem.release(); + interface.rx_sem.unlock(); logging::logf(logging::log_level::TRACE, "loopback: Packet transmitted correctly\n"); } diff --git a/kernel/src/drivers/rtl8139.cpp b/kernel/src/drivers/rtl8139.cpp index c652f875..7e6e3a3f 100644 --- a/kernel/src/drivers/rtl8139.cpp +++ b/kernel/src/drivers/rtl8139.cpp @@ -132,7 +132,7 @@ void packet_handler(interrupt::syscall_regs*, void* data){ direct_int_lock lock; interface.rx_queue.push(packet); - interface.rx_sem.release(); + interface.rx_sem.unlock(); } cur_rx = (cur_rx + packet_length + 4 + 3) & ~3; //align on 4 bytes @@ -198,7 +198,7 @@ void send_packet(network::interface_descriptor& interface, network::ethernet::pa direct_int_lock lock; interface.rx_queue.emplace_push(packet_buffer, packet.payload_size); - interface.rx_sem.release(); + interface.rx_sem.unlock(); logging::logf(logging::log_level::TRACE, "rtl8139: Packet to self transmitted correctly\n"); @@ -209,7 +209,7 @@ void send_packet(network::interface_descriptor& interface, network::ethernet::pa auto iobase = desc.iobase; // Wait for a free entry in the tx buffers - desc.tx_sem.acquire(); + desc.tx_sem.lock(); // Claim an entry in the tx buffers auto entry = __sync_fetch_and_add(&desc.cur_tx, 1) % tx_buffers; diff --git a/kernel/src/fs/fat32.cpp b/kernel/src/fs/fat32.cpp index d5cda591..b0060128 100644 --- a/kernel/src/fs/fat32.cpp +++ b/kernel/src/fs/fat32.cpp @@ -186,7 +186,7 @@ void fat32::fat32_file_system::init(){ std::unique_ptr fat_bs_tmp(new fat_bs_t()); if(read_sectors(0, 1, fat_bs_tmp.get())){ - fat_bs = fat_bs_tmp.release(); + fat_bs = fat_bs_tmp.unlock(); //TODO fat_bs->signature should be 0xAA55 //TODO fat_bs->file_system_type should be FAT32 @@ -199,7 +199,7 @@ void fat32::fat32_file_system::init(){ std::unique_ptr fat_is_tmp(new fat_is_t()); if(read_sectors(fs_information_sector, 1, fat_is_tmp.get())){ - fat_is = fat_is_tmp.release(); + fat_is = fat_is_tmp.unlock(); //TODO fat_is->signature_start should be 0x52 0x52 0x61 0x41 //TODO fat_is->signature_middle should be 0x72 0x72 0x41 0x61 diff --git a/kernel/src/net/network.cpp b/kernel/src/net/network.cpp index 37b0e8db..f14eac0b 100644 --- a/kernel/src/net/network.cpp +++ b/kernel/src/net/network.cpp @@ -45,7 +45,7 @@ void rx_thread(void* data){ logging::logf(logging::log_level::TRACE, "network: RX Thread for interface %u started (pid:%u)\n", interface.id, pid); while(true){ - interface.rx_sem.acquire(); + interface.rx_sem.lock(); auto packet = interface.rx_queue.pop(); network::ethernet::decode(interface, packet); @@ -63,7 +63,7 @@ void tx_thread(void* data){ logging::logf(logging::log_level::TRACE, "network: TX Thread for interface %u started (pid:%u)\n", interface.id, pid); while(true){ - interface.tx_sem.acquire(); + interface.tx_sem.lock(); auto packet = interface.tx_queue.pop(); interface.hw_send(interface, packet); diff --git a/kernel/src/thor_acpi.cpp b/kernel/src/thor_acpi.cpp index e3d7c633..4002fdc2 100644 --- a/kernel/src/thor_acpi.cpp +++ b/kernel/src/thor_acpi.cpp @@ -306,7 +306,7 @@ void AcpiOsDeleteMutex(ACPI_MUTEX handle){ ACPI_STATUS AcpiOsAcquireMutex(ACPI_MUTEX handle, UINT16 Timeout){ auto* lock = static_cast*>(handle); - lock->acquire(); + lock->lock(); return AE_OK; } @@ -317,7 +317,7 @@ ACPI_STATUS AcpiOsAcquireMutex(ACPI_MUTEX handle, UINT16 Timeout){ void AcpiOsReleaseMutex(ACPI_MUTEX handle){ auto* lock = static_cast*>(handle); - lock->release(); + lock->unlock(); } #endif @@ -353,7 +353,7 @@ ACPI_STATUS AcpiOsWaitSemaphore(ACPI_SEMAPHORE handle, UINT32 units, UINT16 /*ti auto* lock = static_cast(handle); for(size_t i = 0; i < units; ++i){ - lock->acquire(); + lock->lock(); } return AE_OK; @@ -396,7 +396,7 @@ void AcpiOsDeleteLock(ACPI_HANDLE handle){ ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK handle){ auto* lock = static_cast(handle); - lock->acquire(); + lock->lock(); return 0; } @@ -407,7 +407,7 @@ ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK handle){ void AcpiOsReleaseLock(ACPI_SPINLOCK handle, ACPI_CPU_FLAGS /*flags*/){ auto* lock = static_cast(handle); - lock->release(); + lock->unlock(); } // Input / Output diff --git a/tstl/include/array.hpp b/tstl/include/array.hpp index b2136c90..9419a21a 100644 --- a/tstl/include/array.hpp +++ b/tstl/include/array.hpp @@ -77,13 +77,13 @@ public: array = new T[s]; } - unique_heap_array(unique_heap_array&& u) : array(u.release()), _size(u._size) { + unique_heap_array(unique_heap_array&& u) : array(u.unlock()), _size(u._size) { u._size = 0; } unique_heap_array& operator=(unique_heap_array&& u){ _size = u._size; - reset(u.release()); + reset(u.unlock()); u._size = 0; return *this; } @@ -113,7 +113,7 @@ public: return array; } - pointer_type release(){ + pointer_type unlock(){ pointer_type p = array; array = nullptr; return p; diff --git a/tstl/include/lock_guard.hpp b/tstl/include/lock_guard.hpp index 7f0033b1..c5de8a7e 100644 --- a/tstl/include/lock_guard.hpp +++ b/tstl/include/lock_guard.hpp @@ -15,7 +15,7 @@ struct lock_guard { Lock& lock; explicit lock_guard(Lock& l) : lock(l) { - lock.acquire(); + lock.lock(); } lock_guard(const lock_guard&) = delete; @@ -25,7 +25,7 @@ struct lock_guard { lock_guard& operator=(const lock_guard&&) = delete; ~lock_guard(){ - lock.release(); + lock.unlock(); } }; diff --git a/tstl/include/unique_ptr.hpp b/tstl/include/unique_ptr.hpp index 4d9a8a97..2282aac3 100644 --- a/tstl/include/unique_ptr.hpp +++ b/tstl/include/unique_ptr.hpp @@ -56,9 +56,9 @@ public: explicit unique_ptr(pointer_type p) : _data(make_tuple(p, deleter_type())) {} - unique_ptr(unique_ptr&& u) : _data(make_tuple(u.release(), u.get_deleter())) {} + unique_ptr(unique_ptr&& u) : _data(make_tuple(u.unlock(), u.get_deleter())) {} unique_ptr& operator=(unique_ptr&& u){ - reset(u.release()); + reset(u.unlock()); get_deleter() = std::forward(u.get_deleter()); return *this; } @@ -102,7 +102,7 @@ public: return get() == pointer_type() ? false : true; } - pointer_type release(){ + pointer_type unlock(){ pointer_type p = get(); std::get<0>(_data) = pointer_type(); return p; @@ -136,9 +136,9 @@ public: explicit unique_ptr(pointer_type p) : _data(make_tuple(p, deleter_type())) {} - unique_ptr(unique_ptr&& u) : _data(make_tuple(u.release(), u.get_deleter())) {} + unique_ptr(unique_ptr&& u) : _data(make_tuple(u.unlock(), u.get_deleter())) {} unique_ptr& operator=(unique_ptr&& u){ - reset(u.release()); + reset(u.unlock()); get_deleter() = std::forward(u.get_deleter()); return *this; } @@ -176,7 +176,7 @@ public: return get() == pointer_type() ? false : true; } - pointer_type release(){ + pointer_type unlock(){ pointer_type p = get(); std::get<0>(_data) = pointer_type(); return p;