Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
qurious-pixel committed Nov 2, 2023
1 parent e2ef1f9 commit 6c1a770
Show file tree
Hide file tree
Showing 195 changed files with 57,292 additions and 51,355 deletions.
577 changes: 309 additions & 268 deletions hw/amdgpu/bridge/include/amdgpu/bridge/bridge.hpp

Large diffs are not rendered by default.

152 changes: 82 additions & 70 deletions hw/amdgpu/bridge/src/bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,92 @@

static int gShmFd = -1;
static constexpr std::size_t kShmSize = sizeof(amdgpu::bridge::BridgeHeader) +
(sizeof(std::uint64_t) * (1024 * 1024));
amdgpu::bridge::BridgeHeader *
amdgpu::bridge::createShmCommandBuffer(const char *name) {
if (gShmFd != -1) {
return nullptr;
}

// unlinkShm(name);

int fd = ::shm_open(name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

if (fd == -1) {
return nullptr;
}

if (ftruncate(fd, kShmSize) < 0) {
::close(fd);
return nullptr;
}

void *memory =
::mmap(nullptr, kShmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (memory == MAP_FAILED) {
::close(fd);
return nullptr;
}

gShmFd = fd;
auto result = new (memory) amdgpu::bridge::BridgeHeader();
result->size =
(kShmSize - sizeof(amdgpu::bridge::BridgeHeader)) / sizeof(std::uint64_t);
return result;
(sizeof(std::uint64_t) * (1024 * 1024));
amdgpu::bridge::BridgeHeader*
amdgpu::bridge::createShmCommandBuffer(const char* name)
{
if (gShmFd != -1)
{
return nullptr;
}

// unlinkShm(name);

int fd = ::shm_open(name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

if (fd == -1)
{
return nullptr;
}

if (ftruncate(fd, kShmSize) < 0)
{
::close(fd);
return nullptr;
}

void* memory =
::mmap(nullptr, kShmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (memory == MAP_FAILED)
{
::close(fd);
return nullptr;
}

gShmFd = fd;
auto result = new (memory) amdgpu::bridge::BridgeHeader();
result->size =
(kShmSize - sizeof(amdgpu::bridge::BridgeHeader)) / sizeof(std::uint64_t);
return result;
}

amdgpu::bridge::BridgeHeader *
amdgpu::bridge::openShmCommandBuffer(const char *name) {
if (gShmFd != -1) {
return nullptr;
}

int fd = ::shm_open(name, O_RDWR, S_IRUSR | S_IWUSR);

if (fd == -1) {
return nullptr;
}

if (ftruncate(fd, kShmSize) < 0) {
::close(fd);
return nullptr;
}

void *memory =
::mmap(nullptr, kShmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (memory == MAP_FAILED) {
::close(fd);
return nullptr;
}

gShmFd = fd;
return new (memory) amdgpu::bridge::BridgeHeader;
amdgpu::bridge::BridgeHeader*
amdgpu::bridge::openShmCommandBuffer(const char* name)
{
if (gShmFd != -1)
{
return nullptr;
}

int fd = ::shm_open(name, O_RDWR, S_IRUSR | S_IWUSR);

if (fd == -1)
{
return nullptr;
}

if (ftruncate(fd, kShmSize) < 0)
{
::close(fd);
return nullptr;
}

void* memory =
::mmap(nullptr, kShmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

if (memory == MAP_FAILED)
{
::close(fd);
return nullptr;
}

gShmFd = fd;
return new (memory) amdgpu::bridge::BridgeHeader;
}

void amdgpu::bridge::destroyShmCommandBuffer(
amdgpu::bridge::BridgeHeader *buffer) {
if (gShmFd == -1) {
__builtin_trap();
}

buffer->~BridgeHeader();
::close(gShmFd);
gShmFd = -1;
::munmap(buffer, kShmSize);
amdgpu::bridge::BridgeHeader* buffer)
{
if (gShmFd == -1)
{
__builtin_trap();
}

buffer->~BridgeHeader();
::close(gShmFd);
gShmFd = -1;
::munmap(buffer, kShmSize);
}

void amdgpu::bridge::unlinkShm(const char *name) { ::shm_unlink(name); }
void amdgpu::bridge::unlinkShm(const char* name) { ::shm_unlink(name); }
Loading

0 comments on commit 6c1a770

Please sign in to comment.