Unison Help
![](https://rowebots.com/wp-content/plugins/documentor/skins/default/images/search.png)
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
1.10.3.3.pt_getblock() #
NAME
pt_create, pt_destroy, pt_getblock, pt_retblock – fixed size block memory allocation
SYNOPSIS
#include <sys.h>
- int pt_create( size_t blocksize , int numblocks );
- int pt_destroy( int ptno );
- void *pt_getblock( int ptno );
- void pt_freeblock( int ptno , void *block );
pt_getblock() and pt_freeblock() are callable from an ISR.
DESCRIPTION
Partitions support allocation and deallocation of fixed size blocks from a memory region. They are used to manage a collection of blocks of the same size with exceptionally fast allocation and deallocation. The partitions support allocation and deallocation by any thread on the same core which allows user threads to fill a buffer, pass the buffer on (using mq_send for example) and then have some other thread return the buffer to the partition.
pt_create() creates a partition from which memory can be dynamically allocated in fixed blocksize blocks. numblocks blocks will be available in the partition. If sucessfull, pt_create() returns ptno, which is a system identifier which will be used by threads to access the partition. pt_getblock() is called to get a fixed sized buffer from the partition ptno. A pointer to the buffer is returned if the call was successful. pt_freeblock() returns a fixed size buffer, pointed to by block, to the partition ptno. block must be the value from a successfull pt_getblock call. pt_destroy will delete the partition with the system identifier ptno All allocated buffers must be returned to the partition before it can be successfully deleted.
RETURN VALUES
If pt_create() or pt_destroy() fails, they will return -1 and set errno. If pt_getblock() fails, it will return 0.
ERRORS
pt_create() will return the following errors:
- EINVAL
- blocksize or numblocks are 0.
- ENOSPC
- Not enough memory to allocate the partition.
- EAGAIN
- All 8 partitions have been allocated.
pt_destroy() will return the following errors:
- EBADID
- ptno was not a valid partition.
- EBUSY
- ptno has outstanding blocks allocated.
NOTES
pt_create() calls kalloc(KA_PT, …) to allocate the memory for the partition. The size passed to kalloc will contain all the overhead for the partition.