Coder Social home page Coder Social logo

go-fd-mutex's Introduction

go-fd-mutex

This fd-mutex is code extracted from the go/net package:

It's great, and designed specifically for low-level IO in Go. It's used by netFD (http://golang.org/src/pkg/net/fd_unix.go), the thing all net.Conn implementations use underneath, to manage their sockets.

I want to use it in go-udtwrapper, and other net protocol implementations. But, sadly, I can't use it because it relies on these odd lines:

// Implemented in runtime package.
func runtime_Semacquire(sema *uint32)
func runtime_Semrelease(sema *uint32)

These are functions without a body. But it turns out that they get special-cased. They are satisfied by the semaphore implementation in http://golang.org/src/pkg/runtime/sema.goc. Go patches it weirdly. This is C code, with a middle-dot · character as a var name delimiter, to mimic the . pkg notation (good idea).

// TODO(dvyukov): move to netpoll.goc once it's used by all OSes.
void net·runtime_Semacquire(uint32 *addr)
{
  runtime·semacquire(addr, true);
}

void net·runtime_Semrelease(uint32 *addr)
{
  runtime·semrelease(addr);
}

And turns out that this C code with .goc extension is compiled using the dist tool, which includes http://golang.org/src/cmd/dist/goc2c.c BUT! it will only compile such .goc code if it exists in the Go runtime package:

From: http://golang.org/src/cmd/dist/build.c#L934

// Generate .c files from .goc files.
if(streq(dir, "pkg/runtime")) {
  for(i=0; i<files.len; i++) {
    p = files.p[i];
    if(!hassuffix(p, ".goc"))
      continue;
    // b = path/zp but with _goos_goarch.c instead of .goc
    bprintf(&b, "%s%sz%s", bstr(&path), slash, lastelem(p));
    b.len -= 4;
    bwritef(&b, "_%s_%s.c", goos, goarch);
    goc2c(p, bstr(&b));
    vadd(&files, bstr(&b));
  }
  vuniq(&files);
}

After finding all this out, trudging through the source, I gave up. If the go team is trying so hard to keep all this private and unused by others, it's likely that it makes lots of assumption I'd break by ripping it out and putting it elsewhere.

This repo is up here for posterity, and just in case I change my mind again.

go-fd-mutex's People

Contributors

chriscool avatar jbenet avatar

Watchers

 avatar  avatar  avatar

Forkers

chriscool

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.