Switch to the new locking API.
authorcoderain <coderain@sdf.org>
Tue, 19 Jun 2018 18:08:15 +0000 (20:08 +0200)
committercoderain <coderain@sdf.org>
Tue, 19 Jun 2018 18:08:15 +0000 (20:08 +0200)
33 files changed:
drivers/acpica/src/osmlxf.c
drivers/floppy/src/main.c
drivers/ps2/src/main.c
drivers/serial/src/main.c
drivers/serial/src/serial.h
kernel/include/cache.h
kernel/include/device.h
kernel/include/filesystem.h
kernel/include/heap.h
kernel/include/memory.h
kernel/include/object.h
kernel/include/pipe.h
kernel/include/process.h
kernel/include/sync.h [deleted file]
kernel/include/thread.h
kernel/src/cache.c
kernel/src/device.c
kernel/src/filesystem.c
kernel/src/heap.c
kernel/src/interrupt.c
kernel/src/irq.c
kernel/src/isa_dma.c
kernel/src/lock.c
kernel/src/log.c
kernel/src/memory/memory.c
kernel/src/object.c
kernel/src/pipe.c
kernel/src/process.c
kernel/src/syscalls.c
kernel/src/thread.c
kernel/src/video.c
sdk/defs.h
sdk/semaphore.h

index 210976e2a2d2e5db4c1f0791670935049e4b8051..028d4f99af36087a415f8ad95a9ad35c215d2bfc 100644 (file)
@@ -28,6 +28,7 @@
 #include <acpi.h>
 #include <stdio.h>
 #include <power.h>
+#include <semaphore.h>
 
 const char driver_name[] = "acpica";
 
index e6f36f25fe3fe5913353f1914e4beb256a727bcb..dc651290633243d7c8976df6ce2546740baf47d1 100644 (file)
 #include <irq.h>
 #include <thread.h>
 #include <heap.h>
+#include <semaphore.h>
 
 const char driver_name[] = "floppy";
 
 static dword_t floppy_motor_status[FLOPPY_DRIVES];
-static lock_t floppy_lock = 0, floppy_motor_lock = 0;
+static DECLARE_LOCK(floppy_lock);
+static DECLARE_LOCK(floppy_motor_lock);
 static semaphore_t irq_mutex;
 static thread_t *floppy_thread = NULL;
 
@@ -149,7 +151,7 @@ static dword_t floppy_motor_thread(void *param)
 
     while (TRUE)
     {
-        acquire_lock(&floppy_motor_lock);
+        lock_acquire(&floppy_motor_lock);
 
         for (i = 0; i < FLOPPY_DRIVES; i++)
         {
@@ -167,7 +169,7 @@ static dword_t floppy_motor_thread(void *param)
             }
         }
 
-        release_lock(&floppy_motor_lock);
+        lock_release(&floppy_motor_lock);
         syscall_sleep(3000);
     }
 
@@ -176,7 +178,7 @@ static dword_t floppy_motor_thread(void *param)
 
 static void floppy_motor_on(dword_t drive)
 {
-    acquire_lock(&floppy_motor_lock);
+    lock_acquire(&floppy_motor_lock);
 
     if (floppy_motor_status[drive & 1] == FLOPPY_MOTOR_STOPPED)
     {
@@ -188,14 +190,14 @@ static void floppy_motor_on(dword_t drive)
     }
 
     floppy_motor_status[drive & 1] = FLOPPY_MOTOR_RUNNING;
-    release_lock(&floppy_motor_lock);
+    lock_release(&floppy_motor_lock);
 }
 
 static void floppy_motor_off(dword_t drive)
 {
-    acquire_lock(&floppy_motor_lock);
+    lock_acquire(&floppy_motor_lock);
     floppy_motor_status[drive & 1] = FLOPPY_MOTOR_IDLE;
-    release_lock(&floppy_motor_lock);
+    lock_release(&floppy_motor_lock);
 }
 
 static bool_t floppy_recalibrate(byte_t drive)
@@ -251,7 +253,7 @@ static dword_t floppy_init(void)
 
         device->driver = &floppy_driver_block;
         strcpy(device->name, FLOPPY_FIRST_NAME);
-        device->resource = 0;
+        lock_init(&device->lock);
         device->capacity = FLOPPY_SECTOR_SIZE * FLOPPY_SECTORS;
 
         ret = register_block_device(device);
@@ -271,7 +273,7 @@ static dword_t floppy_init(void)
 
         device->driver = &floppy_driver_block;
         strcpy(device->name, FLOPPY_SECOND_NAME);
-        device->resource = 0;
+        lock_init(&device->lock);
         device->capacity = FLOPPY_SECTOR_SIZE * FLOPPY_SECTORS;
 
         ret = register_block_device(device);
@@ -345,7 +347,7 @@ static dword_t floppy_read(device_t *device, void *buffer, qword_t offset, size_
     dma_buffer = (byte_t*)isa_dma_alloc();
     if (dma_buffer == NULL) return ERR_NOMEMORY;
 
-    acquire_lock(&floppy_lock);
+    lock_acquire(&floppy_lock);
     floppy_select(drive);
     floppy_motor_on(drive);
 
@@ -416,7 +418,7 @@ static dword_t floppy_read(device_t *device, void *buffer, qword_t offset, size_
 
 done:
     floppy_motor_off(drive);
-    release_lock(&floppy_lock);
+    lock_release(&floppy_lock);
     isa_dma_free(dma_buffer);
 
     if (bytes_read) *bytes_read = count;
@@ -457,7 +459,7 @@ static dword_t floppy_write(device_t *device, const void *buffer, qword_t offset
     dma_buffer = (byte_t*)isa_dma_alloc();
     if (dma_buffer == NULL) return ERR_NOMEMORY;
 
-    acquire_lock(&floppy_lock);
+    lock_acquire(&floppy_lock);
     floppy_select(drive);
     floppy_motor_on(drive);
 
@@ -540,7 +542,7 @@ static dword_t floppy_write(device_t *device, const void *buffer, qword_t offset
 
 done:
     floppy_motor_off(drive);
-    release_lock(&floppy_lock);
+    lock_release(&floppy_lock);
     isa_dma_free(dma_buffer);
 
     if (bytes_written) *bytes_written = count;
index e14b901451d3b557241595e0218da3464854bfd8..a3b057ee2eff72461f52f98c7af1b7fc73bb5d78 100644 (file)
@@ -24,6 +24,7 @@
 #include <timer.h>
 #include <heap.h>
 #include <stdio.h>
+#include <semaphore.h>
 
 const char driver_name[] = "ps2";
 
@@ -157,7 +158,7 @@ static void ps2_irq_handler(registers_t *registers, byte_t int_num)
 
             keyboard->header.port = port;
             keyboard->header.type = PS2_DEVICE_KEYBOARD;
-            keyboard->header.buffer_lock = 0;
+            lock_init(&keyboard->header.buffer_lock);
             keyboard->header.buffer_start = keyboard->header.buffer_end = 0;
 
             if (register_char_device(&keyboard->header.header) == ERR_SUCCESS) ps2_devices[port] = &keyboard->header;
@@ -173,7 +174,7 @@ static void ps2_irq_handler(registers_t *registers, byte_t int_num)
 
             mouse->header.port = port;
             mouse->header.type = PS2_DEVICE_MOUSE;
-            mouse->header.buffer_lock = 0;
+            lock_init(&mouse->header.buffer_lock);
 
             if (register_char_device(&mouse->header.header) == ERR_SUCCESS) ps2_devices[port] = &mouse->header;
             else free(mouse);
@@ -181,7 +182,7 @@ static void ps2_irq_handler(registers_t *registers, byte_t int_num)
     }
     else if (ps2_devices[port])
     {
-        acquire_lock(&ps2_devices[port]->buffer_lock);
+        lock_acquire(&ps2_devices[port]->buffer_lock);
 
         if (ps2_devices[port]->type == PS2_DEVICE_KEYBOARD)
         {
@@ -225,7 +226,7 @@ static void ps2_irq_handler(registers_t *registers, byte_t int_num)
             }
         }
 
-        release_lock(&ps2_devices[port]->buffer_lock);
+        lock_release(&ps2_devices[port]->buffer_lock);
     }
 }
 
@@ -326,7 +327,7 @@ static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *b
 
         while (length > 0)
         {
-            acquire_lock(&ps2_device->buffer_lock);
+            lock_acquire(&ps2_device->buffer_lock);
 
             while (ps2_device->buffer_start != ps2_device->buffer_end)
             {
@@ -336,7 +337,7 @@ static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *b
                 if (--length == 0) break;
             }
 
-            release_lock(&ps2_device->buffer_lock);
+            lock_release(&ps2_device->buffer_lock);
             if (length > 0) wait_mutex(&irq_mutex[ps2_device->port], NO_TIMEOUT);
         }
 
@@ -350,7 +351,7 @@ static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *b
 
         while (length > 0)
         {
-            acquire_lock(&ps2_device->buffer_lock);
+            lock_acquire(&ps2_device->buffer_lock);
 
             while (ps2_device->buffer_start != ps2_device->buffer_end)
             {
@@ -360,7 +361,7 @@ static dword_t ps2_read(device_t *device, void *buffer, size_t length, size_t *b
                 if (--length == 0) break;
             }
 
-            release_lock(&ps2_device->buffer_lock);
+            lock_release(&ps2_device->buffer_lock);
             if (length > 0) wait_mutex(&irq_mutex[ps2_device->port], NO_TIMEOUT);
         }
 
@@ -386,7 +387,7 @@ static dword_t ps2_ioctl(device_t *device, dword_t control_code, const void *in_
     case IOCTL_CHAR_DEV_CHECK_INPUT:
         if (out_length >= sizeof(size_t))
         {
-            acquire_lock(&ps2_device->buffer_lock);
+            lock_acquire(&ps2_device->buffer_lock);
 
             if (ps2_device->buffer_start <= ps2_device->buffer_end)
             {
@@ -397,7 +398,7 @@ static dword_t ps2_ioctl(device_t *device, dword_t control_code, const void *in_
                 *((size_t*)out_buffer) = ps2_device->buffer_end + PS2_BUFFER_CAPACITY - ps2_device->buffer_start;
             }
 
-            release_lock(&ps2_device->buffer_lock);
+            lock_release(&ps2_device->buffer_lock);
             return ERR_SUCCESS;
         }
         else
index 93442ba3e87d6bad0eed325e26d1910ff6bcb552..bb1b2b67fca400f46abd54d819803a4c96dcbaa6 100644 (file)
@@ -100,7 +100,7 @@ static dword_t serial_init(void)
 
         sprintf(device->header.name, "COM%d", i + 1);
         device->header.driver = &serial_driver;
-        device->header.resource = 0;
+        lock_init(&device->header.lock);
         device->port = bda_data[i];
 
         init_semaphore(&device->read_mutex, 0, 1);
index d9491a5c437d754cf764469529a423a4247792bf..f9ddba4b31a7df62a350004f91325587753e5888 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <device.h>
+#include <semaphore.h>
 
 #define SERIAL_BAUD_FREQ 115200
 
index f4492bccb2bcec8c4be2a9a8866abd73aac1cea4..2d83094aec48ee0d7caf6e22d7f3e9159b6e2763 100644 (file)
@@ -21,7 +21,7 @@
 #define _CACHE_H_
 
 #include <common.h>
-#include <sync.h>
+#include <lock.h>
 #include <device.h>
 #include <sdk/avltree.h>
 
@@ -45,7 +45,7 @@ typedef struct device device_t;
 typedef struct
 {
     bool_t enabled;
-    resource_t resource;
+    lock_t lock;
     dword_t flags;
     dword_t block_size;
     read_write_buffer_proc_t read_proc, write_proc;
index e050bd71ad327f78eb50b8fef37658fe5a41d424..bf6133c4a1eaf4e8eabf67ea35a28a21449bdf54 100644 (file)
@@ -21,7 +21,7 @@
 #define _DEVICE_H_
 
 #include <common.h>
-#include <sync.h>
+#include <lock.h>
 #include <cache.h>
 #include <filesystem.h>
 #include <sdk/list.h>
@@ -75,7 +75,7 @@ typedef struct device
     list_entry_t list;
     device_type_t type;
     char name[MAX_DEVICE_NAME];
-    resource_t resource;
+    lock_t lock;
     dword_t flags;
     qword_t capacity;
 
index 3b50aeb1cfd6faddabee60a8d2989096bfd7a4dd..9d9995e751dfab1c1a3c6a474d3e81867ae23e00 100644 (file)
@@ -24,7 +24,7 @@
 #include <object.h>
 #include <sdk/list.h>
 #include <clock.h>
-#include <sync.h>
+#include <lock.h>
 #include <sdk/filesystem.h>
 #include <pipe.h>
 
@@ -95,7 +95,7 @@ struct mounted_volume
     list_entry_t list;
     char *mountpoint;
     dword_t flags;
-    resource_t resource;
+    lock_t lock;
     device_t *device;
     qword_t open_files;
     fs_driver_t *driver;
index f60ce928509e9f3bc0b8bce35e9573cf90c14a13..bb8f488a30c53b7259834d11bb6a01ba0860bd69 100644 (file)
@@ -21,7 +21,7 @@
 #define _HEAP_H_
 
 #include <common.h>
-#include <sync.h>
+#include <lock.h>
 #include <crt/include/malloc.h>
 
 #define SYSTEM_HEAP_START    0x90000000
index 03d976bab9cd7e5cc164f0e7863f08e7e05263d3..3782cb75381bbf756baafd53a44f828251cf4502 100644 (file)
@@ -92,7 +92,7 @@ typedef struct
     uintptr_t pool_size;
     avl_tree_t by_addr_tree;
     avl_tree_t by_size_tree;
-    resource_t resource;
+    lock_t lock;
     list_entry_t evictable_blocks;
     list_entry_t *evict_blk_ptr;
     uintptr_t evict_page_num;
index d846a52a4a0e706a711ac0c4bf626f4ee8ba7414..d3ca00d047786a22013634357689216bd57818ad 100644 (file)
@@ -21,6 +21,7 @@
 #define _OBJECT_H_
 
 #include <common.h>
+#include <lock.h>
 #include <sdk/object.h>
 #include <sdk/list.h>
 #include <sdk/user.h>
@@ -41,7 +42,7 @@ typedef struct
     dword_t open_count;
     object_type_t type;
     uid_t owner;
-    qword_t acl_lock;
+    lock_t acl_lock;
     list_entry_t acl;
 } object_t;
 
index 9b09895f461393982e27fac1061893dd29493ab0..ddeb4a403c811917a4b2573197a11e00985d78f2 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef _PIPE_H_
 #define _PIPE_H_
 
-#include <sync.h>
+#include <lock.h>
 #include <object.h>
 #include <sdk/pipe.h>
 #include <thread.h>
@@ -78,7 +78,7 @@ typedef struct
 static inline void init_pipe(pipe_t *pipe, dword_t flags)
 {
     pipe->flags = flags;
-    pipe->lock = 0;
+    lock_init(&pipe->lock);
     list_init(&pipe->fifo);
 }
 
index 5d5760bb936f5b147548c8166f306178de0b2139..d23a782a25b780f02238b3c691232cdc6e266e8d 100644 (file)
@@ -58,10 +58,10 @@ struct process
     clock_time_t start_time;
     clock_time_t end_time;
     list_entry_t threads;
-    resource_t thread_list_res;
+    lock_t thread_list_lock;
     handle_info_t *handle_table;
     dword_t handle_count, handle_table_size;
-    resource_t handle_table_res;
+    lock_t handle_table_lock;
     user_t *original_user; /* weak reference */
     user_t *current_user; /* strong reference */
 };
diff --git a/kernel/include/sync.h b/kernel/include/sync.h
deleted file mode 100644 (file)
index f6e15f5..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * sync.h
- *
- * Copyright (C) 2018 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _SYNC_H_
-#define _SYNC_H_
-
-#include <sdk/defs.h>
-#include <lock.h>
-#include <semaphore.h>
-
-/*
- * NOTE: This is the legacy interface for synchronization functions. New code
- * should use lock.h and semaphore.h instead.
- */
-
-#define lock_t qword_t
-#define resource_t qword_t
-
-static inline void acquire_lock(qword_t *lock)
-{
-    void (*proc)(void*) = (void(*)(void*))lock_acquire;
-    proc(lock);
-}
-
-static inline void release_lock(qword_t *lock)
-{
-    void (*proc)(void*) = (void(*)(void*))lock_release;
-    proc(lock);
-}
-
-static inline void acquire_resource_shared(qword_t *resource)
-{
-    void (*proc)(void*) = (void(*)(void*))lock_acquire_shared;
-    proc(resource);
-}
-
-static inline void acquire_resource_exclusive(qword_t *resource)
-{
-    void (*proc)(void*) = (void(*)(void*))lock_acquire;
-    proc(resource);
-}
-
-static inline void release_resource(qword_t *resource)
-{
-    void (*proc)(void*) = (void(*)(void*))lock_release;
-    proc(resource);
-}
-
-#endif
index 1f46015f677a5124e75548335f1291ea8dc2c412..748019990ea58b9ef532dcb42c24f2108c7034dc 100644 (file)
@@ -24,7 +24,7 @@
 #include <object.h>
 #include <exception.h>
 #include <sdk/list.h>
-#include <sync.h>
+#include <lock.h>
 #include <interrupt.h>
 #include <syscalls.h>
 #include <sdk/thread.h>
index 4102e42f24adc92686603f4a3d9b40c2f655b125..c89e173514a40a22034c85970042801c5d104e8a 100644 (file)
@@ -65,7 +65,7 @@ void init_cache(cache_descriptor_t *cache,
                 read_write_buffer_proc_t write_proc)
 {
     cache->enabled = TRUE;
-    cache->resource = 0;
+    lock_init(&cache->lock);
     cache->flags = flags;
     cache->block_size = block_size;
     cache->read_proc = read_proc;
@@ -88,7 +88,7 @@ dword_t read_cache(cache_descriptor_t *cache, void *context, byte_t *buffer, qwo
     qword_t last_block = (offset + length - 1) / (qword_t)cache->block_size;
     bool_t exclusive = FALSE;
 
-    acquire_resource_shared(&cache->resource);
+    lock_acquire_shared(&cache->lock);
     *bytes_read = 0;
 
     for (i = first_block; i <= last_block; i++)
@@ -98,8 +98,8 @@ dword_t read_cache(cache_descriptor_t *cache, void *context, byte_t *buffer, qwo
 
         if (element == NULL && !exclusive)
         {
-            release_resource(&cache->resource);
-            acquire_resource_exclusive(&cache->resource);
+            lock_release(&cache->lock);
+            lock_acquire(&cache->lock);
             exclusive = TRUE;
             element = avl_tree_lookup(&cache->entries, &i);
         }
@@ -145,7 +145,7 @@ dword_t read_cache(cache_descriptor_t *cache, void *context, byte_t *buffer, qwo
         *bytes_read += bytes_to_copy;
     }
 
-    release_resource(&cache->resource);
+    lock_release(&cache->lock);
     return ret;
 }
 
@@ -156,7 +156,7 @@ dword_t write_cache(cache_descriptor_t *cache, void *context, const byte_t *buff
     qword_t first_block = offset / (qword_t)cache->block_size;
     qword_t last_block = (offset + length - 1) / (qword_t)cache->block_size;
 
-    acquire_resource_exclusive(&cache->resource);
+    lock_acquire(&cache->lock);
     *bytes_written = 0;
 
     for (i = first_block; i <= last_block; i++)
@@ -219,7 +219,7 @@ dword_t write_cache(cache_descriptor_t *cache, void *context, const byte_t *buff
         }
     }
 
-    release_resource(&cache->resource);
+    lock_release(&cache->lock);
     return ret;
 }
 
index ebece44379d7acf2668d353f688802b28032101a..eac82c8e28426016c95efcd478fc5b7acd29bd8d 100644 (file)
@@ -28,10 +28,10 @@ static DECLARE_LIST(block_dev_drivers);
 static DECLARE_LIST(char_dev_drivers);
 static DECLARE_LIST(block_devices);
 static DECLARE_LIST(char_devices);
-static lock_t block_dev_driver_list_lock = 0;
-static lock_t char_dev_driver_list_lock = 0;
-static resource_t block_device_list_res = 0;
-static resource_t char_device_list_res = 0;
+static DECLARE_LOCK(block_dev_driver_list_lock);
+static DECLARE_LOCK(char_dev_driver_list_lock);
+static DECLARE_LOCK(block_device_list_lock);
+static DECLARE_LOCK(char_device_list_lock);
 
 dword_t device_mount(const char *device, const char *mountpoint, dword_t flags);
 dword_t device_unmount(mounted_volume_t *volume);
@@ -66,7 +66,7 @@ static mounted_volume_t block_device_volume =
 {
     .mountpoint = "BlockDevices",
     .flags      = 0,
-    .resource   = 0,
+    .lock       = {0},
     .device     = NULL,
     .open_files = 0ULL,
     .driver     = &device_fs_driver
@@ -76,7 +76,7 @@ static mounted_volume_t char_device_volume =
 {
     .mountpoint = "CharDevices",
     .flags      = 0,
-    .resource   = 0,
+    .lock       = {0},
     .device     = NULL,
     .open_files = 0ULL,
     .driver     = &device_fs_driver
@@ -86,7 +86,7 @@ device_t *get_block_device(const char *name)
 {
     list_entry_t *i;
     device_t *ptr = NULL;
-    acquire_resource_shared(&block_device_list_res);
+    lock_acquire_shared(&block_device_list_lock);
 
     for (i = block_devices.next; i != &block_devices; i = i->next)
     {
@@ -96,7 +96,7 @@ device_t *get_block_device(const char *name)
 
     if (i == &block_devices) ptr = NULL;
 
-    release_resource(&block_device_list_res);
+    lock_release(&block_device_list_lock);
     return ptr;
 }
 
@@ -107,9 +107,9 @@ dword_t register_block_dev_driver(block_dev_driver_t *driver)
     if (ret == ERR_SUCCESS)
     {
         driver->mounted_devices = 0;
-        acquire_lock(&block_dev_driver_list_lock);
+        lock_acquire(&block_dev_driver_list_lock);
         list_append(&block_dev_drivers, &driver->list);
-        release_lock(&block_dev_driver_list_lock);
+        lock_release(&block_dev_driver_list_lock);
     }
 
     return ret;
@@ -120,9 +120,9 @@ dword_t unregister_block_dev_driver(block_dev_driver_t *driver)
     if (driver->mounted_devices) return ERR_BUSY;
 
     driver->cleanup_proc();
-    acquire_lock(&block_dev_driver_list_lock);
+    lock_acquire(&block_dev_driver_list_lock);
     list_remove(&driver->list);
-    release_lock(&block_dev_driver_list_lock);
+    lock_release(&block_dev_driver_list_lock);
 
     return ERR_SUCCESS;
 }
@@ -134,7 +134,7 @@ dword_t register_block_device(device_t *device)
 
     device->type = BLOCK_DEVICE;
 
-    acquire_resource_exclusive(&block_device_list_res);
+    lock_acquire(&block_device_list_lock);
 
     for (i = block_devices.next; i != &block_devices; i = i->next)
     {
@@ -150,15 +150,15 @@ dword_t register_block_device(device_t *device)
     list_append(&block_devices, &device->list);
 
 cleanup:
-    release_resource(&block_device_list_res);
+    lock_release(&block_device_list_lock);
     return ret;
 }
 
 dword_t unregister_block_device(device_t *device)
 {
-    acquire_resource_exclusive(&block_device_list_res);
+    lock_acquire(&block_device_list_lock);
     list_remove(&device->list);
-    release_resource(&block_device_list_res);
+    lock_release(&block_device_list_lock);
 
     return ERR_SUCCESS;
 }
@@ -168,13 +168,13 @@ device_t *get_char_device(const char *name)
     list_entry_t *i;
     device_t *device;
 
-    acquire_resource_shared(&block_device_list_res);
+    lock_acquire_shared(&block_device_list_lock);
     for (i = char_devices.next; i != &char_devices; i = i->next)
     {
         device = CONTAINER_OF(i, device_t, list);
         if (strcmp(device->name, name) == 0) break;
     }
-    release_resource(&block_device_list_res);
+    lock_release(&block_device_list_lock);
 
     return (i != &char_devices) ? device : NULL;
 }
@@ -185,9 +185,9 @@ dword_t register_char_dev_driver(char_dev_driver_t *driver)
 
     if (ret == ERR_SUCCESS)
     {
-        acquire_lock(&char_dev_driver_list_lock);
+        lock_acquire(&char_dev_driver_list_lock);
         list_append(&char_dev_drivers, &driver->list);
-        release_lock(&char_dev_driver_list_lock);
+        lock_release(&char_dev_driver_list_lock);
     }
 
     return ret;
@@ -196,9 +196,9 @@ dword_t register_char_dev_driver(char_dev_driver_t *driver)
 dword_t unregister_char_dev_driver(char_dev_driver_t *driver)
 {
     driver->cleanup_proc();
-    acquire_lock(&char_dev_driver_list_lock);
+    lock_acquire(&char_dev_driver_list_lock);
     list_remove(&driver->list);
-    release_lock(&char_dev_driver_list_lock);
+    lock_release(&char_dev_driver_list_lock);
 
     return ERR_SUCCESS;
 }
@@ -210,7 +210,7 @@ dword_t register_char_device(device_t *device)
 
     device->type = CHAR_DEVICE;
 
-    acquire_resource_exclusive(&char_device_list_res);
+    lock_acquire(&char_device_list_lock);
 
     for (i = char_devices.next; i != &char_devices; i = i->next)
     {
@@ -226,15 +226,15 @@ dword_t register_char_device(device_t *device)
     list_append(&char_devices, &device->list);
 
 cleanup:
-    release_resource(&char_device_list_res);
+    lock_release(&char_device_list_lock);
     return ret;
 }
 
 dword_t unregister_char_device(device_t *device)
 {
-    acquire_resource_exclusive(&char_device_list_res);
+    lock_acquire(&char_device_list_lock);
     list_remove(&device->list);
-    release_resource(&char_device_list_res);
+    lock_release(&char_device_list_lock);
 
     return ERR_SUCCESS;
 }
@@ -355,7 +355,7 @@ dword_t device_set_file(file_t *file, dword_t info_type, const void *buffer, siz
 dword_t device_read(device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read)
 {
     dword_t ret;
-    acquire_resource_shared(&device->resource);
+    lock_acquire_shared(&device->lock);
 
     if (device->type == BLOCK_DEVICE)
     {
@@ -370,14 +370,14 @@ dword_t device_read(device_t *device, void *buffer, qword_t offset, size_t lengt
         ret = ERR_INVALID;
     }
 
-    release_resource(&device->resource);
+    lock_release(&device->lock);
     return ret;
 }
 
 dword_t device_write(device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written)
 {
     dword_t ret;
-    acquire_resource_exclusive(&device->resource);
+    lock_acquire(&device->lock);
 
     if (device->type == BLOCK_DEVICE)
     {
@@ -392,14 +392,14 @@ dword_t device_write(device_t *device, const void *buffer, qword_t offset, size_
         ret = ERR_INVALID;
     }
 
-    release_resource(&device->resource);
+    lock_release(&device->lock);
     return ret;
 }
 
 dword_t device_ioctl_internal(device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length)
 {
     dword_t ret;
-    acquire_resource_exclusive(&device->resource);
+    lock_acquire(&device->lock);
 
     if (device->type == BLOCK_DEVICE)
     {
@@ -414,7 +414,7 @@ dword_t device_ioctl_internal(device_t *device, dword_t control_code, const void
         ret = ERR_INVALID;
     }
 
-    release_resource(&device->resource);
+    lock_release(&device->lock);
     return ret;
 }
 
index 620cd3891fa3d765fefbb1b2a7fb2baafd9a7f12..70641dad8bd126003f2af9f97fa9c51716d72cb1 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <filesystem.h>
-#include <sync.h>
 #include <exception.h>
 #include <memory.h>
 #include <heap.h>
@@ -26,8 +25,8 @@
 
 static DECLARE_LIST(fs_driver_list);
 static DECLARE_LIST(volumes);
-lock_t fs_driver_list_lock = 0;
-resource_t volume_list_res = 0;
+static DECLARE_LOCK(fs_driver_list_lock);
+static DECLARE_LOCK(volume_list_lock);
 
 static inline int count_delimiters(const char *string)
 {
@@ -40,7 +39,7 @@ mounted_volume_t *get_volume_from_path(const char *path)
 {
     mounted_volume_t *volume = NULL;
     list_entry_t *ptr;
-    acquire_resource_shared(&volume_list_res);
+    lock_acquire_shared(&volume_list_lock);
 
     for (ptr = volumes.next; ptr != &volumes; ptr = ptr->next)
     {
@@ -55,7 +54,7 @@ mounted_volume_t *get_volume_from_path(const char *path)
         }
     }
 
-    release_resource(&volume_list_res);
+    lock_release(&volume_list_lock);
     return volume;
 }
 
@@ -64,7 +63,7 @@ void report_filesystem_event(const char *path, dword_t type)
     list_entry_t *ptr;
     mounted_volume_t *volume = get_volume_from_path(path);
     int path_length = strlen(path);
-    acquire_lock(&volume->event_watch_list_lock);
+    lock_acquire(&volume->event_watch_list_lock);
 
     for (ptr = volume->event_watch_list.next; ptr != &volume->event_watch_list; ptr = ptr->next)
     {
@@ -85,14 +84,14 @@ void report_filesystem_event(const char *path, dword_t type)
         dereference(&watch->directory->header);
     }
 
-    release_lock(&volume->event_watch_list_lock);
+    lock_release(&volume->event_watch_list_lock);
 }
 
 void file_cleanup(file_t *file)
 {
-    acquire_resource_exclusive(&file->volume->resource);
+    lock_acquire(&file->volume->lock);
     file->volume->driver->unload_file(file);
-    release_resource(&file->volume->resource);
+    lock_release(&file->volume->lock);
 
     file->volume->open_files--;
 }
@@ -106,9 +105,9 @@ void file_instance_cleanup(file_instance_t *instance)
         ASSERT(file->attributes & FILE_ATTR_DIRECTORY);
         ASSERT(instance->watch->directory == instance);
 
-        acquire_lock(&file->volume->event_watch_list_lock);
+        lock_acquire(&file->volume->event_watch_list_lock);
         list_remove(&instance->watch->list);
-        release_lock(&file->volume->event_watch_list_lock);
+        lock_release(&file->volume->event_watch_list_lock);
 
         pipe_cleanup(&instance->watch->pipe.header);
 
@@ -131,28 +130,28 @@ void file_instance_cleanup(file_instance_t *instance)
 
 void register_filesystem_driver(fs_driver_t *driver)
 {
-    acquire_lock(&fs_driver_list_lock);
+    lock_acquire(&fs_driver_list_lock);
     list_append(&fs_driver_list, &driver->list);
-    release_lock(&fs_driver_list_lock);
+    lock_release(&fs_driver_list_lock);
 }
 
 bool_t unregister_filesystem_driver(fs_driver_t *driver)
 {
-    acquire_lock(&fs_driver_list_lock);
+    lock_acquire(&fs_driver_list_lock);
     list_remove(&driver->list);
-    release_lock(&fs_driver_list_lock);
+    lock_release(&fs_driver_list_lock);
 
     return TRUE;
 }
 
 dword_t register_mounted_volume(mounted_volume_t *volume)
 {
-    acquire_resource_exclusive(&volume_list_res);
+    lock_acquire(&volume_list_lock);
 
-    volume->resource = 0;
+    lock_init(&volume->lock);;
     volume->open_files = 0;
     list_init(&volume->event_watch_list);
-    volume->event_watch_list_lock = 0;
+    lock_init(&volume->event_watch_list_lock);
 
     int delimiters = count_delimiters(volume->mountpoint);
     list_entry_t *ptr;
@@ -165,20 +164,20 @@ dword_t register_mounted_volume(mounted_volume_t *volume)
 
     list_put_before(ptr, &volume->list);
 
-    release_resource(&volume_list_res);
+    lock_release(&volume_list_lock);
     return ERR_SUCCESS;
 }
 
 dword_t unregister_mounted_volume(mounted_volume_t *volume)
 {
     if (volume->open_files > 0) return ERR_BUSY;
-    acquire_resource_exclusive(&volume_list_res);
-    acquire_resource_exclusive(&volume->resource);
+    lock_acquire(&volume_list_lock);
+    lock_acquire(&volume->lock);
 
     list_remove(&volume->list);
 
-    release_resource(&volume->resource);
-    release_resource(&volume_list_res);
+    lock_release(&volume->lock);
+    lock_release(&volume_list_lock);
     return ERR_SUCCESS;
 }
 
@@ -257,7 +256,7 @@ sysret_t syscall_mount(const char *device, const char *mountpoint, const char *f
         safe_filesystem = (char*)filesystem;
     }
 
-    acquire_lock(&fs_driver_list_lock);
+    lock_acquire(&fs_driver_list_lock);
 
     for (i = fs_driver_list.next; i != &fs_driver_list; i = i->next)
     {
@@ -270,7 +269,7 @@ sysret_t syscall_mount(const char *device, const char *mountpoint, const char *f
         }
     }
 
-    release_lock(&fs_driver_list_lock);
+    lock_release(&fs_driver_list_lock);
 
     if (get_previous_mode() == USER_MODE)
     {
@@ -284,7 +283,7 @@ sysret_t syscall_mount(const char *device, const char *mountpoint, const char *f
 
 sysret_t syscall_unmount(const char *mountpoint)
 {
-    acquire_resource_exclusive(&volume_list_res);
+    lock_acquire(&volume_list_lock);
     list_entry_t *ptr;
     mounted_volume_t *vol = NULL;
 
@@ -299,7 +298,7 @@ sysret_t syscall_unmount(const char *mountpoint)
         }
     }
 
-    release_resource(&volume_list_res);
+    lock_release(&volume_list_lock);
 
     if (vol->open_files) return ERR_BUSY;
     return vol->driver->unmount(vol);
@@ -475,7 +474,7 @@ sysret_t syscall_delete_file(const char *path)
         goto cleanup;
     }
 
-    acquire_resource_exclusive(&vol->resource);
+    lock_acquire(&vol->lock);
 
     file_t *file = NULL;
     reference_by_name(normalized_path, OBJECT_FILE, (object_t**)&file);
@@ -490,7 +489,7 @@ sysret_t syscall_delete_file(const char *path)
         dereference(&file->header);
     }
 
-    release_resource(&vol->resource);
+    lock_release(&vol->lock);
 
 cleanup:
     if (get_previous_mode() == USER_MODE) free(safe_path);
@@ -518,7 +517,7 @@ sysret_t syscall_query_file(handle_t handle, file_info_type_t type, void *buffer
 
     if (!reference_by_handle(handle, OBJECT_FILE_INSTANCE, (object_t**)&file)) return ERR_INVALID;
 
-    acquire_resource_shared(&file->global->volume->resource);
+    lock_acquire_shared(&file->global->volume->lock);
 
     switch (type)
     {
@@ -550,7 +549,7 @@ sysret_t syscall_query_file(handle_t handle, file_info_type_t type, void *buffer
         ret = ERR_INVALID;
     }
 
-    release_resource(&file->global->volume->resource);
+    lock_release(&file->global->volume->lock);
 
     if (get_previous_mode() == USER_MODE)
     {
@@ -584,9 +583,9 @@ sysret_t syscall_set_file(handle_t handle, file_info_type_t set_type, void *buff
 
     if (!reference_by_handle(handle, OBJECT_FILE_INSTANCE, (object_t**)&file)) return ERR_INVALID;
 
-    acquire_resource_exclusive(&file->global->volume->resource);
+    lock_acquire(&file->global->volume->lock);
     dword_t ret = file->global->volume->driver->set_file(file->global, set_type, safe_buffer, size);
-    release_resource(&file->global->volume->resource);
+    lock_release(&file->global->volume->lock);
 
     if (file) dereference(&file->header);
     if (get_previous_mode() == USER_MODE) free(safe_buffer);
@@ -600,9 +599,9 @@ sysret_t syscall_list_directory(handle_t handle, char *filename, bool_t continue
 
     if (!reference_by_handle(handle, OBJECT_FILE_INSTANCE, (object_t**)&directory)) return ERR_INVALID;
 
-    acquire_resource_shared(&directory->global->volume->resource);
+    lock_acquire_shared(&directory->global->volume->lock);
     dword_t ret = directory->global->volume->driver->list_dir(directory, safe_filename, continue_scan);
-    release_resource(&directory->global->volume->resource);
+    lock_release(&directory->global->volume->lock);
 
     if (ret == ERR_SUCCESS)
     {
@@ -649,9 +648,9 @@ sysret_t syscall_read_file(handle_t handle, void *buffer, qword_t offset, size_t
         goto cleanup;
     }
 
-    acquire_resource_shared(&file->global->volume->resource);
+    lock_acquire_shared(&file->global->volume->lock);
     ret = file->global->volume->driver->read_file(file, safe_buffer, offset, size, &read_count);
-    release_resource(&file->global->volume->resource);
+    lock_release(&file->global->volume->lock);
 
 cleanup:
     EH_TRY *bytes_read = read_count;
@@ -697,9 +696,9 @@ sysret_t syscall_write_file(handle_t handle, const void *buffer, qword_t offset,
         goto cleanup;
     }
 
-    acquire_resource_exclusive(&file->global->volume->resource);
+    lock_acquire(&file->global->volume->lock);
     ret = file->global->volume->driver->write_file(file, safe_buffer, offset, size, &written_count);
-    release_resource(&file->global->volume->resource);
+    lock_release(&file->global->volume->lock);
 
     EH_TRY *bytes_written = written_count;
     EH_DONE;
@@ -730,7 +729,7 @@ sysret_t syscall_wait_directory_event(handle_t handle, dword_t event_mask, file_
         init_pipe(&watch->pipe, PIPE_MESSAGE);
 
         mounted_volume_t *volume = directory->global->volume;
-        acquire_lock(&volume->event_watch_list_lock);
+        lock_acquire(&volume->event_watch_list_lock);
         list_append(&volume->event_watch_list, &watch->list);
 
         if (!__sync_bool_compare_and_swap(&directory->watch, NULL, watch))
@@ -739,7 +738,7 @@ sysret_t syscall_wait_directory_event(handle_t handle, dword_t event_mask, file_
             free(watch);
         }
 
-        release_lock(&volume->event_watch_list_lock);
+        lock_release(&volume->event_watch_list_lock);
     }
 
     directory->watch->event_mask = event_mask;
index c6d2414b4fbf2d999efa6533f1068452ad1eea7d..7920f24991bafcc3c751d3f70a835b7a1552b368 100644 (file)
@@ -72,9 +72,9 @@ dword_t heap_create(heap_t *heap, uintptr_t start, uintptr_t end, dword_t flags,
     heap->crt.flags = 0;
     heap->crt.mutex = (void*)&heap->lock;
     heap->crt.problem = heap_problem;
-    heap->crt.lock_mutex_proc = (void (*)(void*))&acquire_lock;
-    heap->crt.unlock_mutex_proc = (void (*)(void*))&release_lock;
-    heap->lock = 0;
+    heap->crt.lock_mutex_proc = (void (*)(void*))&lock_acquire;
+    heap->crt.unlock_mutex_proc = (void (*)(void*))&lock_release;
+    lock_init(&heap->lock);
 
     if (flags & HEAP_ZEROFILL) heap->crt.flags |= __CRT_HEAP_FLAG_ZEROFILL;
 
index c4ebd7a03f27f09c1db56377883557c05db6f1c9..d335aa98eb81e72a46dfd1100aab921b883fafc1 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <interrupt.h>
 #include <segments.h>
-#include <sync.h>
+#include <lock.h>
 #include <thread.h>
 
 static byte_t isr_stubs[IDT_NUM_INTERRUPTS * ISR_STUB_SIZE];
index d3aa03d278944b2a2859229702a160ce52ff29b7..7e1940e6f7fb7efb4cfbb8fb10edd37d6df83069 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <irq.h>
 #include <heap.h>
-#include <sync.h>
+#include <lock.h>
 
 static list_entry_t irq_handlers[MAX_IRQ_COUNT];
 static dword_t irq_alloc_bitmap = 0xFFFFF3FF;
index 8570edbc935628258e221014dd5ade6a59b0df8d..5970030e060044a9940ed6b685b1c1c408bc1fdc 100644 (file)
  */
 
 #include <isa_dma.h>
-#include <sync.h>
+#include <lock.h>
 
 static dword_t isa_dma_bitmap[1 + ((ISA_DMA_MEM_BLOCKS - 1) / 32)] = { 0 };
-static lock_t dma_lock = 0;
+static DECLARE_LOCK(dma_lock);
 
 void *isa_dma_alloc(void)
 {
@@ -47,7 +47,7 @@ void isa_dma_read(dword_t channel, void *buffer, word_t count)
     if (count == 0) return;
     else count--;
 
-    acquire_lock(&dma_lock);
+    lock_acquire(&dma_lock);
     outportb(ISA_DMA_SINGLE_MASK_REG(channel), ISA_DMA_MASK_ON | (channel & 3));
 
     outportb(ISA_DMA_FF_RESET_REG(channel), 0xFF);
@@ -62,7 +62,7 @@ void isa_dma_read(dword_t channel, void *buffer, word_t count)
     outportb(ISA_DMA_MODE_REG(channel), 0x48 | (channel & 3));
 
     outportb(ISA_DMA_SINGLE_MASK_REG(channel), (channel & 3));
-    release_lock(&dma_lock);
+    lock_release(&dma_lock);
 }
 
 void isa_dma_write(dword_t channel, void *buffer, dword_t count)
@@ -71,7 +71,7 @@ void isa_dma_write(dword_t channel, void *buffer, dword_t count)
     if (count == 0) return;
     else count--;
 
-    acquire_lock(&dma_lock);
+    lock_acquire(&dma_lock);
     outportb(ISA_DMA_SINGLE_MASK_REG(channel), ISA_DMA_MASK_ON | (channel & 3));
 
     outportb(ISA_DMA_FF_RESET_REG(channel), 0xFF);
@@ -86,5 +86,5 @@ void isa_dma_write(dword_t channel, void *buffer, dword_t count)
     outportb(ISA_DMA_MODE_REG(channel), 0x44 | (channel & 3));
 
     outportb(ISA_DMA_SINGLE_MASK_REG(channel), (channel & 3));
-    release_lock(&dma_lock);
+    lock_release(&dma_lock);
 }
index 3cf37f0b098bf9f6b1efb2d77f302475aa219bf3..69bcbbb9a43b92fbccadd275f3a2486ea87a7184 100644 (file)
@@ -18,9 +18,6 @@
  */
 
 #include <thread.h>
-
-#undef lock_t
-#undef resource_t
 #include <lock.h>
 
 #define NO_HOLDER ((uintptr_t)0)
index 7dcfca5d4ce401f39820f37ebb7619a84394a8eb..d24e47cf2a07f6df83b31dd89138af4f4cab8672 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <log.h>
 #include <device.h>
-#include <sync.h>
+#include <lock.h>
 #include <stdio.h>
 #include <timer.h>
 
@@ -31,7 +31,7 @@ typedef struct
     char message[MAX_LOG_MESSAGE_SIZE];
 } log_entry_t;
 
-static lock_t lock = 0;
+static DECLARE_LOCK(lock);
 static log_entry_t queue[QUEUE_SIZE];
 static bool_t empty = TRUE;
 static dword_t start = 0, end = 0;
@@ -48,7 +48,7 @@ static void flush_queue(void)
     if (!debug_channel) return;
     device_t *device = get_char_device(debug_channel);
     if (!device) return;
-    acquire_lock(&lock);
+    lock_acquire(&lock);
 
     while (!empty)
     {
@@ -63,7 +63,7 @@ static void flush_queue(void)
         if (start == end) empty = TRUE;
     }
 
-    release_lock(&lock);
+    lock_release(&lock);
 }
 
 void append_log_entry(const char *source, log_level_t level, const char *message)
@@ -84,7 +84,7 @@ void append_log_entry(const char *source, log_level_t level, const char *message
     message_copy[length] = '\0';
     if (too_big) strcat(message_copy, "...");
 
-    acquire_lock(&lock);
+    lock_acquire(&lock);
     queue[end].level = level;
     snprintf(queue[end].message, MAX_LOG_MESSAGE_SIZE, "[%s] %s\n", source, message_copy);
 
@@ -98,6 +98,6 @@ void append_log_entry(const char *source, log_level_t level, const char *message
     end %= QUEUE_SIZE;
     empty = FALSE;
 
-    release_lock(&lock);
+    lock_release(&lock);
     flush_queue();
 }
index f2baea3b10abf584b3db8228a344dc16a27d604a..4ae945d58efba9fc84dfa710c858f78825a76691 100644 (file)
 #include <syscalls.h>
 #include <heap.h>
 #include <cpu.h>
+#include <semaphore.h>
 
 static void **physical_memory_stack = (void**)MEM_STACK_VIRT_ADDR;
-static lock_t phys_mem_stack_lock = 0;
+static DECLARE_LOCK(phys_mem_stack_lock);
 static page_t *pages = NULL;
 static void *current_page_directory = INVALID_PAGE;
 static memory_address_space_t kernel_address_space;
@@ -35,12 +36,12 @@ static list_entry_t user_address_spaces = { &user_address_spaces, &user_address_
 static dword_t total_physical_pages = 0;
 static dword_t num_free_pages = 0;
 static dword_t mem_tree_bitmap[TOTAL_PAGES / 32];
-static lock_t mem_tree_lock = 0;
+static DECLARE_LOCK(mem_tree_lock);
 static semaphore_t temporary_page_semaphore;
 static bool_t evicting = FALSE;
 static DECLARE_LIST(transition_pages);
 static DECLARE_LIST(page_stores);
-static lock_t page_store_lock = 0;
+static DECLARE_LOCK(page_store_lock);
 
 static void *evict_page(void);
 
@@ -62,18 +63,18 @@ static inline void *alloc_physical_page(void)
         if (page != INVALID_PAGE) return page;
     }
 
-    acquire_lock(&phys_mem_stack_lock);
+    lock_acquire(&phys_mem_stack_lock);
     if (num_free_pages) page = physical_memory_stack[--num_free_pages];
-    release_lock(&phys_mem_stack_lock);
+    lock_release(&phys_mem_stack_lock);
 
     return page;
 }
 
 static inline void free_physical_page(void *address)
 {
-    acquire_lock(&phys_mem_stack_lock);
+    lock_acquire(&phys_mem_stack_lock);
     physical_memory_stack[num_free_pages++] = address;
-    release_lock(&phys_mem_stack_lock);
+    lock_release(&phys_mem_stack_lock);
 }
 
 static int compare_page(const void *a, const void *b)
@@ -475,7 +476,7 @@ static memory_block_t *mem_tree_alloc(void)
     dword_t i;
     memory_block_t *block = NULL;
 
-    acquire_lock(&mem_tree_lock);
+    lock_acquire(&mem_tree_lock);
     for (i = 0; i < TOTAL_PAGES; i++) if (!test_bit(mem_tree_bitmap, i)) break;
 
     if (i < TOTAL_PAGES)
@@ -493,7 +494,7 @@ static memory_block_t *mem_tree_alloc(void)
         }
     }
 
-    release_lock(&mem_tree_lock);
+    lock_release(&mem_tree_lock);
     return block;
 }
 
@@ -503,7 +504,7 @@ static void mem_tree_free(memory_block_t *block)
     bool_t busy = FALSE;
     dword_t i, page = PAGE_ALIGN((dword_t)block);
 
-    acquire_lock(&mem_tree_lock);
+    lock_acquire(&mem_tree_lock);
     clear_bit(mem_tree_bitmap, index);
 
     for (i = page; i < page + PAGE_SIZE; i += sizeof(memory_block_t))
@@ -517,7 +518,7 @@ static void mem_tree_free(memory_block_t *block)
     }
 
     if (!busy) free_page((void*)page);
-    release_lock(&mem_tree_lock);
+    lock_release(&mem_tree_lock);
 }
 
 static memory_block_t *find_block_by_addr_internal(memory_block_t *block, void *address)
@@ -621,7 +622,7 @@ static inline void release_memory_block(memory_block_t *block)
         }
     }
 
-    acquire_lock(&page_store_lock);
+    lock_acquire(&page_store_lock);
 
     for (i = page_stores.next; i != &page_stores; i = i->next)
     {
@@ -643,7 +644,7 @@ static inline void release_memory_block(memory_block_t *block)
         }
     }
 
-    release_lock(&page_store_lock);
+    lock_release(&page_store_lock);
 }
 
 static void free_blocks_recursive(memory_block_t *block)
@@ -890,12 +891,12 @@ dword_t map_memory_in_address_space(memory_address_space_t *address_space,
     if (*virtual != NULL && PAGE_OFFSET((uintptr_t)*virtual) != PAGE_OFFSET((uintptr_t)physical)) return ERR_INVALID;
 
     size = (PAGE_ALIGN_UP((uintptr_t)physical + size - 1) - aligned_physical) >> 12;
-    acquire_resource_exclusive(&address_space->resource);
+    lock_acquire(&address_space->lock);
 
     memory_block_t *block = find_free_block(address_space, address, size);
     if (block == NULL)
     {
-        release_resource(&address_space->resource);
+        lock_release(&address_space->lock);
         return ERR_NOMEMORY;
     }
 
@@ -910,7 +911,7 @@ dword_t map_memory_in_address_space(memory_address_space_t *address_space,
     ret = map_memory_internal((void*)aligned_physical, (void*)real_address, size * PAGE_SIZE, flags);
     if (ret != ERR_SUCCESS)
     {
-        release_resource(&address_space->resource);
+        lock_release(&address_space->lock);
         return ret;
     }
 
@@ -953,7 +954,7 @@ dword_t map_memory_in_address_space(memory_address_space_t *address_space,
     block->flags = block_flags;
     *virtual = (void*)((dword_t)block->address + PAGE_OFFSET((uintptr_t)physical));
 
-    release_resource(&address_space->resource);
+    lock_release(&address_space->lock);
     return ERR_SUCCESS;
 }
 
@@ -965,14 +966,14 @@ dword_t pin_memory(const void *virtual, void **pinned, uintptr_t size, bool_t lo
     size = PAGE_ALIGN_UP(size) >> 12;
 
     memory_address_space_t *address_space = check_usermode(virtual, 1) ? &get_current_process()->memory_space : &kernel_address_space;
-    acquire_resource_shared(&address_space->resource);
-    acquire_resource_exclusive(&mapping_space.resource);
+    lock_acquire_shared(&address_space->lock);
+    lock_acquire(&mapping_space.lock);
 
     memory_block_t *block = find_free_block(&mapping_space, address, size);
     if (block == NULL)
     {
-        release_resource(&address_space->resource);
-        release_resource(&mapping_space.resource);
+        lock_release(&address_space->lock);
+        lock_release(&mapping_space.lock);
         return ERR_NOMEMORY;
     }
 
@@ -1038,27 +1039,27 @@ dword_t pin_memory(const void *virtual, void **pinned, uintptr_t size, bool_t lo
     if (!lock_contents) block->flags |= MEMORY_BLOCK_WRITABLE;
     *pinned = (void*)((dword_t)block->address) + PAGE_OFFSET((uintptr_t)virtual);
 
-    release_resource(&address_space->resource);
-    release_resource(&mapping_space.resource);
+    lock_release(&address_space->lock);
+    lock_release(&mapping_space.lock);
     return ERR_SUCCESS;
 }
 
 dword_t unmap_memory_in_address_space(memory_address_space_t *address_space, void *virtual)
 {
-    acquire_resource_exclusive(&mapping_space.resource);
+    lock_acquire(&mapping_space.lock);
     uintptr_t aligned_address = PAGE_ALIGN((uintptr_t)virtual);
 
     avl_node_t *node = avl_tree_lookup(&mapping_space.by_addr_tree, &aligned_address);
     if (node == NULL)
     {
-        release_resource(&mapping_space.resource);
+        lock_release(&mapping_space.lock);
         return ERR_INVALID;
     }
 
     memory_block_t *mem_block = CONTAINER_OF(node, memory_block_t, by_addr_node);
     if (mem_block->flags & MEMORY_BLOCK_FREE)
     {
-        release_resource(&mapping_space.resource);
+        lock_release(&mapping_space.lock);
         return ERR_INVALID;
     }
 
@@ -1068,7 +1069,7 @@ dword_t unmap_memory_in_address_space(memory_address_space_t *address_space, voi
     mem_block = combine_blocks_backward(mem_block);
     mem_block = combine_blocks_forward(mem_block);
 
-    release_resource(&mapping_space.resource);
+    lock_release(&mapping_space.lock);
     return ERR_SUCCESS;
 }
 
@@ -1095,12 +1096,12 @@ dword_t alloc_memory_in_address_space(memory_address_space_t *address_space,
     size = PAGE_ALIGN_UP(size) >> 12;
     if (size == 0) return ERR_INVALID;
 
-    acquire_resource_exclusive(&address_space->resource);
+    lock_acquire(&address_space->lock);
 
     memory_block_t *block = find_free_block(address_space, base_address, size);
     if (block == NULL)
     {
-        release_resource(&address_space->resource);
+        lock_release(&address_space->lock);
         return ERR_NOMEMORY;
     }
 
@@ -1156,26 +1157,26 @@ dword_t alloc_memory_in_address_space(memory_address_space_t *address_space,
     *address = (void*)((dword_t)block->address);
     if (block_flags & MEMORY_BLOCK_EVICTABLE) list_append(&address_space->evictable_blocks, &block->evict_link);
 
-    release_resource(&address_space->resource);
+    lock_release(&address_space->lock);
     return ERR_SUCCESS;
 }
 
 dword_t free_memory_in_address_space(memory_address_space_t *address_space, void *address)
 {
-    acquire_resource_exclusive(&address_space->resource);
+    lock_acquire(&address_space->lock);
     uintptr_t aligned_address = PAGE_ALIGN((uintptr_t)address);
 
     avl_node_t *node = avl_tree_lookup(&address_space->by_addr_tree, &aligned_address);
     if (node == NULL)
     {
-        release_resource(&address_space->resource);
+        lock_release(&address_space->lock);
         return ERR_INVALID;
     }
 
     memory_block_t *mem_block = CONTAINER_OF(node, memory_block_t, by_addr_node);
     if (mem_block->flags & MEMORY_BLOCK_FREE)
     {
-        release_resource(&address_space->resource);
+        lock_release(&address_space->lock);
         return ERR_INVALID;
     }
 
@@ -1187,7 +1188,7 @@ dword_t free_memory_in_address_space(memory_address_space_t *address_space, void
     mem_block = combine_blocks_backward(mem_block);
     mem_block = combine_blocks_forward(mem_block);
 
-    release_resource(&address_space->resource);
+    lock_release(&address_space->lock);
     return ERR_SUCCESS;
 }
 
@@ -1385,13 +1386,13 @@ sysret_t syscall_commit_memory(handle_t process, void *address, dword_t size)
     }
 
     if (proc->terminating) return ERR_CANCELED;
-    acquire_resource_shared(&proc->memory_space.resource);
+    lock_acquire_shared(&proc->memory_space.lock);
 
     process_t *prev_proc = switch_process(proc);
     ret = commit_pages(address, size);
     switch_process(prev_proc);
 
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1414,13 +1415,13 @@ sysret_t syscall_uncommit_memory(handle_t process, void *address, dword_t size)
     }
 
     if (proc->terminating) return ERR_CANCELED;
-    acquire_resource_shared(&proc->memory_space.resource);
+    lock_acquire_shared(&proc->memory_space.lock);
 
     process_t *prev_proc = switch_process(proc);
     ret = uncommit_pages(address, size);
     switch_process(prev_proc);
 
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1444,7 +1445,7 @@ sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags
     }
 
     process_t *prev_proc = switch_process(proc);
-    acquire_resource_exclusive(&proc->memory_space.resource);
+    lock_acquire(&proc->memory_space.lock);
 
     memory_block_t *block = find_block_by_addr(&proc->memory_space, address);
     if (block == NULL)
@@ -1497,7 +1498,7 @@ sysret_t syscall_set_memory_flags(handle_t process, void *address, dword_t flags
     block->flags |= flags;
 
 cleanup:
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     switch_process(prev_proc);
     dereference(&proc->header);
     return ret;
@@ -1523,7 +1524,7 @@ sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info
         reference(&proc->header);
     }
 
-    acquire_resource_shared(&proc->memory_space.resource);
+    lock_acquire_shared(&proc->memory_space.lock);
 
     memory_block_t *block = find_block_by_addr(&proc->memory_space, address);
     if (block == NULL)
@@ -1545,7 +1546,7 @@ sysret_t syscall_query_memory(handle_t process, void *address, memory_block_info
     EH_DONE;
 
 cleanup:
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1575,7 +1576,7 @@ sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dwor
     if (!reference_by_handle(process, OBJECT_PROCESS, (object_t**)&proc)) return ERR_INVALID;
     if (proc->terminating) return ERR_CANCELED;
 
-    acquire_resource_shared(&proc->memory_space.resource);
+    lock_acquire_shared(&proc->memory_space.lock);
 
     dword_t page;
     dword_t first_page = PAGE_ALIGN((dword_t)address);
@@ -1604,7 +1605,7 @@ sysret_t syscall_read_memory(handle_t process, void *address, void *buffer, dwor
         if (ret != ERR_SUCCESS) break;
     }
 
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1634,7 +1635,7 @@ sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dwo
     if (!reference_by_handle(process, OBJECT_PROCESS, (object_t**)&proc)) return ERR_INVALID;
     if (proc->terminating) return ERR_CANCELED;
 
-    acquire_resource_exclusive(&proc->memory_space.resource);
+    lock_acquire(&proc->memory_space.lock);
 
     dword_t page;
     dword_t first_page = PAGE_ALIGN((dword_t)address);
@@ -1663,7 +1664,7 @@ sysret_t syscall_write_memory(handle_t process, void *address, void *buffer, dwo
         if (ret != ERR_SUCCESS) break;
     }
 
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1899,7 +1900,7 @@ sysret_t syscall_flush_memory_section(handle_t process, void *address)
         reference(&proc->header);
     }
 
-    acquire_resource_shared(&proc->memory_space.resource);
+    lock_acquire_shared(&proc->memory_space.lock);
 
     memory_block_t *block = find_block_by_addr(&proc->memory_space, address);
     if (block == NULL || block->section == NULL)
@@ -1922,14 +1923,14 @@ sysret_t syscall_flush_memory_section(handle_t process, void *address)
         if (ret != ERR_SUCCESS) continue;
 
         file_instance_t *file = block->section->file;
-        acquire_resource_exclusive(&file->global->volume->resource);
+        lock_acquire(&file->global->volume->lock);
         ret = file->global->volume->driver->write_file(file, buffer, shared->offset, PAGE_SIZE, &bytes_written);
-        release_resource(&file->global->volume->resource);
+        lock_release(&file->global->volume->lock);
         if (ret != ERR_SUCCESS) break;
     }
 
 cleanup:
-    release_resource(&proc->memory_space.resource);
+    lock_release(&proc->memory_space.lock);
     dereference(&proc->header);
     return ret;
 }
@@ -1997,9 +1998,9 @@ sysret_t syscall_add_page_file(const char *path, dword_t max_entries)
         goto cleanup;
     }
 
-    acquire_lock(&page_store_lock);
+    lock_acquire(&page_store_lock);
     list_append(&page_stores, &store->link);
-    release_lock(&page_store_lock);
+    lock_release(&page_store_lock);
 
 cleanup:
     if (get_previous_mode() == USER_MODE) free(safe_path);
@@ -2034,7 +2035,7 @@ sysret_t syscall_remove_page_file(const char *path)
     list_entry_t *ptr;
     page_store_t *store;
 
-    acquire_lock(&page_store_lock);
+    lock_acquire(&page_store_lock);
 
     for (ptr = page_stores.next; ptr != &page_stores; ptr = ptr->next)
     {
@@ -2066,12 +2067,12 @@ sysret_t syscall_remove_page_file(const char *path)
     if (ptr == &page_stores)
     {
         ret = ERR_NOTFOUND;
-        release_lock(&page_store_lock);
+        lock_release(&page_store_lock);
         goto cleanup;
     }
 
     list_remove(&store->link);
-    release_lock(&page_store_lock);
+    lock_release(&page_store_lock);
 
     for (ptr = store->entry_list.next; ptr != &store->entry_list; ptr = ptr->next)
     {
@@ -2084,7 +2085,7 @@ sysret_t syscall_remove_page_file(const char *path)
         ret = syscall_read_file(store->file_handle, buffer, (qword_t)entry->number * (qword_t)PAGE_SIZE, PAGE_SIZE, &bytes_read);
         if (ret != ERR_SUCCESS) break;
 
-        acquire_resource_exclusive(&entry->address_space->resource);
+        lock_acquire(&entry->address_space->lock);
         memory_block_t *block = find_block_by_addr(entry->address_space, entry->address);
 
         if (block->flags & MEMORY_BLOCK_ACCESSIBLE) page_flags |= PAGE_PRESENT;
@@ -2128,7 +2129,7 @@ sysret_t syscall_remove_page_file(const char *path)
 
 loop_cleanup:
         if (entry->address_space != &kernel_address_space) switch_process(old_process);
-        release_resource(&entry->address_space->resource);
+        lock_release(&entry->address_space->lock);
     }
 
     free(store);
@@ -2136,9 +2137,9 @@ loop_cleanup:
 cleanup:
     if (ret != ERR_SUCCESS)
     {
-        acquire_lock(&page_store_lock);
+        lock_acquire(&page_store_lock);
         list_append(&page_stores, &store->link);
-        release_lock(&page_store_lock);
+        lock_release(&page_store_lock);
     }
 
     if (get_previous_mode() == USER_MODE) free(safe_path);
@@ -2173,7 +2174,7 @@ dword_t create_address_space(void *base_address, dword_t page_count, memory_addr
     mem_space->pool_size = page_count;
     AVL_TREE_INIT(&mem_space->by_addr_tree, memory_block_t, by_addr_node, address, compare_address);
     AVL_TREE_INIT(&mem_space->by_size_tree, memory_block_t, by_size_node, size, compare_size);
-    mem_space->resource = 0;
+    lock_init(&mem_space->lock);
     list_init(&mem_space->evictable_blocks);
     mem_space->evict_blk_ptr = NULL;
     mem_space->evict_page_num = 0;
@@ -2220,13 +2221,13 @@ dword_t clone_address_space(memory_address_space_t *original, memory_address_spa
     dword_t i;
     dword_t ret = ERR_SUCCESS;
 
-    acquire_resource_shared(&original->resource);
+    lock_acquire_shared(&original->lock);
 
     clone->pool_address = original->pool_address;
     clone->pool_size = original->pool_size;
     AVL_TREE_INIT(&clone->by_addr_tree, memory_block_t, by_addr_node, address, NULL);
     AVL_TREE_INIT(&clone->by_size_tree, memory_block_t, by_size_node, size, NULL);
-    clone->resource = 0;
+    lock_init(&clone->lock);
     list_init(&clone->evictable_blocks);
     clone->evict_blk_ptr = NULL;
     clone->evict_page_num = 0;
@@ -2271,7 +2272,7 @@ dword_t clone_address_space(memory_address_space_t *original, memory_address_spa
     list_append(&user_address_spaces, &clone->link);
 
 cleanup:
-    release_resource(&original->resource);
+    lock_release(&original->lock);
     return ret;
 }
 
@@ -2284,7 +2285,7 @@ void bump_address_space(memory_address_space_t *mem_space)
 void delete_address_space(memory_address_space_t *mem_space)
 {
     ASSERT(get_page_directory() != mem_space->page_directory);
-    acquire_resource_exclusive(&mem_space->resource);
+    lock_acquire(&mem_space->lock);
 
     if (mem_space->by_addr_tree.root)
     {
@@ -2296,7 +2297,7 @@ void delete_address_space(memory_address_space_t *mem_space)
     free_physical_page(mem_space->page_directory);
     mem_space->page_directory = NULL;
 
-    release_resource(&mem_space->resource);
+    lock_release(&mem_space->lock);
 }
 
 static bool_t find_evicted_page(memory_block_t *block, void *address, page_store_t **store, page_store_entry_t **entry)
@@ -2474,9 +2475,9 @@ bool_t memory_fault_handler(void *address, registers_t *regs)
             {
                 enable_ints();
                 file_instance_t *file = block->section->file;
-                acquire_resource_shared(&file->global->volume->resource);
+                lock_acquire_shared(&file->global->volume->lock);
                 dword_t ret = file->global->volume->driver->read_file(file, buffer, offset, PAGE_SIZE, &bytes_read);
-                release_resource(&file->global->volume->resource);
+                lock_release(&file->global->volume->lock);
                 disable_ints();
                 if (ret != ERR_SUCCESS && ret != ERR_BEYOND) return FALSE;
             }
index 55a954769df4904481e8d3dd47a37bf6addf5444..649c0d2ba2471c369a47370c45c57ef656363bcb 100644 (file)
@@ -32,7 +32,7 @@ extern void file_instance_cleanup(object_t*);
 extern dword_t semaphore_pre_wait(object_t *obj, void *parameter, wait_condition_t *condition);
 extern void semaphore_post_wait(object_t *obj, void *parameter, wait_result_t result);
 
-static lock_t obj_lock = 0;
+static DECLARE_LOCK(obj_lock);
 static DECLARE_LIST(anonymous_objects);
 static list_entry_t named_objects[256];
 static list_entry_t objects_by_type[OBJECT_TYPE_MAX];
@@ -67,7 +67,7 @@ static handle_t insert_object(object_t *obj, access_flags_t access_flags)
     handle_t i;
     process_t *proc = get_previous_mode() == USER_MODE ? get_current_process() : kernel_process;
 
-    acquire_resource_exclusive(&proc->handle_table_res);
+    lock_acquire(&proc->handle_table_lock);
 
     for (i = 0; i < proc->handle_table_size; i++) if (!proc->handle_table[i].obj)
     {
@@ -92,7 +92,7 @@ static handle_t insert_object(object_t *obj, access_flags_t access_flags)
     proc->handle_table_size *= 2;
 
 cleanup:
-    release_resource(&proc->handle_table_res);
+    lock_release(&proc->handle_table_lock);
     return i;
 }
 
@@ -114,14 +114,14 @@ static bool_t access_check(object_t *obj, access_flags_t access)
 
 void reference(object_t *object)
 {
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
     object->ref_count++;
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
 }
 
 void dereference(object_t *object)
 {
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
     dword_t ref_count = --object->ref_count;
 
     if (!ref_count)
@@ -130,7 +130,7 @@ void dereference(object_t *object)
         list_remove(&object->by_type_list);
     }
 
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
 
     if (!ref_count)
     {
@@ -145,8 +145,8 @@ bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **objec
     process_t *proc = get_previous_mode() == USER_MODE ? get_current_process() : kernel_process;
 
     if (handle >= proc->handle_table_size) return FALSE;
-    acquire_lock(&obj_lock);
-    acquire_resource_shared(&proc->handle_table_res);
+    lock_acquire(&obj_lock);
+    lock_acquire_shared(&proc->handle_table_lock);
 
     *object = proc->handle_table[handle].obj;
     if (*object != NULL && (type == OBJECT_ANY_TYPE || (*object)->type == type))
@@ -155,8 +155,8 @@ bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **objec
         result = TRUE;
     }
 
-    release_resource(&proc->handle_table_res);
-    release_lock(&obj_lock);
+    lock_release(&proc->handle_table_lock);
+    lock_release(&obj_lock);
     return result;
 }
 
@@ -166,7 +166,7 @@ bool_t reference_by_name(const char *name, object_type_t type, object_t **object
     bool_t result = FALSE;
     byte_t hash = get_name_hash(name);
 
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
 
     for (ptr = named_objects[hash].next; ptr != &named_objects[hash]; ptr = ptr->next)
     {
@@ -181,7 +181,7 @@ bool_t reference_by_name(const char *name, object_type_t type, object_t **object
         }
     }
 
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
     return result;
 }
 
@@ -189,7 +189,7 @@ dword_t grant_access(object_t *obj, dword_t uid, access_flags_t access)
 {
     dword_t ret = ERR_SUCCESS;
     reference(obj);
-    acquire_lock(&obj->acl_lock);
+    lock_acquire(&obj->acl_lock);
 
     if (!access_check(obj, access))
     {
@@ -226,7 +226,7 @@ dword_t grant_access(object_t *obj, dword_t uid, access_flags_t access)
     }
 
 cleanup:
-    release_lock(&obj->acl_lock);
+    lock_release(&obj->acl_lock);
     dereference(obj);
     return ret;
 }
@@ -235,7 +235,7 @@ dword_t revoke_access(object_t *obj, dword_t uid, access_flags_t access)
 {
     dword_t ret = ERR_SUCCESS;
     reference(obj);
-    acquire_lock(&obj->acl_lock);
+    lock_acquire(&obj->acl_lock);
 
     if (get_current_uid() != obj->owner)
     {
@@ -261,7 +261,7 @@ dword_t revoke_access(object_t *obj, dword_t uid, access_flags_t access)
     }
 
 cleanup:
-    release_lock(&obj->acl_lock);
+    lock_release(&obj->acl_lock);
     dereference(obj);
     return ret;
 }
@@ -289,11 +289,11 @@ dword_t create_object(object_t *obj)
     ace->access_mask = FULL_ACCESS;
     list_append(&obj->acl, &ace->link);
 
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
     if (obj->name) list_append(&named_objects[get_name_hash(obj->name)], &obj->by_name_list);
     else list_append(&anonymous_objects, &obj->by_name_list);
     list_append(&objects_by_type[obj->type], &obj->by_type_list);
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
 
     return ERR_SUCCESS;
 }
@@ -301,7 +301,7 @@ dword_t create_object(object_t *obj)
 dword_t open_object(object_t *obj, access_flags_t access_flags, handle_t *handle)
 {
     dword_t ret = ERR_SUCCESS;
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
 
     if (!access_check(obj, access_flags))
     {
@@ -321,7 +321,7 @@ dword_t open_object(object_t *obj, access_flags_t access_flags, handle_t *handle
     obj->open_count++;
 
 done:
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
     return ret;
 }
 
@@ -331,7 +331,7 @@ dword_t open_object_by_name(const char *name, object_type_t type, access_flags_t
     object_t *obj;
 
     if (!reference_by_name(name, type, &obj)) return ERR_NOTFOUND;
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
 
     if (!access_check(obj, access_flags))
     {
@@ -350,14 +350,14 @@ dword_t open_object_by_name(const char *name, object_type_t type, access_flags_t
     obj->open_count++;
 
 done:
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
     if (ret != ERR_SUCCESS) dereference(obj);
     return ret;
 }
 
 void close_object_internal(object_t *obj)
 {
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
 
     obj->open_count--;
     qword_t ref_count = --obj->ref_count;
@@ -369,7 +369,7 @@ void close_object_internal(object_t *obj)
         list_remove(&obj->by_type_list);
     }
 
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
 
     if (!ref_count)
     {
@@ -384,11 +384,11 @@ sysret_t syscall_close_object(handle_t handle)
     process_t *proc = get_previous_mode() == USER_MODE ? get_current_process() : kernel_process;
 
     reference(&proc->header);
-    acquire_resource_exclusive(&proc->handle_table_res);
+    lock_acquire(&proc->handle_table_lock);
 
     if (handle >= proc->handle_table_size)
     {
-        release_resource(&proc->handle_table_res);
+        lock_release(&proc->handle_table_lock);
         dereference(&proc->header);
         return ERR_NOTFOUND;
     }
@@ -407,7 +407,7 @@ sysret_t syscall_close_object(handle_t handle)
         ret = ERR_NOTFOUND;
     }
 
-    release_resource(&proc->handle_table_res);
+    lock_release(&proc->handle_table_lock);
     dereference(&proc->header);
 
     return ret;
@@ -434,7 +434,7 @@ sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *bu
     }
 
     reference(&proc->header);
-    acquire_resource_exclusive(&proc->handle_table_res);
+    lock_acquire(&proc->handle_table_lock);
 
     object_t *obj = proc->handle_table[handle].obj;
     if (obj == NULL)
@@ -469,7 +469,7 @@ sysret_t syscall_query_handle(handle_t handle, handle_info_type_t type, void *bu
     }
 
 cleanup:
-    release_resource(&proc->handle_table_res);
+    lock_release(&proc->handle_table_lock);
     dereference(&proc->header);
     if (get_previous_mode() == USER_MODE) free(safe_buffer);
     return ret;
@@ -495,11 +495,11 @@ sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, hand
         reference(&proc->header);
     }
 
-    acquire_resource_shared(&proc->handle_table_res);
+    lock_acquire_shared(&proc->handle_table_lock);
 
     if (handle >= proc->handle_table_size)
     {
-        release_resource(&proc->handle_table_res);
+        lock_release(&proc->handle_table_lock);
         dereference(&proc->header);
         return ERR_INVALID;
     }
@@ -508,14 +508,14 @@ sysret_t syscall_duplicate_handle(handle_t source_process, handle_t handle, hand
     access_flags_t access_flags = proc->handle_table[handle].access_flags;
     if (obj == NULL)
     {
-        release_resource(&proc->handle_table_res);
+        lock_release(&proc->handle_table_lock);
         dereference(&proc->header);
         return ERR_INVALID;
     }
 
     reference(obj);
 
-    release_resource(&proc->handle_table_res);
+    lock_release(&proc->handle_table_lock);
     dereference(&proc->header);
 
     if (dest_process != INVALID_HANDLE)
@@ -558,7 +558,7 @@ dword_t enum_objects_by_type(object_type_t type, object_t **object)
     list_entry_t *ptr;
     object_t *previous = *object;
 
-    acquire_lock(&obj_lock);
+    lock_acquire(&obj_lock);
 
     if (previous == NULL) ptr = objects_by_type[type].next;
     else ptr = previous->by_type_list.next;
@@ -574,7 +574,7 @@ dword_t enum_objects_by_type(object_type_t type, object_t **object)
         ret = ERR_NOMORE;
     }
 
-    release_lock(&obj_lock);
+    lock_release(&obj_lock);
 
     if (*object) reference(*object);
     if (previous) dereference(previous);
index f0609f37926050d80e0e816555e125633bf81b5a..aaa6635f443e5b0accf336fca872fe20ca5870eb 100644 (file)
@@ -48,17 +48,17 @@ dword_t read_pipe(pipe_t *pipe, void *buffer, size_t *size, dword_t timeout)
 {
     dword_t ret = ERR_SUCCESS;
     size_t requested_size = *size;
-    acquire_lock(&pipe->lock);
+    lock_acquire(&pipe->lock);
 
     if (pipe->flags & PIPE_MESSAGE)
     {
         if (pipe->fifo.next == &pipe->fifo)
         {
-            release_lock(&pipe->lock);
+            lock_release(&pipe->lock);
             wait_condition_t condition = { .type = WAIT_UNTIL_NOT_EQUAL, .pointer = (dword_t*)&pipe->fifo.next, .value = 0 };
             wait_result_t status = scheduler_wait(&condition, timeout);
             if (status != ERR_SUCCESS) return (status == WAIT_TIMED_OUT) ? ERR_TIMEOUT : ERR_CANCELED;
-            acquire_lock(&pipe->lock);
+            lock_acquire(&pipe->lock);
         }
 
         pipe_message_entry_t *entry = CONTAINER_OF(pipe->fifo.next, pipe_message_entry_t, link);
@@ -84,11 +84,11 @@ dword_t read_pipe(pipe_t *pipe, void *buffer, size_t *size, dword_t timeout)
         {
             if (pipe->fifo.next == &pipe->fifo)
             {
-                release_lock(&pipe->lock);
+                lock_release(&pipe->lock);
                 wait_condition_t condition = { .type = WAIT_UNTIL_NOT_EQUAL, .pointer = (dword_t*)&pipe->fifo.next, .value = 0 };
                 wait_result_t status = scheduler_wait(&condition, timeout);
                 if (status != ERR_SUCCESS) return (status == WAIT_TIMED_OUT) ? ERR_TIMEOUT : ERR_CANCELED;
-                acquire_lock(&pipe->lock);
+                lock_acquire(&pipe->lock);
             }
 
             pipe_fifo_entry_t *entry = CONTAINER_OF(pipe->fifo.next, pipe_fifo_entry_t, link);
@@ -111,7 +111,7 @@ dword_t read_pipe(pipe_t *pipe, void *buffer, size_t *size, dword_t timeout)
     pipe->bytes_ready -= *size;
 
 cleanup:
-    release_lock(&pipe->lock);
+    lock_release(&pipe->lock);
     return ret;
 }
 
@@ -120,7 +120,7 @@ dword_t write_pipe(pipe_t *pipe, const void *buffer, size_t size)
     dword_t ret = ERR_SUCCESS;
     dword_t count = 0;
 
-    acquire_lock(&pipe->lock);
+    lock_acquire(&pipe->lock);
 
     if (pipe->flags & PIPE_MESSAGE)
     {
@@ -171,7 +171,7 @@ dword_t write_pipe(pipe_t *pipe, const void *buffer, size_t size)
     pipe->bytes_ready += count;
 
 cleanup:
-    release_lock(&pipe->lock);
+    lock_release(&pipe->lock);
     return ret;
 }
 
@@ -230,7 +230,7 @@ sysret_t syscall_create_pipeline(const char *name, dword_t flags, access_flags_t
 
     init_object(&pipeline->header, safe_name, OBJECT_PIPELINE);
     pipeline->flags = flags;
-    pipeline->lock = 0;
+    lock_init(&pipeline->lock);
     pipeline->status = PIPELINE_IDLE;
 
     ret = create_object(&pipeline->header);
@@ -326,10 +326,10 @@ static dword_t pipeline_create_pipes(pipeline_t *pipeline)
 
 static dword_t connect_to_pipeline(pipeline_t *pipeline, pipe_connection_t *conn)
 {
-    ASSERT(pipeline->lock);
+    lock_acquire_smart(&pipeline->lock);
 
     dword_t ret = open_object(&pipeline->request_pipe->header, 0, &conn->request_pipe);
-    if (ret != ERR_SUCCESS) return ret;
+    if (ret != ERR_SUCCESS) goto cleanup;
 
     if (pipeline->response_pipe)
     {
@@ -337,6 +337,8 @@ static dword_t connect_to_pipeline(pipeline_t *pipeline, pipe_connection_t *conn
         if (ret != ERR_SUCCESS) syscall_close_object(conn->response_pipe);
     }
 
+cleanup:
+    lock_release(&pipeline->lock);
     return ret;
 }
 
@@ -357,11 +359,11 @@ sysret_t syscall_listen_pipeline(handle_t handle, dword_t timeout, pipe_connecti
     pipeline_t *pipeline;
     if (!reference_by_handle(handle, OBJECT_PIPELINE, (object_t**)&pipeline)) return ERR_INVALID;
 
-    acquire_lock(&pipeline->lock);
+    lock_acquire_smart(&pipeline->lock);
 
     if (pipeline->status != PIPELINE_IDLE)
     {
-        release_lock(&pipeline->lock);
+        lock_release(&pipeline->lock);
         dereference(&pipeline->header);
         return ERR_BUSY;
     }
@@ -371,11 +373,11 @@ sysret_t syscall_listen_pipeline(handle_t handle, dword_t timeout, pipe_connecti
     pipeline->request_pipe = pipeline->response_pipe = NULL;
 
     pipeline->status = PIPELINE_ACCEPTING;
-    release_lock(&pipeline->lock);
+    lock_release(&pipeline->lock);
 
     wait_condition_t condition = { .type = WAIT_UNTIL_NOT_EQUAL, .pointer = &pipeline->status, .value = PIPELINE_ACCEPTING };
     wait_result_t result = scheduler_wait(&condition, timeout);
-    acquire_lock(&pipeline->lock);
+    lock_acquire_smart(&pipeline->lock);
 
     if (pipeline->status != PIPELINE_CONNECTING)
     {
@@ -422,7 +424,7 @@ cleanup:
     if (pipeline->response_pipe) dereference(&pipeline->response_pipe->header);
     pipeline->request_pipe = pipeline->response_pipe = NULL;
 
-    release_lock(&pipeline->lock);
+    lock_release(&pipeline->lock);
     dereference(&pipeline->header);
     return ret;
 }
@@ -449,7 +451,7 @@ sysret_t syscall_connect_pipeline(handle_t handle, access_flags_t access, pipe_c
         goto cleanup;
     }
 
-    acquire_lock(&pipeline->lock);
+    lock_acquire_smart(&pipeline->lock);
 
     if (pipeline->status != PIPELINE_ACCEPTING)
     {
@@ -494,7 +496,7 @@ sysret_t syscall_connect_pipeline(handle_t handle, access_flags_t access, pipe_c
     }
 
 cleanup:
-    release_lock(&pipeline->lock);
+    lock_release(&pipeline->lock);
     if (pipeline) dereference(&pipeline->header);
     return ret;
 }
index bd10219537532712ba7e107c21ef617dbc48c524..cc9004d901b06ec512c3a3fa69ae7452fc40c62c 100644 (file)
@@ -31,7 +31,7 @@ dword_t load_aout(handle_t file, thread_state_t *initial_state);
 typedef dword_t (*loader_proc)(handle_t, thread_state_t*);
 
 static dword_t pid_alloc_bitmap[MAX_PROCESSES / 32];
-static lock_t pid_bitmap_lock = 0;
+static DECLARE_LOCK(pid_bitmap_lock);
 
 static loader_proc loaders[] =
 {
@@ -47,7 +47,7 @@ static dword_t alloc_pid()
     int i;
     dword_t pid = (dword_t)-1;
 
-    acquire_lock(&pid_bitmap_lock);
+    lock_acquire(&pid_bitmap_lock);
 
     for (i = 0; i < MAX_PROCESSES; i++)
     {
@@ -59,7 +59,7 @@ static dword_t alloc_pid()
         }
     }
 
-    release_lock(&pid_bitmap_lock);
+    lock_release(&pid_bitmap_lock);
     return pid;
 }
 
@@ -70,7 +70,7 @@ void destroy_process(process_t *proc)
 
     delete_address_space(&proc->memory_space);
 
-    acquire_resource_exclusive(&proc->handle_table_res);
+    lock_acquire(&proc->handle_table_lock);
 
     for (i = 0; i < proc->handle_table_size / sizeof(proc->handle_table[i]); i++)
     {
@@ -83,7 +83,7 @@ void destroy_process(process_t *proc)
         }
     }
 
-    release_resource(&proc->handle_table_res);
+    lock_release(&proc->handle_table_lock);
 
     proc->terminated = TRUE;
     dereference(&proc->header);
@@ -96,9 +96,9 @@ void process_cleanup(object_t *obj)
     free(proc->name);
     dereference(&proc->current_user->header);
 
-    acquire_lock(&pid_bitmap_lock);
+    lock_acquire(&pid_bitmap_lock);
     clear_bit(pid_alloc_bitmap, proc->pid);
-    release_lock(&pid_bitmap_lock);
+    lock_release(&pid_bitmap_lock);
 }
 
 dword_t process_pre_wait(object_t *obj, void *parameter, wait_condition_t *condition)
@@ -267,7 +267,7 @@ sysret_t syscall_create_process(const char *path, dword_t flags, process_params_
     proc->name = strdup(path ? path : get_current_process()->name);
 
     list_init(&proc->threads);
-    proc->thread_list_res = 0;
+    lock_init(&proc->thread_list_lock);
 
     reference(&current->current_user->header);
     proc->original_user = proc->current_user = current->current_user;
@@ -275,13 +275,13 @@ sysret_t syscall_create_process(const char *path, dword_t flags, process_params_
     if (!(flags & PROCESS_CREATE_NO_INHERIT) && current != kernel_process)
     {
         dword_t i;
-        acquire_resource_shared(&current->handle_table_res);
+        lock_acquire_shared(&current->handle_table_lock);
 
         proc->handle_table = (handle_info_t*)heap_alloc(&evictable_heap, STARTUP_HANDLE_TABLE_SIZE);
         memset(proc->handle_table, 0, current->handle_table_size);
         proc->handle_table_size = current->handle_table_size;
         proc->handle_count = current->handle_count;
-        proc->handle_table_res = 0;
+        lock_init(&proc->handle_table_lock);
 
         for (i = 0; i < current->handle_table_size; i++)
         {
@@ -293,7 +293,7 @@ sysret_t syscall_create_process(const char *path, dword_t flags, process_params_
             }
         }
 
-        release_resource(&current->handle_table_res);
+        lock_release(&current->handle_table_lock);
     }
     else
     {
@@ -301,7 +301,7 @@ sysret_t syscall_create_process(const char *path, dword_t flags, process_params_
         memset(proc->handle_table, 0, STARTUP_HANDLE_TABLE_SIZE);
         proc->handle_table_size = STARTUP_HANDLE_TABLE_SIZE;
         proc->handle_count = 0;
-        proc->handle_table_res = 0;
+        lock_init(&proc->handle_table_lock);
     }
 
     if (safe_path)
@@ -407,9 +407,9 @@ cleanup:
 
         if (proc->pid != (dword_t)-1)
         {
-            acquire_lock(&pid_bitmap_lock);
+            lock_acquire(&pid_bitmap_lock);
             clear_bit(pid_alloc_bitmap, proc->pid);
-            release_lock(&pid_bitmap_lock);
+            lock_release(&pid_bitmap_lock);
         }
 
         if (proc->name) free(proc->name);
@@ -444,7 +444,7 @@ sysret_t syscall_terminate(handle_t handle, dword_t exit_code)
     proc->exit_code = exit_code;
     syscall_clock_get_time(&proc->end_time);
 
-    acquire_resource_shared(&proc->thread_list_res);
+    lock_acquire_shared(&proc->thread_list_lock);
 
     while (proc->threads.next != &proc->threads)
     {
@@ -459,9 +459,9 @@ sysret_t syscall_terminate(handle_t handle, dword_t exit_code)
 
         if (ptr != &proc->threads)
         {
-            release_resource(&proc->thread_list_res);
+            lock_release(&proc->thread_list_lock);
             terminate_thread_internal(thread, exit_code);
-            acquire_resource_shared(&proc->thread_list_res);
+            lock_acquire_shared(&proc->thread_list_lock);
         }
         else
         {
@@ -469,7 +469,7 @@ sysret_t syscall_terminate(handle_t handle, dword_t exit_code)
         }
     }
 
-    release_resource(&proc->thread_list_res);
+    lock_release(&proc->thread_list_lock);
 
     if (proc->threads.next == &proc->threads) destroy_process(proc);
     dereference(&proc->header);
@@ -574,7 +574,7 @@ sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *
                 list_entry_t *ptr;
                 dword_t i = 1, count = 0;
 
-                acquire_resource_shared(&proc->thread_list_res);
+                lock_acquire_shared(&proc->thread_list_lock);
                 for (ptr = proc->threads.next; ptr != &proc->threads; ptr = ptr->next) count++;
                 *((dword_t*)safe_buffer) = count;
 
@@ -584,7 +584,7 @@ sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *
                 }
 
                 if (ptr != &proc->threads) ret = ERR_SMALLBUF;
-                release_resource(&proc->thread_list_res);
+                lock_release(&proc->thread_list_lock);
             }
             else
             {
@@ -600,7 +600,7 @@ sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *
             {
                 dword_t i, j = 1;
 
-                acquire_resource_shared(&proc->handle_table_res);
+                lock_acquire_shared(&proc->handle_table_lock);
                 *((dword_t*)safe_buffer) = proc->handle_count;
 
                 for (i = 0; i < proc->handle_table_size && j < (size / sizeof(dword_t)); i++)
@@ -609,7 +609,7 @@ sysret_t syscall_query_process(handle_t handle, process_info_t info_type, void *
                 }
 
                 if (i != proc->handle_table_size) ret = ERR_SMALLBUF;
-                release_resource(&proc->handle_table_res);
+                lock_release(&proc->handle_table_lock);
             }
             else
             {
@@ -746,10 +746,10 @@ void process_init(void)
     syscall_clock_get_time(&kernel_process->start_time);
 
     list_init(&kernel_process->threads);
-    kernel_process->thread_list_res = 0;
+    lock_init(&kernel_process->thread_list_lock);
 
     kernel_process->handle_table = (handle_info_t*)heap_alloc(&evictable_heap, STARTUP_HANDLE_TABLE_SIZE);
     kernel_process->handle_table_size = STARTUP_HANDLE_TABLE_SIZE;
     kernel_process->handle_count = 0;
-    kernel_process->handle_table_res = 0;
+    lock_init(&kernel_process->handle_table_lock);
 }
index 5753200eb0a2a0a2c30e76e74dc900744a4d3076..3d80c25670fb5d8dfc688f58e78ad91c752e3311 100644 (file)
@@ -28,6 +28,7 @@
 #include <power.h>
 #include <exception.h>
 #include <pipe.h>
+#include <semaphore.h>
 
 extern sysret_t syscall_function(const void*, dword_t*, dword_t);
 
index 8ceb4ef351214d6e037f1dcbb88cc72a0d868658..a1344bf3b853d6b727eb1d4b182ece7b11b7c57f 100644 (file)
@@ -33,14 +33,14 @@ static list_entry_t thread_queue[THREAD_PRIORITY_MAX];
 static thread_t *current_thread = NULL;
 static thread_t *last_fpu_thread = NULL;
 static dword_t tid_alloc_bitmap[MAX_THREADS / 32];
-static lock_t tid_bitmap_lock = 0;
+static DECLARE_LOCK(tid_bitmap_lock);
 
 static dword_t alloc_tid()
 {
     int i;
     dword_t tid = (dword_t)-1;
 
-    acquire_lock(&tid_bitmap_lock);
+    lock_acquire(&tid_bitmap_lock);
 
     for (i = 0; i < MAX_THREADS; i++)
     {
@@ -52,7 +52,7 @@ static dword_t alloc_tid()
         }
     }
 
-    release_lock(&tid_bitmap_lock);
+    lock_release(&tid_bitmap_lock);
     return tid;
 }
 
@@ -117,9 +117,9 @@ static void destroy_thread(thread_t *thread)
 {
     list_remove(&thread->in_queue_list);
 
-    acquire_resource_exclusive(&thread->owner_process->thread_list_res);
+    lock_acquire(&thread->owner_process->thread_list_lock);
     list_remove(&thread->in_process_list);
-    release_resource(&thread->owner_process->thread_list_res);
+    lock_release(&thread->owner_process->thread_list_lock);
 
     free(thread->kernel_stack);
     thread->kernel_stack = NULL;
@@ -205,9 +205,9 @@ dword_t create_thread_internal(process_t *proc, thread_state_t *initial_state, d
     thread->kernel_stack = kernel_stack;
     thread->kernel_esp = ((uintptr_t)thread->kernel_stack + KERNEL_STACK_SIZE + 3) & ~3;
 
-    acquire_resource_exclusive(&thread->owner_process->thread_list_res);
+    lock_acquire(&thread->owner_process->thread_list_lock);
     list_append(&proc->threads, &thread->in_process_list);
-    release_resource(&thread->owner_process->thread_list_res);
+    lock_release(&thread->owner_process->thread_list_lock);
 
     critical_t critical;
     enter_critical(&critical);
@@ -225,9 +225,9 @@ cleanup:
 
         if (thread->tid != (dword_t)-1)
         {
-            acquire_lock(&tid_bitmap_lock);
+            lock_acquire(&tid_bitmap_lock);
             clear_bit(tid_alloc_bitmap, thread->tid);
-            release_lock(&tid_bitmap_lock);
+            lock_release(&tid_bitmap_lock);
         }
     }
 
index 636d50e4be965fb1edff446a98ac3a585300edb2..2c1a713bc6bcbb17d31476f5f509c6afc2d54153 100644 (file)
@@ -163,7 +163,7 @@ static dword_t video_device_init(void)
 
             video->header.driver = &video_subsystem;
             sprintf(video->header.name, "Video%d", number);
-            video->header.resource = 0;
+            lock_init(&video->header.lock);
             video->pci_device = device;
             video->driver = &video_default_driver;
 
index 4d42a2d943b8a1d8b48e4cd1b400d8c2e5fdb63a..93b84814a44616cf71d20c1d74f2f4b9d91a48dc 100644 (file)
@@ -62,6 +62,7 @@
 #define MAX_ERR       0xE0000013
 
 #define MAX_PATH 16384
+#define NO_TIMEOUT 0xFFFFFFFF
 
 #define UNUSED_PARAMETER(x) (x)=(x)
 #define OFFSET_OF(type, field) ((uintptr_t)(&((type*)NULL)->field))
index 8f567a5ba5443260a8debcc993c77b4810a0f2ff..5fdf92840589abee9572e8c3da6256ca67ec3e58 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "object.h"
 
-#define NO_TIMEOUT 0xFFFFFFFF
-
 #define syscall_create_mutex(n, i, h) syscall_create_semaphore((n), (i), 1, (h))
 #define syscall_open_mutex(n, h) syscall_open_semaphore((n), (h))
 #define syscall_wait_semaphore(s, c, t) syscall_wait_for_one((s), (void*)(c), (t))